Skip to content

Commit 373cc84

Browse files
committed
[SILGen] Move non-trivial none-ownership values.
All non-trivial values which correspond to `VarDecl`s must be marked appropriately so that they can be found by the relevant checker. Here, values with none ownership are marked.
1 parent 24c9046 commit 373cc84

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,12 @@ class LetValueInitialization : public Initialization {
800800
ConsumableAndAssignable);
801801
}
802802

803+
if (!value->getType().isTrivial(SGF.F)) {
804+
// A value without ownership of non-trivial type, e.g. Optional<K>.none.
805+
// Mark that it is from a VarDecl.
806+
return SGF.B.createMoveValue(PrologueLoc, value, IsNotLexical,
807+
DoesNotHavePointerEscape, IsFromVarDecl);
808+
}
803809

804810
return value;
805811
}

test/Concurrency/flow_isolation.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,7 @@ actor OhBrother {
706706
let blah = { (x: OhBrother) -> Int in 0 }
707707
giver = blah
708708

709-
// TODO: would be nice if we didn't say "after this closure" since it's not a capture, but a call.
710-
711-
_ = blah(self) // expected-note {{after this closure involving 'self', only non-isolated properties of 'self' can be accessed from this init}}
709+
_ = blah(self) // expected-note {{after a call involving 'self', only non-isolated properties of 'self' can be accessed from this init}}
712710

713711
whatever = 2 // expected-warning {{cannot access property 'whatever' here in non-isolated initializer; this is an error in the Swift 6 language mode}}
714712
}
@@ -788,7 +786,7 @@ func testActorWithInitAccessorInit() {
788786
let escapingSelf: (EscapeBeforeFullInit) -> Void = { _ in }
789787

790788
escapingSelf(self) // expected-error {{'self' used before all stored properties are initialized}}
791-
// expected-note@-1 {{after this closure involving 'self', only non-isolated properties of 'self' can be accessed from this init}}
789+
// expected-note@-1 {{after a call involving 'self', only non-isolated properties of 'self' can be accessed from this init}}
792790

793791
self.a = v
794792
// expected-warning@-1 {{cannot access property '_a' here in non-isolated initializer; this is an error in the Swift 6 language mode}}

test/SILGen/async_conversion.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ actor A: P2 {
4747
// CHECK: hop_to_executor {{.*}} : $MainActor
4848
// CHECK: [[F:%.*]] = function_ref @$s4test11mainActorFnyyF : $@convention(thin) () -> ()
4949
// CHECK: [[THICK_F:%.*]] = thin_to_thick_function [[F]] : $@convention(thin) () -> () to $@callee_guaranteed () -> ()
50+
// CHECK: [[THICK_F_VAR:%.*]] = move_value [var_decl] [[THICK_F]]
51+
// CHECK: [[THICK_F_BORROW:%.*]] = begin_borrow [[THICK_F_VAR]]
52+
// CHECK: [[THICK_F_COPY:%.*]] = copy_value [[THICK_F_BORROW]]
5053
// CHECK: [[THUNK:%.*]] = function_ref @$sIeg_IegH_TR : $@convention(thin) @async (@guaranteed @callee_guaranteed () -> ()) -> ()
51-
// CHECK: = partial_apply [callee_guaranteed] [[THUNK]]([[THICK_F]]) : $@convention(thin) @async (@guaranteed @callee_guaranteed () -> ()) -> ()
54+
// CHECK: = partial_apply [callee_guaranteed] [[THUNK]]([[THICK_F_COPY]]) : $@convention(thin) @async (@guaranteed @callee_guaranteed () -> ()) -> ()
5255
// ... after applying ...
5356
// CHECK: hop_to_executor {{.*}} : $MainActor
5457
let f: () -> () = mainActorFn

test/SILGen/cf_members.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public func foo(_ x: Double) {
3939

4040
// CHECK: [[FN:%.*]] = function_ref @$s10cf_members3fooyySdFSo10IAMStruct1VSdcfu_ : $@convention(thin) (Double) -> Struct1
4141
// CHECK: [[A:%.*]] = thin_to_thick_function [[FN]]
42-
// CHECK: [[BORROWED_A:%.*]] = begin_borrow [[A]]
42+
// CHECK: [[MOVED_A:%.*]] = move_value [var_decl] [[A]]
43+
// CHECK: [[BORROWED_A:%.*]] = begin_borrow [[MOVED_A]]
44+
// CHECK: [[COPIED_A:%.*]] = copy_value [[BORROWED_A]]
45+
// CHECK: [[BORROWED_A:%.*]] = begin_borrow [[COPIED_A]]
4346
let a: (Double) -> Struct1 = Struct1.init(value:)
4447
// CHECK: [[NEW_Z_VALUE:%.*]] = apply [[BORROWED_A]]([[X]])
4548
// CHECK: end_borrow [[BORROWED_A]]
@@ -78,10 +81,13 @@ public func foo(_ x: Double) {
7881
z = c(x)
7982
// CHECK: [[THUNK:%.*]] = function_ref @$s10cf_members3fooyySdFSo10IAMStruct1VSdcADcfu2_ : $@convention(thin) (Struct1) -> @owned @callee_guaranteed (Double) -> Struct1
8083
// CHECK: [[THICK:%.*]] = thin_to_thick_function [[THUNK]]
84+
// CHECK: [[MOVED_THICK:%.*]] = move_value [var_decl] [[THICK]]
85+
// CHECK: [[BORROWED_THICK:%.*]] = begin_borrow [[MOVED_THICK]]
86+
// CHECK: [[COPIED_THICK:%.*]] = copy_value [[BORROWED_THICK]]
8187
let d: (Struct1) -> (Double) -> Struct1 = Struct1.translate(radians:)
8288
// CHECK: [[READ:%.*]] = begin_access [read] [unknown] [[Z]] : $*Struct1
8389
// CHECK: [[ZVAL:%.*]] = load [trivial] [[READ]]
84-
// CHECK: [[THICK_BORROW:%.*]] = begin_borrow [[THICK]]
90+
// CHECK: [[THICK_BORROW:%.*]] = begin_borrow [[COPIED_THICK]]
8591
// CHECK: apply [[THICK_BORROW]]([[ZVAL]])
8692
// CHECK: end_borrow [[THICK_BORROW]]
8793
z = d(z)(x)
@@ -156,8 +162,11 @@ public func foo(_ x: Double) {
156162
var y = Struct1.staticMethod()
157163
// CHECK: [[THUNK:%.*]] = function_ref @$s10cf_members3fooyySdFs5Int32Vycfu8_ : $@convention(thin) () -> Int32
158164
// CHECK: [[I2:%.*]] = thin_to_thick_function [[THUNK]]
165+
// CHECK: [[MOVED_I2:%.*]] = move_value [var_decl] [[I2]]
166+
// CHECK: [[BORROWED_I2:%.*]] = begin_borrow [[MOVED_I2]]
167+
// CHECK: [[COPIED_I2:%.*]] = copy_value [[BORROWED_I2]]
159168
let i = Struct1.staticMethod
160-
// CHECK: [[BORROWED_I2:%.*]] = begin_borrow [[I2]]
169+
// CHECK: [[BORROWED_I2:%.*]] = begin_borrow [[COPIED_I2]]
161170
// CHECK: apply [[BORROWED_I2]]()
162171
y = i()
163172

test/SILGen/implicitly_unwrapped_optional.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ func f_46343() {
7373
// Verify that there are no additional reabstractions introduced.
7474
// CHECK: [[CLOSURE:%.+]] = function_ref @$s29implicitly_unwrapped_optional7f_46343yyFyypSgcfU_ : $@convention(thin) (@in_guaranteed Optional<Any>) -> ()
7575
// CHECK: [[F:%.+]] = thin_to_thick_function [[CLOSURE]] : $@convention(thin) (@in_guaranteed Optional<Any>) -> () to $@callee_guaranteed (@in_guaranteed Optional<Any>) -> ()
76-
// CHECK: [[BORROWED_F:%.*]] = begin_borrow [[F]]
76+
// CHECK: [[MOVED_F:%.*]] = move_value [var_decl] [[F]]
77+
// CHECK: [[BORROWED_F:%.*]] = begin_borrow [[MOVED_F]]
78+
// CHECK: [[COPIED_F:%.*]] = copy_value [[BORROWED_F]]
79+
// CHECK: [[BORROWED_F:%.*]] = begin_borrow [[COPIED_F]]
7780
// CHECK: = apply [[BORROWED_F]]({{%.+}}) : $@callee_guaranteed (@in_guaranteed Optional<Any>) -> ()
7881
// CHECK: end_borrow [[BORROWED_F]]
7982
let f: ((Any?) -> Void) = { (arg: Any!) in }

test/SILOptimizer/consume_operator_kills_copyable_values.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ public func castTestIfLet2(_ x : __owned EnumWithKlass) { // expected-error {{'x
362362
}
363363
}
364364

365+
func f(x:[Int]?)
366+
{
367+
}
368+
func g()
369+
{
370+
let x:[Int]? = nil
371+
f(x: consume x)
372+
}
373+
365374
/////////////////////////
366375
// Partial Apply Tests //
367376
/////////////////////////

0 commit comments

Comments
 (0)