Skip to content

Commit 6e46da7

Browse files
committed
SIL: Workaround for GenericSignatureBuilder bug
The GSB will drop same-type requirements sometimes, when the right hand side is smaller than the left. Change the order when adding these requirements, which seems to work well enough for my reduced testcase. Also, ensure that everything works correctly with the RequirementMachine, which doesn't have the same underlying problems with same-type requirement handling. Fixes rdar://86431977.
1 parent bb1d1ae commit 6e46da7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-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
}
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 | %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)