Skip to content

Commit 1696769

Browse files
committed
reword diagnostics for partial consume of fields
1 parent f5b04cc commit 1696769

File tree

3 files changed

+36
-53
lines changed

3 files changed

+36
-53
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,9 @@ ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed, none,
773773
"cannot consume noncopyable stored property '%0' %select{of a class|that is global}1",
774774
(StringRef, bool))
775775

776-
ERROR(sil_moveonlychecker_cannot_destructure_deinit_nominal_type_self, none,
777-
"Cannot partially consume '%0' since it has a user defined deinit",
776+
ERROR(sil_moveonlychecker_cannot_destructure_has_deinit, none,
777+
"cannot partially consume '%0' since it has a user defined deinit",
778778
(StringRef))
779-
ERROR(sil_moveonlychecker_cannot_destructure_deinit_nominal_type_field, none,
780-
"Cannot partially consume '%0' since it contains field '%1.%2' whose type %3 has a user defined deinit",
781-
(StringRef, StringRef, StringRef, DeclBaseName))
782779

783780
NOTE(sil_moveonlychecker_partial_consume_here, none,
784781
"partial consume here", ())

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -683,25 +683,21 @@ void DiagnosticEmitter::emitCannotDestructureDeinitNominalError(
683683
MarkMustCheckInst *markedValue, StringRef pathString,
684684
NominalTypeDecl *deinitedNominal, SILInstruction *consumingUser) {
685685
auto &astContext = fn->getASTContext();
686+
686687
SmallString<64> varName;
687688
getVariableNameForValue(markedValue, varName);
688689

690+
if (!pathString.empty())
691+
varName.append(pathString);
692+
693+
diagnose(
694+
astContext, consumingUser,
695+
diag::sil_moveonlychecker_cannot_destructure_has_deinit,
696+
varName);
689697
registerDiagnosticEmitted(markedValue);
690698

691-
if (pathString.empty()) {
692-
diagnose(
693-
astContext, markedValue,
694-
diag::sil_moveonlychecker_cannot_destructure_deinit_nominal_type_self,
695-
varName);
696-
} else {
697-
diagnose(
698-
astContext, markedValue,
699-
diag::sil_moveonlychecker_cannot_destructure_deinit_nominal_type_field,
700-
varName, varName, pathString.drop_front(),
701-
deinitedNominal->getBaseName());
702-
}
703-
diagnose(astContext, consumingUser,
704-
diag::sil_moveonlychecker_consuming_use_here);
705-
astContext.Diags.diagnose(deinitedNominal->getValueTypeDestructor(),
706-
diag::sil_moveonlychecker_deinit_here);
699+
// point to the deinit if we know where it is.
700+
if (auto deinitLoc =
701+
deinitedNominal->getValueTypeDestructor()->getLoc(/*SerializedOK=*/false))
702+
astContext.Diags.diagnose(deinitLoc, diag::sil_moveonlychecker_deinit_here);
707703
}

test/SILOptimizer/moveonly_addresschecker_destructure_through_deinit_diagnostics.swift

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,7 @@ struct DeinitStruct {
5858
var fourth: (MoveOnlyKlass, MoveOnlyKlass)
5959
var fifth: MoveOnlyKlass
6060

61-
deinit {}
62-
// expected-note @-1 {{deinit declared here}}
63-
// expected-note @-2 {{deinit declared here}}
64-
// expected-note @-3 {{deinit declared here}}
65-
// expected-note @-4 {{deinit declared here}}
66-
// expected-note @-5 {{deinit declared here}}
67-
// expected-note @-6 {{deinit declared here}}
68-
// expected-note @-7 {{deinit declared here}}
69-
// expected-note @-8 {{deinit declared here}}
70-
// expected-note @-9 {{deinit declared here}}
71-
// expected-note @-10 {{deinit declared here}}
61+
deinit {} // expected-note 10{{deinit declared here}}
7262
}
7363

7464
func testConsumeCopyable(_ x: consuming DeinitStruct) {
@@ -78,24 +68,24 @@ func testConsumeCopyable(_ x: consuming DeinitStruct) {
7868
}
7969

8070
func testConsumeNonCopyable1(_ x: consuming DeinitStruct) {
81-
// expected-error @-1 {{Cannot partially consume 'x' since it has a user defined deinit}}
82-
consume(x.third.rhs) // expected-note {{consuming use here}}
71+
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
72+
consume(x.third.rhs)
8373
}
8474

8575
func testConsumeNonCopyable2(_ x: consuming DeinitStruct) {
86-
// expected-error @-1 {{Cannot partially consume 'x' since it has a user defined deinit}}
87-
consume(x.fourth.0) // expected-note {{consuming use here}}
76+
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
77+
consume(x.fourth.0)
8878
}
8979

9080
func testConsumeNonCopyable3(_ x: consuming DeinitStruct) {
91-
// expected-error @-1 {{Cannot partially consume 'x' since it has a user defined deinit}}
92-
consume(x.fourth.1) // expected-note {{consuming use here}}
81+
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
82+
consume(x.fourth.1)
9383
}
9484

9585

9686
func testConsumeNonCopyable4(_ x: consuming DeinitStruct) {
97-
// expected-error @-1 {{Cannot partially consume 'x' since it has a user defined deinit}}
98-
consume(x.fifth) // expected-note {{consuming use here}}
87+
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
88+
consume(x.fifth)
9989
}
10090

10191
/////////////////
@@ -123,33 +113,33 @@ func testStructContainDeinitStructConsumeCopyable1(_ x: consuming StructContainD
123113
}
124114

125115

126-
func testStructContainStructContainDeinitStructConsumeNonCopyable1(_ x: consuming StructContainDeinitStruct) {
127-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.first' whose type 'DeinitStruct' has a user defined deinit}}
128-
consume(x.first.third.rhs) // expected-note {{consuming use here}}
116+
func testStructContainStructContainDeinitStructConsumeNonCopyable1(_ xyz: consuming StructContainDeinitStruct) {
117+
// expected-error @+1 {{cannot partially consume 'xyz.first' since it has a user defined deinit}}
118+
consume(xyz.first.third.rhs)
129119
}
130120

131121
func testStructContainStructContainDeinitStructConsumeNonCopyable1a(_ x: consuming StructContainDeinitStruct) {
132-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.second.0' whose type 'DeinitStruct' has a user defined deinit}}
133-
consume(x.second.0.third.rhs) // expected-note {{consuming use here}}
122+
// expected-error @+1 {{cannot partially consume 'x.second.0' since it has a user defined deinit}}
123+
consume(x.second.0.third.rhs)
134124
}
135125

136126
func testStructContainStructContainDeinitStructConsumeNonCopyable2(_ x: consuming StructContainDeinitStruct) {
137-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.first' whose type 'DeinitStruct' has a user defined deinit}}
138-
consume(x.first.fourth.0) // expected-note {{consuming use here}}
127+
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
128+
consume(x.first.fourth.0)
139129
}
140130

141131
func testStructContainStructContainDeinitStructConsumeNonCopyable2a(_ x: consuming StructContainDeinitStruct) {
142-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.second.1' whose type 'DeinitStruct' has a user defined deinit}}
143-
consume(x.second.1.fourth.0) // expected-note {{consuming use here}}
132+
// expected-error @+1 {{cannot partially consume 'x.second.1' since it has a user defined deinit}}
133+
consume(x.second.1.fourth.0)
144134
}
145135

146136
func testStructContainStructContainDeinitStructConsumeNonCopyable3(_ x: consuming StructContainDeinitStruct) {
147-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.first' whose type 'DeinitStruct' has a user defined deinit}}
148-
consume(x.first.fourth.1) // expected-note {{consuming use here}}
137+
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
138+
consume(x.first.fourth.1)
149139
}
150140

151141

152142
func testStructContainStructContainDeinitStructConsumeNonCopyable4(_ x: consuming StructContainDeinitStruct) {
153-
// expected-error @-1 {{Cannot partially consume 'x' since it contains field 'x.first' whose type 'DeinitStruct' has a user defined deinit}}
154-
consume(x.first.fifth) // expected-note {{consuming use here}}
143+
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
144+
consume(x.first.fifth)
155145
}

0 commit comments

Comments
 (0)