Skip to content
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

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

topolarity
Copy link
Member

@topolarity topolarity commented Aug 26, 2023

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

@topolarity
Copy link
Member Author

kudos to @maleadt for the heads up on the PkgEval failures

@Keno
Copy link
Member

Keno commented Aug 26, 2023

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.
@topolarity
Copy link
Member Author

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 goto #x if not a::Union{Const(true), Float64} or similar.

@@ -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)
Copy link
Member

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.

@topolarity topolarity merged commit 0b29986 into JuliaLang:master Aug 28, 2023
3 of 6 checks passed
@topolarity topolarity deleted the pkgeval-im-sorry branch August 28, 2023 21:15
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.

4 participants