-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Track dependencies of SIL instructions on opened archetypes which they use. #2928
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
Conversation
@swift-ci Please test |
@atrick @rudkx Do you mind reviewing the new version of the opened archetype tracking? This time it is a complete implementation. Each instruction using an opened archetype has a dedicated The most interesting changes are:
|
@jckarter Joe, you may want to have a look as well. |
|
||
// Build a set of typedef operands for an apply instruction. This is done by | ||
// scanning the list of substitutions and collecting all opened archetypes. | ||
void createApplyTypeDefs(SILInstruction *I, ArrayRef<Substitution> Subs) { |
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.
Hmm. Unfortunately, I think there's too much potential confusion with C++ to use the term "typedef" for this.
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.
@rjmccall Yeah, may be you are right about this. Any suggestions for a better name? ArchetypeDef
? ArchDef
? ExistentialDef
? OpenExistentialDef
?
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.
These are opened archetype operands that refer to opened existential values. We're not even creating special "def" values for archetypes yet, so let's not call them "defs". OpenedArchetype is fine.
I think most of the issues that I saw are going to be fixed after handling @rjmccall's suggestions. Let me summarize:
|
1dc123e
to
d7ec9da
Compare
@swift-ci Please test |
Main changes in this version are:
|
d7ec9da
to
edc71bd
Compare
auto newLookupType = getOpASTType(lookupType); | ||
SILValue OpenedExistential; | ||
if (Inst->hasOperand()) | ||
OpenedExistential = getOpValue(Inst->getOperand()); |
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.
Could you be more explicit when getting the opened archetype operand by using getNumOpenedArchetypesOperands(), getOpenedArchetypesOperands?
It looks like this assumes that if the old instruction has an opened archetype operand, that the new one will too. I'm not sure that's right. If so, then we should have some assert.
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.
Actually, with all the introduced machinery in place, we can now handle the WitnessMethodInst as any regular instruction that may have opened archetype operands. There is no need for any special handling.
Thanks Roman. I think this design makes sense, at least for now... I know it was very tricky to implement. I like that the set of operations that may need opened archetype operands are explicit, even thought it's awkward to always pass in their opened archetypes. It is ugly, but I think it would be a mistake to hide the ugliness with magic inside SILIntruction creation. I like that the SILInstruction actually manages the operands and allocates memory up front, and that the builder tracks state across the creation of multiple instructions. |
@atrick Andy, thanks a lot for your review! It was very helpful! I think I addressed (almost) all of your comments. I pushed my changes as a series of commits on top of the one that you just reviewed to make it easier for you to see what was changed. Most of these changes can be classified as renaming or dead code removal. Once there are no further required changes, I'll squash the commits before merging. |
@swift-ci Please test |
da31d65
to
b803b7f
Compare
I squashed all commits into one before merging. |
@swift-ci Please test |
MutableArrayRef<Operand> getOpenedArchetypeOperands() { | ||
if (!hasOpenedArchetypeOperands()) | ||
return {}; | ||
return { &getAllOperands()[0] + 1, getNumOpenedArchetypeOperands() }; |
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 entire method is just:
return getAllOperands().slice(1);
Style comments aside, LGTM. |
5b7b6a6
to
0a3882b
Compare
I addressed all of @rjmccall comments and squashed the commits into one. |
@swift-ci Please test |
…y use Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype. This patch does the following: - Map opened archetypes to the instructions defining them, i.e. to open_existential instructions. - Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings. - Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes. - Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files. - SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
0a3882b
to
8ef8bb4
Compare
The last forced push just updated the time stamp of the commit which had the 26th of May as its date ;-) |
What's in this pull request?
Resolved bug number: (SR-)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.
This patch does the following: