Skip to content

Commit f39fb2d

Browse files
committed
IRGen: Correctly indicate non-key same-typed generic parameters.
The correct query here is whether the generic parameter is canonical within its generic signature, not whether it's concrete.
1 parent b842686 commit f39fb2d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ namespace {
223223

224224
for (auto param : canSig->getGenericParams()) {
225225
// Currently, there are only type parameters. The parameter is a key
226-
// argument if it hasn't been grounded by a same-type constraint.
226+
// argument if it's canonical in its generic context.
227227
asImpl().addGenericParameter(GenericParamKind::Type,
228-
/*key argument*/ !canSig->isConcreteType(param),
229-
/*extra argument*/ false);
228+
/*key argument*/ canSig->isCanonicalTypeInContext(param),
229+
/*extra argument*/ false);
230230
}
231231

232232
// Pad the structure up to four bytes for the following requirements.

test/IRGen/same_type_constraints.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir -primary-file %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
22
// RUN: %target-swift-frontend -Osize -assume-parsing-unqualified-ownership-sil -emit-ir -primary-file %s -disable-objc-attr-requires-foundation-module | %FileCheck %s --check-prefix=OSIZE
33

4+
// Ensure that same-type constraints between generic arguments get reflected
5+
// correctly in the type context descriptor.
6+
// CHECK-LABEL: @"$S21same_type_constraints4SG11VA2A2P2Rzq_RszrlE13InnerTEqualsUVMn" =
7+
// T U(==T) V padding
8+
// CHECK-SAME: , i8 -128, i8 0, i8 -128, i8 0,
9+
410
// <rdar://problem/21665983> IRGen crash with protocol extension involving same-type constraint to X<T>
511
public struct DefaultFoo<T> {
612
var t: T?
@@ -16,7 +22,8 @@ public extension P where Foo == DefaultFoo<Self> {
1622
}
1723
}
1824

19-
// CHECK: define{{( protected)?}} swiftcc void @"$S21same_type_constraints1PPA2A10DefaultFooVyxG0E0RtzrlE3fooAFyF"
25+
26+
// CHECK-LABEL: define{{( protected)?}} swiftcc void @"$S21same_type_constraints1PPA2A10DefaultFooVyxG0E0RtzrlE3fooAFyF"
2027

2128
// <rdar://26873036> IRGen crash with derived class declaring same-type constraint on constrained associatedtype.
2229
public class C1<T: Equatable> { }

0 commit comments

Comments
 (0)