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

Allow Error to conform to itself #20629

Merged
merged 2 commits into from Dec 6, 2018

Conversation

Projects
None yet
4 participants
@rjmccall
Copy link
Member

rjmccall commented Nov 16, 2018

Most of the foundation for this was laid in earlier patches.

This PR should not be merged because it arguably requires Evolution approval.

I was considered adding an -enable-error-self-conformance flag and merging this so that people could test it. Unfortunately, testing it would require the stdlib to be built under that flag, and doing that by default would change the ABI of the stdlib — and avoiding that ABI change is exactly why I can't merge this patch yet. So no dice.

PRs this depends on that aren't in the 5.0 branch: #20658, #20662

@rjmccall rjmccall requested a review from DougGregor Nov 16, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 16, 2018

@swift-ci Please test.

@rjmccall rjmccall changed the title Allow Error to conform to itself [DNM] Allow Error to conform to itself Nov 16, 2018

@DougGregor
Copy link
Member

DougGregor left a comment

Huh. This is a not nearly as complicated as I would have thought

lib/SILGen/SILGenPoly.cpp Outdated
getSelfTypeAndConformanceForWitness(SILDeclRef witness, SubstitutionMap subs) {
auto protocol = cast<ProtocolDecl>(witness.getDecl()->getDeclContext());
auto sig = subs.getGenericSignature();
auto selfParam = sig->getGenericParams()[0]->getCanonicalType();

This comment has been minimized.

@DougGregor

DougGregor Nov 16, 2018

Member

You can use protocol->getProtocolSelfType() here, FWIW

This comment has been minimized.

@rjmccall

rjmccall Nov 16, 2018

Author Member

Fixed.

test/Interpreter/error_self_conformance.swift Outdated

func castValueToError<T>(error: T) -> Error? {
return error as? Error
}

This comment has been minimized.

@DougGregor

DougGregor Nov 16, 2018

Member

You'll need to update swift::_conformsToProtocol in the runtime, because it has a path that will need to know that an error existential conforms to the Error protocol. (Right now it only considers @objc existentials to conform to their protocols). You can exercise the code by evaluating a conditional conformance at runtime.

This comment has been minimized.

@rjmccall

rjmccall Nov 16, 2018

Author Member

It actually Just Works, probably because I'm generating an ordinary conformance with a conformance descriptor whose conforming type is linked correctly back to the protocol (by a cavalcade of different PRs). But as discussed privately, I'll flesh out the tests for various cases of this.

test/Interpreter/error_self_conformance.swift Outdated
@@ -0,0 +1,44 @@
// RUN: %target-jit-run %s 2>&1 | %FileCheck %s

This comment has been minimized.

@slavapestov

slavapestov Nov 16, 2018

Member

Any reason this is a JIT test and not a build a binary and run it test?

This comment has been minimized.

@rjmccall

rjmccall Nov 16, 2018

Author Member

No, I'll fix that.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test OS X Platform
Git Sha - c86f9579b3fc7779f02aa2ef7b824815b86d4f98

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch Nov 16, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 16, 2018

@swift-ci Please test.

1 similar comment
@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 16, 2018

@swift-ci Please test.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test OS X Platform
Git Sha - f33dfffe77e69f0ec064fec9420472b624e71ca6

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test Linux Platform
Git Sha - f33dfffe77e69f0ec064fec9420472b624e71ca6

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch Nov 16, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 16, 2018

@swift-ci Please test.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test OS X Platform
Git Sha - f33dfffe77e69f0ec064fec9420472b624e71ca6

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test Linux Platform
Git Sha - f33dfffe77e69f0ec064fec9420472b624e71ca6

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch Nov 16, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 16, 2018

@swift-ci Please test.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test Linux Platform
Git Sha - 976e5be00628ee7d9f3a16bf03bd6fa98ad195e5

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 16, 2018

Build failed
Swift Test OS X Platform
Git Sha - 976e5be00628ee7d9f3a16bf03bd6fa98ad195e5

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch Nov 17, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

@swift-ci Please test.

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

@swift-ci Please test source compatibility.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test OS X Platform
Git Sha - e6072f563ac79a64bf838045a3d4f5b41d72f9f4

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test Linux Platform
Git Sha - e6072f563ac79a64bf838045a3d4f5b41d72f9f4

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

That's a real bug caught by the compatibility suite, not just a source compatibility problem.

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

...oh, but I think it's actually caused by the change I made to ProtocolConformanceRef::subst.

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch Nov 17, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

@swift-ci Please test.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test Linux Platform
Git Sha - c66ad971d0f63f7c4e225586230a61dec681969b

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test OS X Platform
Git Sha - c66ad971d0f63f7c4e225586230a61dec681969b

rjmccall added some commits Nov 17, 2018

Allow Error to conform to itself.
Most of the foundation for this was laid in earlier patches.

@rjmccall rjmccall force-pushed the rjmccall:error-self-conformance branch to 49ba9c5 Nov 17, 2018

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

@swift-ci Please test.

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test Linux Platform
Git Sha - 3f6bdc2a8e82fe7c9dfafeee11f37212d1c86fec

@swift-ci

This comment has been minimized.

Copy link
Contributor

swift-ci commented Nov 17, 2018

Build failed
Swift Test OS X Platform
Git Sha - 3f6bdc2a8e82fe7c9dfafeee11f37212d1c86fec

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Nov 17, 2018

@swift-ci Please test OS X

@rjmccall

This comment has been minimized.

Copy link
Member Author

rjmccall commented Dec 5, 2018

@swift-ci Please test.

@rjmccall rjmccall changed the title [DNM] Allow Error to conform to itself Allow Error to conform to itself Dec 5, 2018

@rjmccall rjmccall merged commit 8112f68 into apple:master Dec 6, 2018

4 checks passed

Swift Test Linux Platform 11543 tests run, 10403 skipped, 0 failed.
Details
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform 57920 tests run, 2475 skipped, 0 failed.
Details
Swift Test OS X Platform (smoke test)
Details

rjmccall added a commit to rjmccall/swift that referenced this pull request Dec 6, 2018

@rjmccall rjmccall deleted the rjmccall:error-self-conformance branch Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment