Skip to content

Commit 3414609

Browse files
committed
[Tests] NFC: Expand init accessor with nonmutating set coverage
1 parent 24c4fcc commit 3414609

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

test/Interpreter/init_accessors.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ do {
865865

866866
struct TestNonMutatingSetNoDefault {
867867
var _count: Int
868+
var _other: String = ""
868869

869870
var count: Int {
870871
@storageRestrictions(initializes: _count)
@@ -917,7 +918,7 @@ do {
917918
// CHECK-NEXT: test-nonmutating-set-2: TestNonMutatingSetDefault(_count: 0)
918919
// CHECK-NEXT: init accessor is called: -1
919920
// CHECK-NEXT: nonmutating set called: 0
920-
// CHECK-NEXT: test-nonmutating-set-3: TestNonMutatingSetNoDefault(_count: -1)
921+
// CHECK-NEXT: test-nonmutating-set-3: TestNonMutatingSetNoDefault(_count: -1, _other: "")
921922
// CHECK-NEXT: init accessor is called: 42
922923
// CHECK-NEXT: nonmutating set called: 0
923924
// CHECK-NEXT: test-nonmutating-set-4: TestNonMutatingSetCustom(_count: 42)

test/SILOptimizer/init_accessor_raw_sil_lowering.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,49 @@ func test_handling_of_nonmutating_set() {
431431
self.count = 0
432432
}
433433
}
434+
435+
struct TestWithStored {
436+
private var _count: Int
437+
private var _text: String = ""
438+
439+
var count: Int {
440+
@storageRestrictions(initializes: _count)
441+
init { _count = newValue }
442+
get { _count }
443+
nonmutating set { }
444+
}
445+
446+
// CHECK-LABEL: sil private [ossa] @$s23assign_or_init_lowering32test_handling_of_nonmutating_setyyF14TestWithStoredL_V5countADSi_tcfC
447+
// CHECK: [[SELF_REF:%.*]] = mark_uninitialized [rootself] %2
448+
// CHECK: [[SELF:%.*]] = load [copy] {{.*}} : $*TestWithStored
449+
// CHECK: [[SETTER_REF:%.*]] = function_ref @$s23assign_or_init_lowering32test_handling_of_nonmutating_setyyF14TestWithStoredL_V5countSivs : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
450+
// CHECK-NEXT: [[SETTER_CLOSURE:%.*]] = partial_apply [callee_guaranteed] [on_stack] [[SETTER_REF]]([[SELF]]) : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
451+
// CHECK-NEXT: assign_or_init [init] #<abstract function>TestWithStored.count, self [[SELF_REF]] : $*TestWithStored, value %0 : $Int, init {{.*}} : $@convention(thin) (Int) -> @out Int, set [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
452+
// CHECK-NEXT: destroy_value [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
453+
// CHECK-NEXT: destroy_value [[SELF]] : $TestWithStored
454+
init(count: Int) {
455+
self.count = count
456+
}
457+
458+
// CHECK-LABEL: sil private [ossa] @$s23assign_or_init_lowering32test_handling_of_nonmutating_setyyF14TestWithStoredL_V5valueADSi_tcfC
459+
// CHECK: [[SELF_REF:%.*]] = mark_uninitialized [rootself] %2
460+
// CHECK: [[SELF:%.*]] = load [copy] {{.*}} : $*TestWithStored
461+
//
462+
// CHECK: [[SETTER_REF:%.*]] = function_ref @$s23assign_or_init_lowering32test_handling_of_nonmutating_setyyF14TestWithStoredL_V5countSivs : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
463+
// CHECK-NEXT: [[SETTER_CLOSURE:%.*]] = partial_apply [callee_guaranteed] [on_stack] [[SETTER_REF]]([[SELF]]) : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
464+
// CHECK-NEXT: assign_or_init [init] #<abstract function>TestWithStored.count, self [[SELF_REF]] : $*TestWithStored, value {{.*}} : $Int, init {{.*}} : $@convention(thin) (Int) -> @out Int, set [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
465+
// CHECK-NEXT: destroy_value [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
466+
// CHECK-NEXT: destroy_value [[SELF]] : $TestWithStored
467+
//
468+
// CHECK: [[SELF:%.*]] = load [copy] {{.*}} : $*TestWithStored
469+
// CHECK: [[SETTER_REF:%.*]] = function_ref @$s23assign_or_init_lowering32test_handling_of_nonmutating_setyyF14TestWithStoredL_V5countSivs : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
470+
// CHECK-NEXT: [[SETTER_CLOSURE:%.*]] = partial_apply [callee_guaranteed] [on_stack] [[SETTER_REF]]([[SELF]]) : $@convention(method) (Int, @guaranteed TestWithStored) -> ()
471+
// CHECK-NEXT: assign_or_init [set] #<abstract function>TestWithStored.count, self [[SELF_REF]] : $*TestWithStored, value %0 : $Int, init {{.*}} : $@convention(thin) (Int) -> @out Int, set [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
472+
// CHECK-NEXT: destroy_value [[SETTER_CLOSURE]] : $@noescape @callee_guaranteed (Int) -> ()
473+
// CHECK-NEXT: destroy_value [[SELF]] : $TestWithStored
474+
init(value: Int) {
475+
self.count = 0
476+
self.count = value
477+
}
478+
}
434479
}

0 commit comments

Comments
 (0)