Skip to content

[NFC] Simplify printing of unreachable replacements#8616

Merged
tlively merged 4 commits intomainfrom
simplify-unreachable-print
Apr 20, 2026
Merged

[NFC] Simplify printing of unreachable replacements#8616
tlively merged 4 commits intomainfrom
simplify-unreachable-print

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Apr 17, 2026

When an instruction has a type immediate that we cannot print because the expression it is supposed to come from has unreachable or null type, we instead print an unreachable block with a comment saying what instruction we failed to print. We previously handled this via different code paths for type immediates that come from child expressions that type immediates that come from the printed expression's own return type. Unify these code paths in the printer by improving Properties::hasUnwritableTypeImmediate to handle both cases. Also fix the printing of ShallowExpression to check for unwritable type immediates first to avoid assertion failures.

When an instruction has a type immediate that we cannot print because the expression it is supposed to come from has unreachable or null type, we instead print an unreachable block with a comment saying what instruction we failed to print. We previously handled this via different code paths for type immediates that come from child expressions that type immediates that come from the printed expression's own return type. Unify these code paths in the printer by improving `Properties::hasUnwritableTypeImmediate` to handle both cases. Also fix the printing of `ShallowExpression` to check for unwritable type immediates first to avoid assertion failures.
@tlively tlively requested a review from a team as a code owner April 17, 2026 05:08
@tlively tlively requested review from aheejin and removed request for a team April 17, 2026 05:08
Comment thread src/ir/properties.h Outdated
Comment on lines +556 to +559
if (curr->is<StructNew>() || curr->is<ArrayNew>() ||
curr->is<ArrayNewData>() || curr->is<ArrayNewElem>() ||
curr->is<ArrayNewFixed>() || curr->is<ContNew>() ||
curr->is<ContBind>()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we possibly define these as a macro in wasm-delegations-fields.def too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could possibly add a macro similar to the macros for fields, but not actually associated with a field. Do you think that would be better than this? (also cc @kripken for opinions)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was, would it be possible and make sense to define a macro that means "This instruction's type printing depends on the instruction's type"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, understood. The only weird part is that there would not be a field associated with that macro.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I tried it this way, PTAL.

Comment thread src/ir/properties.h Outdated
}
if (!cast->desc->type.getHeapType().getDescribedType()) {
return true;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
}

@tlively tlively merged commit 9a1516f into main Apr 20, 2026
16 checks passed
@tlively tlively deleted the simplify-unreachable-print branch April 20, 2026 14:28
tlively added a commit that referenced this pull request Apr 20, 2026
When #8617 landed, it introduced this code from an out-of-date version
of #8616. The code had been moved in such a way that the merge kept both
old and new versions instead of creating a merge conflict. Remove the
outdated code.
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.

2 participants