-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Extend findInitExistential for cases when ApplySite argument is a global_addr #17361
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
Extend findInitExistential for cases when ApplySite argument is a global_addr #17361
Conversation
@gottesmm @slavapestov @atrick Can you review this PR? This Pr refactors the old code for findInitExistentialFromGlobalAddr to findInitExistentialFromGlobalAddrAndCopyAddr and adds a new interface for finding init_existential for an apply argument who happens to be a global_addr, findInitExistentialFromGlobalAddrAndApply . This function is currently not being used, hence no new tests. I will use this interface when #13991 lands fully. |
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.
This generally looks good and the comments are nice. The only comments I have are the misleading variable names above.
|
||
/// Find InitExistential from global_addr and an apply argument. | ||
SILValue findInitExistentialFromGlobalAddrAndApply(GlobalAddrInst *GAI, | ||
ApplySite AI, int ArgIdx); |
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.
Whenever I see uses of an "apply" without the type spelled out, I like to know when I'm dealing with an ApplySite vs. ApplyInst, and which code is potentially handling try_apply. Since "AI" is an acronym for ApplyInst, this is misleading. (I suspect this is backward in so much of our code because someone did a massive replace on the type without changing variable names?) Let's not make it worse.
|
||
/// %10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP) | ||
static SILValue findInitExistentialFromGlobalAddr(GlobalAddrInst *GAI, | ||
SILInstruction *AI) { |
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.
AI
is misleading again here. This is not always an ApplyInst. It's just some arbitrary use of the global_addr
.
/// %9 = open_existential_addr mutable_access %3 : $*SomeP to $*@opened SomeP | ||
/// %15 = apply %11(%9) : $@convention(thin) (@in_guaranteed SomeP) | ||
SILValue swift::findInitExistentialFromGlobalAddrAndApply(GlobalAddrInst *GAI, | ||
ApplySite AI, |
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.
Again, calling this AI
leads me to believe that it's not potentially a try_apply.
a7f56d5
to
42257c2
Compare
Thanks @atrick. Should be fixed now. |
|
||
/// %10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP) | ||
static SILValue findInitExistentialFromGlobalAddr(GlobalAddrInst *GAI, | ||
SILInstruction *Insn) { |
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.
nit: you should probably comment that Insn
is assumed to be a direct user of GAI
(e.g. copy_addr
or apply
in the pattern above) and that a valid init_existential_addr
value is returned only if this routine can prove that the value it initializes is the same value in memory at the given use point. Looking at this again, I don't understand why the return type is SILValue
and not InitExistentialAddrInst*
.
42257c2
to
392469a
Compare
@atrick Thanks for the suggestion -- added the assumption. The reason it returns SILValue is because for convenience in use in getAddressOfStackInit below that returns a SILValue. |
Ok. FYI, any SingleValueInstruction such as this is castable to SILValue. |
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
Please update the existing SILCombiner self concrete type peephole to use the new function and add a SIL test. |
Determine InitExistential for an apply argument that is a global_addr.
Pattern 1:
Pattern 2:
No test cases yet, will be merged as part of the large PR #13991