-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix a few more callers of ProtocolConformanceRef::forAbstract() to pass in a subject type #80107
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 a few more callers of ProtocolConformanceRef::forAbstract() to pass in a subject type #80107
Conversation
If any of the get*() methods are called on the wrong kind of ProtocolConformanceRef, we immediately cast a pointer to an incorrect type, which will most likely cause a crash.
The "abstract conformance is just a ProtocolDecl" assumption is pretty fundamental here, so we have to fudge a bit at the API boundary for now. Eventually, LocalTypeDataKind should just contain a ProtocolConformanceRef instead of duplicating the representation, however this would require fixing various calls to LocalTypeDataKind::forAbstractProtocolWitnessTable() which pass in a ProtocolDecl to pass in a ProtocolConformanceRef instead.
…eWitness The Protocol field isn't really necessary, because the conformance stores the protocol. But we do need the substituted subject type of the requirement, just temporarily, until an abstract conformance stores its own subject type too.
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
@@ -37,6 +37,9 @@ public struct Conformance: CustomStringConvertible, NoReflectionChildren { | |||
return Type(bridged: bridged.getType()) | |||
} | |||
|
|||
public var proto: ProtocolDecl { |
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.
Can you name this var `protocol`: ProtocolDecl
. We try to avoid abbreviations in the swift APIs as good as possible.
Note that the backticks are not needed when using this property, e.g. p = c.protocol
SILWT->getConformance()->getAssociatedConformance(requirement.getAssociation(), | ||
requirement.getAssociatedRequirement()); | ||
llvm::Constant *witnessEntry = IGM.getAddrOfWitnessTable(assocConf.getConcrete()); | ||
ProtocolConformance *assocConf = associatedWitness.Witness.getConcrete(); |
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.
associatedWithness
comes from a variable which is part of that #ifndef NDEBUG
above. Makes this a compilation failure when compiling a non-asserts toolchain.
Is there a fix already happening for this?
I want to make abstract conformances store a subject type, eventually.
This PR is another small step in that direction, by making us pass down a subject type instead of Type() in most places.
I wanted to avoid this becoming too much of a yak shave, so a couple of bits are a little hacky. IRGen's LocalTypeDataKind duplicates ProtocolConformanceRef in an awkward way, and SILWitnessTable::AssociatedConformanceWitness needs a temporary hack. We can unwind these later once the core representation is fixed.
One more call to forAbstract() without a subject type remains. Once that's fixed, we can start storing the subject type that is passed in to forAbstract(). This will allow simplifying some APIs, which will make them more convenient to call from Swift -- something that @eeckstein ran into, which is why I decided to pick up this refactoring again.