Skip to content

Commit b025679

Browse files
authored
Merge pull request swiftlang#40583 from slavapestov/sil-lowering-gsb-workaround
SIL: Workaround for GenericSignatureBuilder bug
2 parents 0f52da0 + 20a913d commit b025679

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,8 @@ class SubstFunctionTypePatternVisitor
16491649
newGPMapping.insert({gp, newParamTy});
16501650
auto substGPTy = Type(gp).subst(substGPMap)->castTo<GenericTypeParamType>();
16511651
substRequirements.push_back(Requirement(RequirementKind::SameType,
1652-
substGPTy,
1653-
newParamTy));
1652+
newParamTy,
1653+
substGPTy));
16541654
assert(!substReplacementTypes[substGPTy->getIndex()]);
16551655
substReplacementTypes[substGPTy->getIndex()] = substParamTy;
16561656
}

test/Generics/rdar86431977.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
2+
3+
protocol P1 {
4+
associatedtype A
5+
associatedtype B : P1 where B.A == A, B.B == B
6+
}
7+
8+
protocol P2 : P1 where A == Self {}
9+
10+
struct G<T, U> {}
11+
12+
// The GSB used to get the signature of bar() wrong.
13+
14+
extension G {
15+
// CHECK-LABEL: rdar86431977.(file).G extension.foo()@
16+
// CHECK: Generic signature: <T, U where T : P2, T == U>
17+
func foo() where T : P2, U == T {}
18+
19+
// CHECK-LABEL: rdar86431977.(file).G extension.bar()@
20+
// CHECK: Generic signature: <T, U where T : P2, T == U>
21+
func bar() where T : P2, T == U {}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-emit-silgen %s -requirement-machine-abstract-signatures=verify | %FileCheck %s
2+
3+
struct G<Key: CaseIterable, Value> where Key: RawRepresentable, Value: Codable {
4+
var key: Key.RawValue
5+
}
6+
7+
protocol P: CaseIterable, RawRepresentable {}
8+
9+
struct Value: Codable {}
10+
11+
enum Key: Int, P {
12+
case elt
13+
}
14+
15+
func callee<Key: P>(_: Key.Type, _: @escaping (G<Key, Value>) -> Void) {}
16+
17+
// CHECK-LABEL: sil hidden [ossa] @$s029type_lowering_subst_function_A20_requirement_machine6calleryyF : $@convention(thin) () -> () {
18+
// CHECK: function_ref @$s029type_lowering_subst_function_A20_requirement_machine6calleryyFyAA1GVyAA3KeyOAA5ValueVGcfU_ : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : CaseIterable, τ_0_0 : RawRepresentable, τ_0_0 == τ_0_2, τ_0_1 == Value> (@in_guaranteed G<τ_0_0, Value>) -> () for <Key, Value, Key>
19+
func caller() {
20+
callee(Key.self, { _ in })
21+
}
22+

0 commit comments

Comments
 (0)