Skip to content

Commit e5e7948

Browse files
authored
Merge pull request #85357 from slavapestov/workaround-rdar160649141
IRGen: Terrible workaround for problem in searchNominalTypeMetadata()
2 parents 05f98b2 + 1adfad0 commit e5e7948

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

lib/IRGen/Fulfillment.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,24 @@ bool FulfillmentMap::searchNominalTypeMetadata(IRGenModule &IGM,
380380

381381
for (unsigned reqtIndex : indices(requirements.getRequirements())) {
382382
auto requirement = requirements.getRequirements()[reqtIndex];
383-
auto arg = requirement.getTypeParameter().subst(subs)->getCanonicalType();
383+
384+
// FIXME: The correct fix is to pass down the substitution map's
385+
// output generic signature and reduce the result of subst() with
386+
// this signature before forming the lookup key.
387+
//
388+
// Once that's fixed, change the below back to this:
389+
// auto arg = requirement.getTypeParameter().subst(subs)->getCanonicalType();
390+
391+
auto arg = requirement.getTypeParameter().subst(
392+
QuerySubstitutionMap{subs},
393+
[&](InFlightSubstitution &IFS, Type origType, ProtocolDecl *proto)
394+
-> ProtocolConformanceRef {
395+
auto substType = origType.subst(IFS);
396+
if (substType->isTypeParameter())
397+
return ProtocolConformanceRef::forAbstract(substType, proto);
398+
399+
return subs.lookupConformance(origType->getCanonicalType(), proto);
400+
})->getCanonicalType();
384401

385402
// Skip uninteresting type arguments.
386403
if (!keys.hasInterestingType(arg))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -enable-library-evolution | %FileCheck %s
2+
3+
// FIXME: We just need to adjust the check line below, there's no inherent
4+
// reason for this not to be tested on wasm.
5+
// UNSUPPORTED: CPU=wasm32
6+
7+
// rdar://160649141
8+
9+
public protocol P1 {}
10+
11+
public protocol P2 {
12+
associatedtype A1
13+
}
14+
15+
public protocol P5 {
16+
associatedtype A2: P2
17+
}
18+
19+
public protocol P3 where A4.A1 == A3.A2.A1 {
20+
associatedtype A3: P5
21+
associatedtype A4: P2
22+
23+
var x: Int { get }
24+
}
25+
26+
public protocol P6: P3 {}
27+
28+
public protocol P4 {
29+
associatedtype A4: P2
30+
}
31+
32+
public struct G1<A1>: P2 {}
33+
34+
public struct G2<A2: P2>: P5 {}
35+
36+
public struct G3<T: P6 & P4>: P3 where T.A4.A1: P1 {
37+
public typealias A4 = G1<T.A3.A2.A1>
38+
public typealias A3 = G2<T.A3.A2>
39+
40+
// Make sure this witness thunk doesn't have any additional bogus parameters.
41+
42+
// CHECK-LABEL: define internal swiftcc i64 @"$s28fulfillment_map_key_equality2G3VyxGAA2P3A2aEP1xSivgTW"(ptr noalias swiftself captures(none) %0, ptr %Self, ptr %SelfWitnessTable) {{.*}} {
43+
public var x: Int { fatalError() }
44+
}

0 commit comments

Comments
 (0)