tqchen commented on code in PR #19940:
URL: https://github.com/apache/tvm/pull/19940#discussion_r3523729367
##########
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:
Addressed in `3546a2ad84`. The active `PythonDocPrinter` now redirects only
its existing output stream buffer to an isolated child sink, so the printer
instance, original configuration, locale, and formatting state are preserved.
It copies and escapes only the child bytes, eliminating the accumulated-prefix
copies and restoring linear output behavior. Child source-path registration is
suppressed while offsets are child-local and pre-escape; after restoration, the
enclosing `ExprStringDoc` records the complete final escaped literal span. This
matches the earlier `LiteralDoc` diagnostic granularity and prevents raw child
offsets from leaking. Existing focused/adjacent/broad suites pass (49, 354, and
1,164 tests respectively), and a disposable `T.Cast("int64", n)` probe verified
the escaped wrapper underline, nearest-visible-parent behavior, config reuse,
and absence of stale child carets or duplicated diagnostic text. No new test
was checked in.
--
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]