Skip to content

RFC: stop wrapping unreachable statements in Const #58581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JeffBezanson
Copy link
Member

This does not make sense semantically, and we have better sources of reachability info now. The biggest concrete problem is that it makes code_warntype output confusing, e.g.

1 ─ %1 = Main.throw::Core.Const(throw)
│   %2 = Main.AssertionError::Core.Const(AssertionError)
│   %3 = Base.string("x1=", x1)::String
│   %4 = (%2)(%3)::Core.PartialStruct(AssertionError, Any[String])
│        (%1)(%4)
└──      Core.Const(:(return %5))

where the final unreachable return statement looks like a type.

What I have here seems to work (passes Compiler tests) but I need some help because I don't think it's optimal. The change in construct_ssa! is not quite right since iterated_dominance_frontier is now reaching unreachable statements that it skipped before, but I haven't yet figured out how it's depending on the Const wrapping for that.

@JeffBezanson JeffBezanson added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label May 30, 2025
@aviatesk
Copy link
Member

The change in construct_ssa! is not quite right since iterated_dominance_frontier is now reaching unreachable statements that it skipped before, but I haven't yet figured out how it's depending on the Const wrapping for that.

I think we likely need to tweak convert_to_ircode, in particular

julia/Compiler/src/optimize.jl

Lines 1247 to 1252 in b61664e

if !(idx < length(code) && isa(code[idx + 1], ReturnNode) && !isdefined((code[idx + 1]::ReturnNode), :val))
# Any statements from here to the end of the block have been wrapped in Core.Const(...)
# by type inference (effectively deleting them). Only task left is to replace the block
# terminator with an explicit `unreachable` marker.
if block_end > idx
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants