Skip to content

Commit 48c10aa

Browse files
author
Joe Shajrawi
authored
Merge pull request #7815 from shajrawi/composition_erasure
Add support for composition erasure + copy into for opaque value types
2 parents 032d053 + 4cdf894 commit 48c10aa

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,6 @@ namespace {
11111111
llvm_unreachable("copy into");
11121112
}
11131113

1114-
// --- Same as NonTrivialLoadableTypeLowering
1115-
1116-
void emitStoreOfCopy(SILBuilder &B, SILLocation loc,
1117-
SILValue newValue, SILValue addr,
1118-
IsInitialization_t isInit) const override {
1119-
llvm_unreachable("store copy");
1120-
}
1121-
11221114
// --- Same as LeafLoadableTypeLowering.
11231115

11241116
SILValue emitLoweredCopyValue(SILBuilder &B, SILLocation loc,

lib/SILGen/ManagedValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ManagedValue ManagedValue::formalAccessCopy(SILGenFunction &gen,
6060
void ManagedValue::copyInto(SILGenFunction &gen, SILValue dest,
6161
SILLocation loc) {
6262
auto &lowering = gen.getTypeLowering(getType());
63-
if (lowering.isAddressOnly()) {
63+
if (lowering.isAddressOnly() && gen.silConv.useLoweredAddresses()) {
6464
gen.B.createCopyAddr(loc, getValue(), dest, IsNotTake, IsInitialization);
6565
return;
6666
}

test/SILGen/opaque_values_silgen.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,21 @@ func s190___return_foo_var() -> Foo {
307307
func s200______use_foo_var() {
308308
foo_var.foo()
309309
}
310+
311+
// Tests composition erasure of opaque existentials + copy into of opaques
312+
// ---
313+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s210______compErasures5Error_psAC_AA3FoopF : $@convention(thin) (@in Error & Foo) -> @owned Error {
314+
// CHECK: bb0([[ARG:%.*]] : $Error & Foo):
315+
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
316+
// CHECK: [[OPAQUE_ARG:%.*]] = open_existential_opaque [[BORROWED_ARG]] : $Error & Foo to $@opened({{.*}}) Error & Foo
317+
// CHECK: [[EXIST_BOX:%.*]] = alloc_existential_box $Error, $@opened({{.*}}) Error & Foo
318+
// CHECK: [[PROJ_BOX:%.*]] = project_existential_box $@opened({{.*}}) Error & Foo in [[EXIST_BOX]]
319+
// CHECK: [[COPY_OPAQUE:%.*]] = copy_value [[OPAQUE_ARG]] : $@opened({{.*}}) Error & Foo
320+
// CHECK: store [[COPY_OPAQUE]] to [init] [[PROJ_BOX]] : $*@opened({{.*}}) Error & Foo
321+
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]]
322+
// CHECK: destroy_value [[ARG]] : $Error & Foo
323+
// CHECK: return [[EXIST_BOX]] : $Error
324+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s210______compErasures5Error_psAC_AA3FoopF'
325+
func s210______compErasure(_ x: Foo & Error) -> Error {
326+
return x
327+
}

0 commit comments

Comments
 (0)