-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Always rewrite GotoIfNot with unreachable branches #51062
Conversation
kudos to @maleadt for the heads up on the PkgEval failures |
Add a test, please, otherwise LGTM. |
This resolves a regression introduced in JuliaLang#50943 (comment) The problem was that we now expect the explicit CFG of the IR to correspond 1-1 in terms of reachability to the information we get from inference. That means that we have to unconditionally re-write control flow to match the branches that inference ended up actually exploring. This change also modifies Inference to update the ssaflags on GotoIfNot and GotoNode statements, so that we can be sure these `@assert`s will trip if Inference is ever made smart enough to fold Union{Const(true), Float64}-style conditions.
57abcb0
to
4d3de1a
Compare
Test coverage added. Should be ready to land after approval and passing CI. This now has an assert so that it will not silently break if Inference gets smart enough to partially-explore |
@@ -3002,6 +3003,8 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState) | |||
condt = Conditional(condx, Const(true), Const(false)) | |||
end | |||
condval = maybe_extract_const_bool(condt) | |||
nothrow = (condval !== nothing) || ⊑(𝕃ᵢ, orig_condt, Bool) | |||
nothrow && add_curr_ssaflag!(frame, IR_FLAG_NOTHROW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some additional issues here where the merge_effects!
down below isn't in the right place, but I'm already fixing that in #50805.
This resolves a regression introduced in #50943 (comment)
That PR requires the Goto/GotoIfNot statements of the IR to correspond 1-1 (in terms of reachability) to the information we get from inference. To make that happen, we have to unconditionally re-write control flow to match the branches that inference ended up actually exploring.
The problem is that we were choosing not to do this if the GotoIfNot condition seemed to be maybe-non-Boolean.
Thankfully, it turns out that check is unnecessary because Inference when following conditionals does not consider "true or non-Bool" etc. If it did, we'd instead have to re-write these branches as a
typeassert; goto
to encode the reachability