Skip to content

[Relax][TVMScript] Keep metadata for bare constant If-branch bodies - #20946

Open
cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-20892
Open

cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-20892

Conversation

@cchung100m

Copy link
Copy Markdown
Contributor

Hi Committers,

This PR fixes issue #20892. Any suggestions would be greatly appreciated.

Root Cause

  • RelaxSeqBody (src/relax/script/printer/region.cc) called DocTranslatorObj::Translate(SeqExpr).
  • SeqExprDocTranslate returns the body Doc unchanged, and Translate unconditionally calls RecordOrigin(result, value) on the returned Doc(doc_translator.h). This overwrites the GenericConst origin set by AddMetadata with the SeqExpr.
  • CollectMetadata(printer.cc) only accepts a reference whose recorded origin has the same type key as the registry key (ir.GenericConst), so it skipped the reference and RenderScript omitted the declaration.
  • When one branch has bindings, and the other is a bare constant, only the bound branch is collected, and the table gets a null entry at the bare branch's slot.

FunctionDocTranslate translates func->body->body directly and does not hit this, which matches the observation that a bare constant function body with no If round-trips correctly.

Solution

Move the SeqExpr body translation (blocks, implicit-def handling, body) into TranslateSeqExprContents and call it from both SeqExprDocTranslate and RelaxSeqBody, so RelaxSeqBody no longer goes through Translate(SeqExpr) and the body Doc keeps its own origin.

@cchung100m
cchung100m marked this pull request as ready for review November 9, 2026 13:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant