tqchen commented on code in PR #19940:
URL: https://github.com/apache/tvm/pull/19940#discussion_r3523797802


##########
src/script/printer/doc_printer/python_doc_printer.cc:
##########
@@ -394,6 +396,19 @@ void PythonDocPrinter::PrintTypedDoc(const LiteralDoc& 
doc) {
   }
 }
 
+void PythonDocPrinter::PrintTypedDoc(const ExprStringDoc& doc) {
+  this->output_ << '"';
+  size_t start_pos = this->output_.tellp();
+  this->PrintDoc(doc->value);
+  std::string output = this->output_.str();
+  std::string value = output.substr(start_pos);
+  TVM_FFI_ICHECK(value.find('\n') == std::string::npos)
+      << "An expression rendered inside a Python string literal must be one 
line";
+  this->output_.str(output.substr(0, start_pos));
+  this->output_.seekp(start_pos);
+  this->output_ << support::StrEscape(value) << '"';
+}

Review Comment:
   Follow-up correction `a41b121336` now streams the existing byte-wise Python 
escaping directly into the final output only while `this->PrintDoc(doc->value)` 
runs. The scoped adapter delegates `tellp()` to the destination, so child spans 
are recorded at absolute escaped offsets; it also restores the original buffer 
and stream state on every exit. A focused `T.Cast("int64", n)` regression 
verifies the 22-byte wrapper, 9-byte escaped dtype, and 1-byte value spans at a 
nonzero prefix, repeated configuration use, and no diagnostic leakage. The 
build passed; the focused/adjacent suites passed 402 tests with 2 expected 
failures, and the broader printer/type suite passed 1,022 tests with 1 expected 
failure and 2 no-LLVM deselections. Both private and public PR heads resolve 
exactly to this commit; no merge was performed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to