Skip to content

Commit c6942ee

Browse files
authored
Merge pull request #63392 from gottesmm/pr-edebfaea60c9ef3f6834b82c2f5155097c04c93b
[move-only][no-implicit-copy] Some small fixes
2 parents 7b317c0 + 37024f1 commit c6942ee

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyObjectChecker.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,14 @@ void MoveOnlyChecker::check(DominanceInfo *domTree, PostOrderAnalysis *poa) {
554554
if (!diagnosticEmitter.emittedDiagnosticForValue(markedInst)) {
555555
if (markedInst->getCheckKind() == MarkMustCheckInst::CheckKind::NoCopy) {
556556
if (auto *cvi = dyn_cast<CopyValueInst>(markedInst->getOperand())) {
557-
if (auto *arg = dyn_cast<SILFunctionArgument>(cvi->getOperand())) {
557+
SingleValueInstruction *i = cvi;
558+
if (auto *copyToMoveOnly =
559+
dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
560+
cvi->getOperand())) {
561+
i = copyToMoveOnly;
562+
}
563+
564+
if (auto *arg = dyn_cast<SILFunctionArgument>(i->getOperand(0))) {
558565
if (arg->getOwnershipKind() == OwnershipKind::Guaranteed) {
559566
for (auto *use : markedInst->getConsumingUses()) {
560567
destroys.push_back(cast<DestroyValueInst>(use->getUser()));

test/SILOptimizer/noimplicitcopy.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -sil-move-only-object-checker %s
2+
3+
//////////////////
4+
// Declarations //
5+
//////////////////
6+
7+
class Klass {}
8+
9+
sil @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
10+
11+
///////////
12+
// Tests //
13+
///////////
14+
15+
// This test makes sure that we eliminate %2 after checking and that
16+
// sil-verify-all does not trigger.
17+
sil [ossa] @test_remove_early_copyvalue : $@convention(thin) (@guaranteed Klass) -> () {
18+
bb0(%0 : @noImplicitCopy @guaranteed $Klass):
19+
%1 = copyable_to_moveonlywrapper [guaranteed] %0 : $Klass
20+
%2 = copy_value %1 : $@moveOnly Klass
21+
%3 = mark_must_check [no_copy] %2 : $@moveOnly Klass
22+
debug_value %3 : $@moveOnly Klass, let, name "x2", argno 1
23+
%5 = begin_borrow %3 : $@moveOnly Klass
24+
%6 = function_ref @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
25+
%7 = moveonlywrapper_to_copyable [guaranteed] %5 : $@moveOnly Klass
26+
%8 = apply %6(%7) : $@convention(thin) (@guaranteed Klass) -> ()
27+
end_borrow %5 : $@moveOnly Klass
28+
destroy_value %3 : $@moveOnly Klass
29+
%11 = tuple ()
30+
return %11 : $()
31+
}

test/SILOptimizer/noimplicitcopy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-move-only -verify %s -parse-stdlib -emit-sil
1+
// RUN: %target-swift-frontend -sil-verify-all -enable-experimental-move-only -verify %s -parse-stdlib -emit-sil
22

33
import Swift
44

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %target-sil-opt -verify -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses -enable-sil-verify-all -sil-move-only-borrow-to-destructure %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
7+
//////////////////
8+
// Declarations //
9+
//////////////////
10+
11+
class Klass {}
12+
13+
struct AggStruct {
14+
var lhs: Klass
15+
var rhs: Klass
16+
}
17+
18+
sil @classConsume : $@convention(thin) (@owned Klass) -> ()
19+
20+
// We shouldn't emit any errors here since while AggStruct is no implicit copy,
21+
// its fields are not, so we can copy them.
22+
sil [ossa] @aggStructConsumeField : $@convention(thin) (@guaranteed AggStruct) -> () {
23+
bb0(%0 : @guaranteed $AggStruct):
24+
debug_value %0 : $AggStruct, let, name "x", argno 1
25+
%2 = copy_value %0 : $AggStruct
26+
%3 = begin_borrow [lexical] %2 : $AggStruct
27+
%4 = copy_value %3 : $AggStruct
28+
%5 = copyable_to_moveonlywrapper [owned] %4 : $AggStruct
29+
%6 = mark_must_check [no_implicit_copy] %5 : $@moveOnly AggStruct
30+
debug_value %6 : $@moveOnly AggStruct, let, name "x2"
31+
%8 = begin_borrow %6 : $@moveOnly AggStruct
32+
%9 = struct_extract %8 : $@moveOnly AggStruct, #AggStruct.lhs
33+
%10 = copy_value %9 : $@moveOnly Klass
34+
%11 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
35+
%12 = moveonlywrapper_to_copyable [owned] %10 : $@moveOnly Klass
36+
%13 = apply %11(%12) : $@convention(thin) (@owned Klass) -> ()
37+
end_borrow %8 : $@moveOnly AggStruct
38+
br bb1
39+
40+
bb1:
41+
cond_br undef, bb2, bb3
42+
43+
bb2:
44+
%52 = begin_borrow %6 : $@moveOnly AggStruct
45+
%53 = struct_extract %52 : $@moveOnly AggStruct, #AggStruct.lhs
46+
%54 = copy_value %53 : $@moveOnly Klass
47+
%55 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
48+
%56 = moveonlywrapper_to_copyable [owned] %54 : $@moveOnly Klass
49+
%57 = apply %55(%56) : $@convention(thin) (@owned Klass) -> ()
50+
end_borrow %52 : $@moveOnly AggStruct
51+
br bb1
52+
53+
bb3:
54+
destroy_value %6 : $@moveOnly AggStruct
55+
end_borrow %3 : $AggStruct
56+
destroy_value %2 : $AggStruct
57+
%64 = tuple ()
58+
return %64 : $()
59+
}

test/SILOptimizer/noimplicitcopy_trivial.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-move-only -verify %s -parse-stdlib -emit-sil
1+
// RUN: %target-swift-frontend -sil-verify-all -enable-experimental-move-only -verify %s -parse-stdlib -emit-sil
22

33
import Swift
44

0 commit comments

Comments
 (0)