Skip to content

Commit 563ebde

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 30c9981 commit 563ebde

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
@@ -172,7 +172,7 @@ class RecordTypeInfoImpl : public Base,
172172
return emitAssignWithCopyCall(IGF, T, dest, src);
173173
}
174174

175-
if (isOutlined || T.hasLocalArchetype()) {
175+
if (isOutlined || T.hasParameterizedExistential()) {
176176
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
177177
for (auto &field : getFields()) {
178178
if (field.isEmpty())
@@ -195,7 +195,7 @@ class RecordTypeInfoImpl : public Base,
195195
return emitAssignWithTakeCall(IGF, T, dest, src);
196196
}
197197

198-
if (isOutlined || T.hasLocalArchetype()) {
198+
if (isOutlined || T.hasParameterizedExistential()) {
199199
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
200200
for (auto &field : getFields()) {
201201
if (field.isEmpty())
@@ -225,7 +225,7 @@ class RecordTypeInfoImpl : public Base,
225225
return emitInitializeWithCopyCall(IGF, T, dest, src);
226226
}
227227

228-
if (isOutlined || T.hasLocalArchetype()) {
228+
if (isOutlined || T.hasParameterizedExistential()) {
229229
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
230230
for (auto &field : getFields()) {
231231
if (field.isEmpty())
@@ -257,7 +257,7 @@ class RecordTypeInfoImpl : public Base,
257257
return emitInitializeWithTakeCall(IGF, T, dest, src);
258258
}
259259

260-
if (isOutlined || T.hasLocalArchetype()) {
260+
if (isOutlined || T.hasParameterizedExistential()) {
261261
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
262262
for (auto &field : getFields()) {
263263
if (field.isEmpty())
@@ -280,7 +280,7 @@ class RecordTypeInfoImpl : public Base,
280280
return emitDestroyCall(IGF, T, addr);
281281
}
282282

283-
if (isOutlined || T.hasLocalArchetype()) {
283+
if (isOutlined || T.hasParameterizedExistential()) {
284284
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
285285
for (auto &field : getFields()) {
286286
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)