Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AST/SIL: Fix problems if protocol requirement signature makes Self : …
…P conformance implicit Fixes assertion failures in SILGen and the optimizer with this exotic setup: protocol P { associatedtype T : Q } protocol Q { func requirement<U : P>(u: U) where U.T == Self } Here, we only have a U : P conformance, and not Self : Q, because Self : Q is available as U.T : Q. There were three problems here: - The SIL verifier was too strict in verifying the generic signature. All that matters is we can get the Self parameter conformance, not that it's the first requirement, etc. - GenericSignature::getSubstitutionMap() had a TODO concerning handling of same-type constraints -- this is the first test-case I've found that triggered the problem. - GenericEnvironment::getSubstitutionMap() incorrectly ignored same-type constraints where one of the two types was a generic parameter. Fixes <https://bugs.swift.org/browse/SR-3321>.
- Loading branch information
1 parent
b47eff1
commit 3cbc08c
Showing
4 changed files
with
96 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
validation-test/compiler_crashers_2_fixed/0059-sr3321.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %target-swift-frontend %s -emit-ir | ||
// RUN: %target-swift-frontend %s -emit-ir -O | ||
|
||
protocol ControllerB { | ||
associatedtype T: Controller | ||
} | ||
|
||
protocol Controller { | ||
associatedtype T | ||
|
||
func shouldSelect<S: ControllerB>(_ a: T, b: S) where S.T == Self | ||
} | ||
|
||
struct ControllerAImpl {} | ||
|
||
struct ControllerImpl : Controller { | ||
typealias T = ControllerAImpl | ||
|
||
func shouldSelect<S : ControllerB>(_ a: ControllerAImpl, b: S) where S.T == ControllerImpl {} | ||
} | ||
|
||
struct ControllerBImpl1 : ControllerB { | ||
typealias T = ControllerImpl | ||
} | ||
|
||
struct ControllerBImpl2<C : Controller> : ControllerB { | ||
typealias T = C | ||
} | ||
|
||
extension Controller { | ||
func didSelect<S: ControllerB>(_ a: T, b: S) where S.T == Self { | ||
shouldSelect(a, b: b) | ||
} | ||
} | ||
|
||
ControllerImpl().didSelect(ControllerAImpl(), b: ControllerBImpl1()) | ||
ControllerImpl().didSelect(ControllerAImpl(), b: ControllerBImpl2<ControllerImpl>()) |