Skip to content

[4.2-04-30-2018] [SILGen] Ensure type params in witness method conformances match the witness method signatures. #16518

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

huonw
Copy link
Contributor

@huonw huonw commented May 11, 2018

Explanation: A class conditionally conforming to a protocol and using a default method for one of the requirements, would result in an incorrect signature (at the LLVM/asm level) for the thunk for the witness for that requirement. These are called dynamically, and so would result in crashes/undefined behaviour at runtime if things from the conditional requirements were used (e.g. calling a method on a T in extension Class: P where T: Q).
Scope: Any class conforming to a protocol as above is at high risk of this.
Radar: rdar://problem/40078863.
Risk: Low: this is, essentially, just changing a type parameter from the incorrect default to the correct one, without modifying anything around it.
Testing: Test suite plus source compatibility suite
Reviewer: @DougGregor

#16493 #16514

…witness method signatures.

A witness method of a class can have its generic parameters rephrased: a
parameters of the class, like τ_0_0, get pushed to the next depth, like τ_1_0,
to make way for a τ_0_0 parameter with a τ_0_0: Class<...> subclass
constraint. When this wasn't accounted for, IRGen would find that it couldn't
satisfy conditional requirements on the rewritten type parameters, and they'd
incorrectly be passed as additional arguments of a witness method thunk rather
than pulled out of the Self witness table's private area inside the thunk.

Fixes rdar://problem/40078863.
@huonw
Copy link
Contributor Author

huonw commented May 11, 2018

@swift-ci please test

@huonw
Copy link
Contributor Author

huonw commented May 11, 2018

@swift-ci please test source compatibility

@huonw huonw changed the title [SILGen] Ensure type params in witness method conformances match the witness method signatures. [4.2-04-30-2018] [SILGen] Ensure type params in witness method conformances match the witness method signatures. May 11, 2018
@huonw
Copy link
Contributor Author

huonw commented May 11, 2018

@swift-ci please nominate

@huonw
Copy link
Contributor Author

huonw commented May 11, 2018

@swift-ci please test source compatibility

@huonw
Copy link
Contributor Author

huonw commented May 12, 2018

I'm told that these the source compatibility failures haven't been set up for this branch. Merging.

@huonw huonw merged commit f42dc73 into swiftlang:swift-4.2-branch-04-30-2018 May 12, 2018
@huonw huonw deleted the conditional-class-crash-4.2-2018-04-30 branch May 12, 2018 09:18
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.

1 participant