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

fix internal IR corruption from use of a global #39540

Merged
merged 1 commit into from
Mar 8, 2021
Merged

fix internal IR corruption from use of a global #39540

merged 1 commit into from
Mar 8, 2021

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Feb 5, 2021

Fixes #39508

@vtjnash vtjnash requested a review from Keno February 5, 2021 16:47
@vtjnash vtjnash added the backport 1.6 Change should be backported to release-1.6 label Feb 5, 2021
@Keno
Copy link
Member

Keno commented Feb 5, 2021

Can we come up with a form that is always legal to have here? Requiring the type lifting pass to be run seems like a code smell.

compact.result[idx][:line], true)
compact.ssa_rename[compact.idx-1] = pi
Y = stmt.args[2]
if !isa(Y, GlobalRef)
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't GlobalRef work here? Can you explain that in a comment or in the commit message?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

GlobalRef is not pure, so it is invalid to duplicate it

Copy link
Member

Choose a reason for hiding this comment

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

Wasn't the whole point of #36450 to change that? What non-purity remains?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

They can also still be non-constant

Copy link
Member

Choose a reason for hiding this comment

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

If there is a data race you mean? In that case, what if instead of not doing the canonicalization, we did:

%a = GlobalRef(...)
typassert(%a, T)
PiNode(%a, T)

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

That's fine too

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 5, 2021

I'm not sure. This part of the code needs more documentation. The issue is we're inserting a use of an SSAValue, whose purpose (later) is to tell us is to let us track backwards (through PhiNodes) to discover if it was legal dynamically

@Keno
Copy link
Member

Keno commented Feb 5, 2021

What prevents us from just making undefcheck a legal codegen form? I thought it was that way originally.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 7, 2021

I don't think it ever existed (I tried to search back a little, but didn't see anything). undefcheck doesn't feel directly legal because it is an operation on the inferred type of the SSAValue. That's also why we see type_lift_pass is where final legalization happens, since it is taking that information out of the type domain, and inserting runtime values that track it where necessary (generally initialized by a Phi(c)Node, since otherwise we should have a certainty that it is defined, or not).

@Keno
Copy link
Member

Keno commented Feb 7, 2021

undefcheck doesn't feel directly legal because it is an operation on the inferred type of the SSAValue.

I'm not sure I agree with that. It's a dynamic check on the definedness on that branch. I guess the issue is that we don't have the capacity to track this in codegen and if we did, it would just look like type_lift_pass, so we might as well call that pass required. I'm not sure I 100% like that since type_lift_pass was supposed to be an optimization, but I guess it's the most expedient path for now.

@@ -147,6 +148,7 @@ function fixemup!(cond, rename, ir::IRCode, ci::CodeInfo, idx::Int, @nospecializ
return true
end
end
# temporarily corrupt the isdefined node. type_lift_pass! will fix it
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a separate Expr head then?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Probably would be more accurate? But possibly annoying to implement? Dunno. I was going for the minimal fix

These ops are not actually legal (they're semantically invalid), but we
temporarily use them to carry information between passes which needs to
then remove them correctly.

Fixes #39508
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Mar 2, 2021

I've dropped the objectionable commit and created #39893 for the better alternative of it. This should be ready to merge

Copy link
Member

@Keno Keno left a comment

Choose a reason for hiding this comment

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

Still would prefer to have the type lifting pass be purely an optimization, but let's fix the crash. We're doing worse things elsewhere in the compiler.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Mar 3, 2021

Agreed. I think the main challenge is that we need a concretization pass at some point to split maybe-undef variables, and it either looks a lot like this pass, but could be run separately / very early, or it just is this pass.

@vtjnash vtjnash merged commit 970edc7 into master Mar 8, 2021
@vtjnash vtjnash deleted the jn/39508 branch March 8, 2021 19:18
@KristofferC KristofferC mentioned this pull request Mar 14, 2021
14 tasks
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Mar 23, 2021
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.

internal IR corruption from use of a local variable assigned in a try block
3 participants