Skip to content

Commit 1f01767

Browse files
author
Joe Shajrawi
authored
Merge pull request #8100 from shajrawi/ImplicitValueConstructor
Support Implicit Value Construction under Opaque value mode
2 parents 9da79dd + c8618fa commit 1f01767

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void emitImplicitValueConstructor(SILGenFunction &gen,
8888

8989
// Emit the indirect return argument, if any.
9090
SILValue resultSlot;
91-
if (selfTy.isAddressOnly(gen.SGM.M)) {
91+
if (selfTy.isAddressOnly(gen.SGM.M) && gen.silConv.useLoweredAddresses()) {
9292
auto &AC = gen.getASTContext();
9393
auto VD = new (AC) ParamDecl(/*IsLet*/ false, SourceLoc(), SourceLoc(),
9494
AC.getIdentifier("$return_value"),

test/SILGen/opaque_values_silgen.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ protocol P {
1010
var x : Int { get }
1111
}
1212

13+
struct Box<T> {
14+
let t: T
15+
}
16+
1317
func s010_hasVarArg(_ args: Any...) {}
1418

1519
// Test that we still use addresses when dealing with array initialization
@@ -392,9 +396,24 @@ func s240_____propOfLValue(_ x: Error) -> String {
392396
return x._domain
393397
}
394398

399+
// Tests Implicit Value Construction under Opaque value mode
400+
// ---
401+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s250_________testBoxTyyF : $@convention(thin) () -> () {
402+
// CHECK: bb0:
403+
// CHECK: [[BOX_MTYPE:%.*]] = metatype $@thin Box<Int>.Type
404+
// CHECK: [[MTYPE:%.*]] = metatype $@thin Int.Type
405+
// CHECK: [[INTLIT:%.*]] = integer_literal $Builtin.Int2048, 42
406+
// CHECK: [[AINT:%.*]] = apply {{.*}}([[INTLIT]], [[MTYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
407+
// CHECK: apply {{.*}}<Int>([[AINT]], [[BOX_MTYPE]]) : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Box<τ_0_0>.Type) -> @out Box<τ_0_0>
408+
// CHECK: return %{{.*}} : $()
409+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s250_________testBoxTyyF'
410+
func s250_________testBoxT() {
411+
let _ = Box(t: 42)
412+
}
413+
395414
// Tests conditional value casts and correspondingly generated reabstraction thunk, with <T> types
396415
// ---
397-
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s250_____condTFromAnyyyp_xtlF : $@convention(thin) <T> (@in Any, @in T) -> () {
416+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s999_____condTFromAnyyyp_xtlF : $@convention(thin) <T> (@in Any, @in T) -> () {
398417
// CHECK: bb0([[ARG0:%.*]] : $Any, [[ARG1:%.*]] : $T):
399418
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG0]]
400419
// CHECK: [[COPY__ARG:%.*]] = copy_value [[BORROWED_ARG]]
@@ -404,12 +423,21 @@ func s240_____propOfLValue(_ x: Error) -> String {
404423
// CHECK: partial_apply [[THUNK_REF]]<T>([[THUNK_PARAM]])
405424
// CHECK: bb6:
406425
// CHECK: return %{{.*}} : $()
407-
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s250_____condTFromAnyyyp_xtlF'
408-
func s250_____condTFromAny<T>(_ x: Any, _ y: T) {
426+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s999_____condTFromAnyyyp_xtlF'
427+
func s999_____condTFromAny<T>(_ x: Any, _ y: T) {
409428
if let f = x as? (Int, T) -> (Int, T) {
410429
f(42, y)
411430
}
412431
}
432+
433+
// s250_________testBoxT continued Tests Implicit Value Construction under Opaque value mode
434+
// ---
435+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen3BoxVACyxGx1t_tcfC : $@convention(method) <T> (@in T, @thin Box<T>.Type) -> @out Box<T> {
436+
// CHECK: bb0([[ARG0:%.*]] : $T, [[ARG1:%.*]] : $@thin Box<T>.Type):
437+
// CHECK: [[RETVAL:%.*]] = struct $Box<T> ([[ARG0]] : $T)
438+
// CHECK: return [[RETVAL]] : $Box<T>
439+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen3BoxVACyxGx1t_tcfC'
440+
413441
// CHECK-LABEL: sil shared [transparent] [reabstraction_thunk] @{{.*}} : $@convention(thin) (Int, Int, Int, Int, Int, @owned @callee_owned (@in (Int, (Int, (Int, Int)), Int)) -> @out (Int, (Int, (Int, Int)), Int)) -> (Int, Int, Int, Int, Int)
414442
// CHECK: bb0([[ARG0:%.*]] : $Int, [[ARG1:%.*]] : $Int, [[ARG2:%.*]] : $Int, [[ARG3:%.*]] : $Int, [[ARG4:%.*]] : $Int, [[ARG5:%.*]] : $@callee_owned (@in (Int, (Int, (Int, Int)), Int)) -> @out (Int, (Int, (Int, Int)), Int)):
415443
// CHECK: [[TUPLE_TO_APPLY0:%.*]] = tuple ([[ARG2]] : $Int, [[ARG3]] : $Int)

0 commit comments

Comments
 (0)