Skip to content

Support for address based array initialization under opaque values mode #7470

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
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
22 changes: 12 additions & 10 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2965,16 +2965,18 @@ namespace {
// it's not already there. (Note that this potentially includes
// conventions which pass indirectly without transferring
// ownership, like Itanium C++.)
if (SGF.silConv.isSILIndirect(param)) {
if (specialDest) {
emitIndirectInto(std::move(arg), origParamType,
loweredSubstParamType, *specialDest);
Args.push_back(ManagedValue::forInContext());
} else {
auto value = emitIndirect(std::move(arg), loweredSubstArgType,
origParamType, param);
Args.push_back(value);
}
if (specialDest) {
assert(param.isFormalIndirect() &&
"SpecialDest should imply indirect parameter");
// TODO: Change the way we initialize array storage in opaque mode
emitIndirectInto(std::move(arg), origParamType, loweredSubstParamType,
*specialDest);
Args.push_back(ManagedValue::forInContext());
return;
} else if (SGF.silConv.isSILIndirect(param)) {
auto value = emitIndirect(std::move(arg), loweredSubstArgType,
origParamType, param);
Args.push_back(value);
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 @@ -8,6 +8,24 @@ protocol P {
var x : Int { get }
}

func hasVarArg(_ args: Any...) {}

// Test that we still use addresses when dealing with array initialization
// ---
// CHECK-LABEL: sil @_TF20opaque_values_silgen10callVarArgFT_T_ : $@convention(thin) () -> () {
// CHECK: %[[APY:.*]] = apply %{{.*}}<Any>(%{{.*}}) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
// CHECK: %[[BRW:.*]] = begin_borrow %[[APY]]
// CHECK: %[[TPL:.*]] = tuple_extract %[[BRW]] : $(Array<Any>, Builtin.RawPointer), 1
// CHECK: end_borrow %[[BRW]] from %[[APY]] : $(Array<Any>, Builtin.RawPointer), $(Array<Any>, Builtin.RawPointer)
// CHECK: destroy_value %[[APY]]
// CHECK: %[[PTR:.*]] = pointer_to_address %[[TPL]] : $Builtin.RawPointer to [strict] $*Any
// CHECK: init_existential_addr %[[PTR]] : $*Any, $Int
// CHECK: return %{{.*}} : $()
// CHECK: } // end sil function '_TF20opaque_values_silgen10callVarArgFT_T_'
public func callVarArg() {
hasVarArg(3)
}

// Test emitSemanticStore.
// ---
// CHECK-LABEL: sil hidden @_TF20opaque_values_silgen11assigninouturFTRxx_T_ : $@convention(thin) <T> (@inout T, @in T) -> () {
Expand Down
7 changes: 0 additions & 7 deletions test/SILGen/opaque_values_silgen_todo.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
// RUN: %target-swift-frontend -enable-sil-opaque-values -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen %s | %FileCheck %s
// REQUIRES: EnableSILOpaqueValues

func hasVarArg(_ args: Any...) {}

// ArgEmitter: fix SpecialDest args.
public func callVarArg() {
hasVarArg(3)
}