Skip to content

Commit 44dba8f

Browse files
committed
IRGen: Try harder not to emit calls to swift_getExtendedExistentialTypeMetadata()
This entry point doesn't exist on older runtimes. Sema enforces that constrained existentials don't appear in substitution maps, however IRGen would sometimes try to instantiate metadata even if the user didn't do that. Fixes #64657.
1 parent 6682d50 commit 44dba8f

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ namespace {
493493
if (!getSingleton()) return;
494494
if (!ElementsAreABIAccessible) {
495495
emitAssignWithCopyCall(IGF, T, dest, src);
496-
} else if (isOutlined || T.hasLocalArchetype()) {
496+
} else if (isOutlined || T.hasParameterizedExistential()) {
497497
dest = getSingletonAddress(IGF, dest);
498498
src = getSingletonAddress(IGF, src);
499499
getSingleton()->assignWithCopy(
@@ -508,7 +508,7 @@ namespace {
508508
if (!getSingleton()) return;
509509
if (!ElementsAreABIAccessible) {
510510
emitAssignWithTakeCall(IGF, T, dest, src);
511-
} else if (isOutlined || T.hasLocalArchetype()) {
511+
} else if (isOutlined || T.hasParameterizedExistential()) {
512512
dest = getSingletonAddress(IGF, dest);
513513
src = getSingletonAddress(IGF, src);
514514
getSingleton()->assignWithTake(
@@ -530,7 +530,7 @@ namespace {
530530
if (!getSingleton()) return;
531531
if (!ElementsAreABIAccessible) {
532532
emitInitializeWithCopyCall(IGF, T, dest, src);
533-
} else if (isOutlined || T.hasLocalArchetype()) {
533+
} else if (isOutlined || T.hasParameterizedExistential()) {
534534
dest = getSingletonAddress(IGF, dest);
535535
src = getSingletonAddress(IGF, src);
536536
getSingleton()->initializeWithCopy(
@@ -545,7 +545,7 @@ namespace {
545545
if (!getSingleton()) return;
546546
if (!ElementsAreABIAccessible) {
547547
emitInitializeWithTakeCall(IGF, T, dest, src);
548-
} else if (isOutlined || T.hasLocalArchetype()) {
548+
} else if (isOutlined || T.hasParameterizedExistential()) {
549549
dest = getSingletonAddress(IGF, dest);
550550
src = getSingletonAddress(IGF, src);
551551
getSingleton()->initializeWithTake(
@@ -601,7 +601,7 @@ namespace {
601601
!getSingleton()->isTriviallyDestroyable(ResilienceExpansion::Maximal)) {
602602
if (!ElementsAreABIAccessible) {
603603
emitDestroyCall(IGF, T, addr);
604-
} else if (isOutlined || T.hasLocalArchetype()) {
604+
} else if (isOutlined || T.hasParameterizedExistential()) {
605605
getSingleton()->destroy(IGF, getSingletonAddress(IGF, addr),
606606
getSingletonType(IGF.IGM, T), isOutlined);
607607
} else {
@@ -2754,7 +2754,7 @@ namespace {
27542754
}
27552755
if (!ElementsAreABIAccessible) {
27562756
return emitDestroyCall(IGF, T, addr);
2757-
} else if (isOutlined || T.hasLocalArchetype()) {
2757+
} else if (isOutlined || T.hasParameterizedExistential()) {
27582758
switch (CopyDestroyKind) {
27592759
case TriviallyDestroyable:
27602760
return;
@@ -3041,7 +3041,7 @@ namespace {
30413041
SILType T, bool isOutlined) const override {
30423042
if (!ElementsAreABIAccessible) {
30433043
emitAssignWithCopyCall(IGF, T, dest, src);
3044-
} else if (isOutlined || T.hasLocalArchetype()) {
3044+
} else if (isOutlined || T.hasParameterizedExistential()) {
30453045
emitIndirectAssign(IGF, dest, src, T, IsNotTake, isOutlined);
30463046
} else {
30473047
callOutlinedCopy(IGF, dest, src, T, IsNotInitialization, IsNotTake);
@@ -3052,7 +3052,7 @@ namespace {
30523052
SILType T, bool isOutlined) const override {
30533053
if (!ElementsAreABIAccessible) {
30543054
emitAssignWithTakeCall(IGF, T, dest, src);
3055-
} else if (isOutlined || T.hasLocalArchetype()) {
3055+
} else if (isOutlined || T.hasParameterizedExistential()) {
30563056
emitIndirectAssign(IGF, dest, src, T, IsTake, isOutlined);
30573057
} else {
30583058
callOutlinedCopy(IGF, dest, src, T, IsNotInitialization, IsTake);
@@ -3063,7 +3063,7 @@ namespace {
30633063
SILType T, bool isOutlined) const override {
30643064
if (!ElementsAreABIAccessible) {
30653065
emitInitializeWithCopyCall(IGF, T, dest, src);
3066-
} else if (isOutlined || T.hasLocalArchetype()) {
3066+
} else if (isOutlined || T.hasParameterizedExistential()) {
30673067
emitIndirectInitialize(IGF, dest, src, T, IsNotTake, isOutlined);
30683068
} else {
30693069
callOutlinedCopy(IGF, dest, src, T, IsInitialization, IsNotTake);
@@ -3074,7 +3074,7 @@ namespace {
30743074
SILType T, bool isOutlined) const override {
30753075
if (!ElementsAreABIAccessible) {
30763076
emitInitializeWithTakeCall(IGF, T, dest, src);
3077-
} else if (isOutlined || T.hasLocalArchetype()) {
3077+
} else if (isOutlined || T.hasParameterizedExistential()) {
30783078
emitIndirectInitialize(IGF, dest, src, T, IsTake, isOutlined);
30793079
} else {
30803080
callOutlinedCopy(IGF, dest, src, T, IsInitialization, IsTake);
@@ -4899,7 +4899,7 @@ namespace {
48994899
SILType T, bool isOutlined) const override {
49004900
if (!ElementsAreABIAccessible) {
49014901
emitAssignWithCopyCall(IGF, T, dest, src);
4902-
} else if (isOutlined || T.hasLocalArchetype()) {
4902+
} else if (isOutlined || T.hasParameterizedExistential()) {
49034903
emitIndirectAssign(IGF, dest, src, T, IsNotTake, isOutlined);
49044904
} else {
49054905
callOutlinedCopy(IGF, dest, src, T, IsNotInitialization, IsNotTake);
@@ -4910,7 +4910,7 @@ namespace {
49104910
SILType T, bool isOutlined) const override {
49114911
if (!ElementsAreABIAccessible) {
49124912
emitAssignWithTakeCall(IGF, T, dest, src);
4913-
} else if (isOutlined || T.hasLocalArchetype()) {
4913+
} else if (isOutlined || T.hasParameterizedExistential()) {
49144914
emitIndirectAssign(IGF, dest, src, T, IsTake, isOutlined);
49154915
} else {
49164916
callOutlinedCopy(IGF, dest, src, T, IsNotInitialization, IsTake);
@@ -4921,7 +4921,7 @@ namespace {
49214921
SILType T, bool isOutlined) const override {
49224922
if (!ElementsAreABIAccessible) {
49234923
emitInitializeWithCopyCall(IGF, T, dest, src);
4924-
} else if (isOutlined || T.hasLocalArchetype()) {
4924+
} else if (isOutlined || T.hasParameterizedExistential()) {
49254925
emitIndirectInitialize(IGF, dest, src, T, IsNotTake, isOutlined);
49264926
} else {
49274927
callOutlinedCopy(IGF, dest, src, T, IsInitialization, IsNotTake);
@@ -4932,7 +4932,7 @@ namespace {
49324932
SILType T, bool isOutlined) const override {
49334933
if (!ElementsAreABIAccessible) {
49344934
emitInitializeWithTakeCall(IGF, T, dest, src);
4935-
} else if (isOutlined || T.hasLocalArchetype()) {
4935+
} else if (isOutlined || T.hasParameterizedExistential()) {
49364936
emitIndirectInitialize(IGF, dest, src, T, IsTake, isOutlined);
49374937
} else {
49384938
callOutlinedCopy(IGF, dest, src, T, IsInitialization, IsTake);
@@ -4966,7 +4966,7 @@ namespace {
49664966
}
49674967
if (!ElementsAreABIAccessible) {
49684968
emitDestroyCall(IGF, T, addr);
4969-
} else if (isOutlined || T.hasLocalArchetype()) {
4969+
} else if (isOutlined || T.hasParameterizedExistential()) {
49704970
switch (CopyDestroyKind) {
49714971
case TriviallyDestroyable:
49724972
return;

lib/IRGen/GenRecord.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class RecordTypeInfoImpl : public Base,
170170
return emitAssignWithCopyCall(IGF, T, dest, src);
171171
}
172172

173-
if (isOutlined || T.hasLocalArchetype()) {
173+
if (isOutlined || T.hasParameterizedExistential()) {
174174
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
175175
for (auto &field : getFields()) {
176176
if (field.isEmpty())
@@ -193,7 +193,7 @@ class RecordTypeInfoImpl : public Base,
193193
return emitAssignWithTakeCall(IGF, T, dest, src);
194194
}
195195

196-
if (isOutlined || T.hasLocalArchetype()) {
196+
if (isOutlined || T.hasParameterizedExistential()) {
197197
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
198198
for (auto &field : getFields()) {
199199
if (field.isEmpty())
@@ -223,7 +223,7 @@ class RecordTypeInfoImpl : public Base,
223223
return emitInitializeWithCopyCall(IGF, T, dest, src);
224224
}
225225

226-
if (isOutlined || T.hasLocalArchetype()) {
226+
if (isOutlined || T.hasParameterizedExistential()) {
227227
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
228228
for (auto &field : getFields()) {
229229
if (field.isEmpty())
@@ -255,7 +255,7 @@ class RecordTypeInfoImpl : public Base,
255255
return emitInitializeWithTakeCall(IGF, T, dest, src);
256256
}
257257

258-
if (isOutlined || T.hasLocalArchetype()) {
258+
if (isOutlined || T.hasParameterizedExistential()) {
259259
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
260260
for (auto &field : getFields()) {
261261
if (field.isEmpty())
@@ -278,7 +278,7 @@ class RecordTypeInfoImpl : public Base,
278278
return emitDestroyCall(IGF, T, addr);
279279
}
280280

281-
if (isOutlined || T.hasLocalArchetype()) {
281+
if (isOutlined || T.hasParameterizedExistential()) {
282282
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
283283
for (auto &field : getFields()) {
284284
if (field.isTriviallyDestroyable())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-ir -O %s | %FileCheck %s
3+
4+
protocol Foo<T> {
5+
associatedtype T
6+
func acceptEvent<T>(event: T)
7+
}
8+
9+
protocol FooFactory<T> {
10+
associatedtype T
11+
func makeFoo() -> any Foo<T>
12+
}
13+
14+
class Bar<T> {
15+
private var foo: (any Foo<T>)
16+
17+
init(fooFactory: any FooFactory<T>) {
18+
self.foo = fooFactory.makeFoo()
19+
}
20+
}
21+
22+
// CHECK-NOT: swift_getExtendedExistentialTypeMetadata

test/IRGen/variadic_generic_outlining.sil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ struct Wrapper<Value> {
1616
// CHECK-NEXT: [[PACK:%.*]] = inttoptr [[INT]] [[PACK_ADDR2]] to %swift.type**
1717
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[PACK]], [[INT]]
1818
// CHECK-NEXT: [[ELT_TYPE:%.*]] = load %swift.type*, %swift.type** [[T0]], align
19+
// CHECK: [[WRAPPER_RESPONSE:%.*]] = call swiftcc %swift.metadata_response @"$s26variadic_generic_outlining7WrapperVMa"
20+
// CHECK-NEXT: [[WRAPPER_TYPE:%.*]] = extractvalue %swift.metadata_response [[WRAPPER_RESPONSE]]
1921
// Test that we do the copy through the VWT for the element type.
20-
// CHECK: [[T0:%.*]] = bitcast %swift.type* [[ELT_TYPE]] to i8***
22+
// CHECK-NEXT: [[T0:%.*]] = bitcast %swift.type* [[WRAPPER_TYPE]] to i8***
2123
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8**, i8*** [[T0]], [[INT]] -1
2224
sil hidden @test_outlining : $@convention(thin) <each T> (@pack_guaranteed Pack{repeat Wrapper<each T>}) -> @pack_out Pack{repeat Wrapper<each T>} {
2325
bb0(%0 : $*Pack{repeat Wrapper<each T>}, %1 : $*Pack{repeat Wrapper<each T>}):

0 commit comments

Comments
 (0)