-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Use conformance access paths in IRGen #8072
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
Use conformance access paths in IRGen #8072
Conversation
@swift-ci Please test. |
if (wtable) return wtable; | ||
|
||
// Otherwise, find the best path from one of the protocols directly | ||
// conformed to by the protocol, then get that conformance. | ||
// It can happen with class constraints that Sema will consider a |
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.
Do you have an example of this? It looks like another consequence of improper modeling of superclass constraints.
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.
I absolutely agree. That was existing code that I didn't feel like testing whether it was still necessary.
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.
The GenericSignatureBuilder
should no longer create such concrete constraints; I fixed something in this area a week or so ago when teaching it to maintain all requirement sources for superclass constraints.
lib/IRGen/GenArchetype.cpp
Outdated
// FIXME: eliminate this path when opened types have generic environments. | ||
auto environment = archetype->getGenericEnvironment(); | ||
if (!environment) { | ||
SmallVector<ProtocolEntry, 4> entries; |
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.
Maybe add an assert(archetype->isOpenedExistential()) here?
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.
Yeah, good idea.
@@ -88,9 +88,6 @@ func class_bounded_archetype_method<T : ClassBoundBinary>(_ x: T, y: T) { | |||
// CHECK: [[INHERITED:%.*]] = load i8*, i8** %T.ClassBoundBinary, align 8 | |||
// CHECK: [[INHERITED_WTBL:%.*]] = bitcast i8* [[INHERITED]] to i8** | |||
// CHECK: [[WITNESS:%.*]] = load i8*, i8** [[INHERITED_WTBL]], align 8 | |||
// FIXME: Redundant load of inherited conformance |
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.
Sweet :)
Build failed |
access path work. Having done so, simplify archetype TypeInfos by removing a now- unnecessary layer of abstraction.
a783485
to
22382f7
Compare
@swift-ci Please test. |
Build failed |
Build failed |
Fantastic! The AST doesn't currently track all of the requirement sources for conformances (which would be needed to enumerate all possible paths and pick the best one), but it does some basic keep-the-shortest-path logic. |
This series of patches — primarily the last — teaches IRGen to use conformance access paths to derive protocol conformances instead of a hacky recursive algorithm.
For now, we're just trusting the AST to figure out the best path, but it shouldn't be too hard to get the AST to give us multiple paths if they exist and then figure out which is best based on the type information currently in use within the function.