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

irinterp: Fix accidentally introduced deletion of effectful statement #49750

Merged
merged 1 commit into from
May 11, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented May 11, 2023

I moved around some code in #49692 that broadened the replacement of statements by their const results. This is fine for how we're currently using irinterp in base, because we're requiring some fairly strong effects, but some downstream pipelines (and potentially Base in the future) want to use irinterp on code with arbitrary effects, so put in an appropriate check.

I moved around some code in #49692 that broadened the replacement of
statements by their const results. This is fine for how we're currently
using irinterp in base, because we're requiring some fairly strong
effects, but some downstream pipelines (and potentially Base in the future)
want to use irinterp on code with arbitrary effects, so put in an
appropriate check.
@@ -2544,6 +2544,7 @@ end
function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e), vtypes::VarTable, sv::InferenceState)
if !isa(e, Expr)
if isa(e, PhiNode)
add_curr_ssaflag!(sv, IR_FLAG_EFFECT_FREE)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? This function works on InferenceState and thus irinterp will never use it. The ordinary inference may see PhiNode somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

We made it legal in untyped code, but it is true that we may need to add the flag in ssa conversion also.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there is any actual users of this PhiNode handling within untyped code inference. And it sounds a good idea to add the flag during SSA conversion.

Copy link
Member Author

@Keno Keno May 11, 2023

Choose a reason for hiding this comment

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

I wonder if there is any actual users of this PhiNode handling within untyped code inference.

Diffractor uses it.

And it sounds a good idea to add the flag during SSA conversion.

I think we already set this since stmt_effect_flags knows about it, but we've of course been moving to not
calling that function quite as often.

@Keno Keno merged commit 0b5ec1f into master May 11, 2023
@Keno Keno deleted the kf/fix49692 branch May 11, 2023 03:35
Keno added a commit that referenced this pull request May 12, 2023
This is yet another followup to #49692 and #49750.
With the introduced change, we kill the CFG edge
from the basic block with the discovered error to
its successors. However, we have an invariant in
the verifier that the CFG should always match the
IR. Turns out this is for good reason, as we assume
in a number of places (including, ironically in the
irinterp) that a GotoNode/GotoIfNot terminator means
that the BB has the corresponding number of successors
in the IR. Fix all this by killing the rest of the basic
block when we discover that it is unreachable and if
possible introducing an unreachable node at the end.
However, of course if the erroring statement is the
fallthrough terminator itself, there is no space for
an unreachable node. We fix this by tweaking the
verification to allow this case, as its really
no worse than the other problems with fall-through
terminators (#41476), but of course it would be good
to address that as part of a more general IR refactor.
Keno added a commit that referenced this pull request May 13, 2023
This is yet another followup to #49692 and #49750.
With the introduced change, we kill the CFG edge
from the basic block with the discovered error to
its successors. However, we have an invariant in
the verifier that the CFG should always match the
IR. Turns out this is for good reason, as we assume
in a number of places (including, ironically in the
irinterp) that a GotoNode/GotoIfNot terminator means
that the BB has the corresponding number of successors
in the IR. Fix all this by killing the rest of the basic
block when we discover that it is unreachable and if
possible introducing an unreachable node at the end.
However, of course if the erroring statement is the
fallthrough terminator itself, there is no space for
an unreachable node. We fix this by tweaking the
verification to allow this case, as its really
no worse than the other problems with fall-through
terminators (#41476), but of course it would be good
to address that as part of a more general IR refactor.
Keno added a commit that referenced this pull request May 14, 2023
If a fall-through terminator was already Bottom, we should not attempt
to rekill the successor edge, because it was already deleted.
Yet another fix in the #49692, #49750, #49797 series, which is
turning out to be quite a rabit hole. Also fix a typo in the
verifer tweak where we were looking at the BB idx rather than
the terminator idx.
Keno added a commit that referenced this pull request May 15, 2023
If a fall-through terminator was already Bottom, we should not attempt
to rekill the successor edge, because it was already deleted.
Yet another fix in the #49692, #49750, #49797 series, which is
turning out to be quite a rabit hole. Also fix a typo in the
verifer tweak where we were looking at the BB idx rather than
the terminator idx.
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