Skip to content

Add support for composition erasure + store of copy for opaque value types #7815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/SIL/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,14 +1111,6 @@ namespace {
llvm_unreachable("copy into");
}

// --- Same as NonTrivialLoadableTypeLowering

void emitStoreOfCopy(SILBuilder &B, SILLocation loc,
SILValue newValue, SILValue addr,
IsInitialization_t isInit) const override {
llvm_unreachable("store copy");
}

// --- Same as LeafLoadableTypeLowering.

SILValue emitLoweredCopyValue(SILBuilder &B, SILLocation loc,
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/ManagedValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ManagedValue ManagedValue::formalAccessCopy(SILGenFunction &gen,
void ManagedValue::copyInto(SILGenFunction &gen, SILValue dest,
SILLocation loc) {
auto &lowering = gen.getTypeLowering(getType());
if (lowering.isAddressOnly()) {
if (lowering.isAddressOnly() && gen.silConv.useLoweredAddresses()) {
gen.B.createCopyAddr(loc, getValue(), dest, IsNotTake, IsInitialization);
return;
}
Expand Down
18 changes: 18 additions & 0 deletions test/SILGen/opaque_values_silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,21 @@ func s190___return_foo_var() -> Foo {
func s200______use_foo_var() {
foo_var.foo()
}

// Tests composition erasure of opaque existentials + copy into of opaques
// ---
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s210______compErasures5Error_psAC_AA3FoopF : $@convention(thin) (@in Error & Foo) -> @owned Error {
// CHECK: bb0([[ARG:%.*]] : $Error & Foo):
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
// CHECK: [[OPAQUE_ARG:%.*]] = open_existential_opaque [[BORROWED_ARG]] : $Error & Foo to $@opened({{.*}}) Error & Foo
// CHECK: [[EXIST_BOX:%.*]] = alloc_existential_box $Error, $@opened({{.*}}) Error & Foo
// CHECK: [[PROJ_BOX:%.*]] = project_existential_box $@opened({{.*}}) Error & Foo in [[EXIST_BOX]]
// CHECK: [[COPY_OPAQUE:%.*]] = copy_value [[OPAQUE_ARG]] : $@opened({{.*}}) Error & Foo
// CHECK: store [[COPY_OPAQUE]] to [init] [[PROJ_BOX]] : $*@opened({{.*}}) Error & Foo
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]]
// CHECK: destroy_value [[ARG]] : $Error & Foo
// CHECK: return [[EXIST_BOX]] : $Error
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s210______compErasures5Error_psAC_AA3FoopF'
func s210______compErasure(_ x: Foo & Error) -> Error {
return x
}