Skip to content

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

Merged
merged 4 commits into from
Mar 14, 2017

Conversation

rjmccall
Copy link
Contributor

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.

@rjmccall
Copy link
Contributor Author

@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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

// FIXME: eliminate this path when opened types have generic environments.
auto environment = archetype->getGenericEnvironment();
if (!environment) {
SmallVector<ProtocolEntry, 4> entries;
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Sweet :)

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - a7834851135f83291ea0dff9363ed44a9c904363
Test requested by - @rjmccall

access path work.

Having done so, simplify archetype TypeInfos by removing a now-
unnecessary layer of abstraction.
@rjmccall rjmccall force-pushed the irgen-conformance-access-paths branch from a783485 to 22382f7 Compare March 14, 2017 07:48
@rjmccall
Copy link
Contributor Author

@swift-ci Please test.

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - a7834851135f83291ea0dff9363ed44a9c904363
Test requested by - @rjmccall

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - a7834851135f83291ea0dff9363ed44a9c904363
Test requested by - @rjmccall

@rjmccall rjmccall merged commit f3bfc77 into swiftlang:master Mar 14, 2017
@rjmccall rjmccall deleted the irgen-conformance-access-paths branch March 14, 2017 15:01
@DougGregor
Copy link
Member

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.

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.

4 participants