Skip to content

Commit 667de83

Browse files
committed
Optimizer: move DiagnoseStaticExclusivity after MandatoryAllocBoxToStack
This is needed because MandatoryAllocBoxToStack can convert dynamic accesses to static accesses. Also, it improves diagnostics for closure captures.
1 parent a80ba34 commit 667de83

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
117117
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
118118
P.addDiagnoseInvalidEscapingCaptures();
119119
P.addReferenceBindingTransform();
120-
P.addDiagnoseStaticExclusivity();
121120
P.addNestedSemanticFunctionCheck();
122121
P.addCapturePromotion();
123122

@@ -130,6 +129,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
130129
#else
131130
P.addLegacyAllocBoxToStack();
132131
#endif
132+
// Needs to run after MandatoryAllocBoxToStack, because MandatoryAllocBoxToStack
133+
// can convert dynamic accesses to static accesses.
134+
P.addDiagnoseStaticExclusivity();
135+
133136
P.addNoReturnFolding();
134137
P.addBooleanLiteralFolding();
135138
addDefiniteInitialization(P);

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func testLocalLetClosureCaptureVar() {
143143
consumeVal(x) // expected-note {{consumed here}}
144144
// expected-note @-1 {{consumed again here}}
145145
borrowConsumeVal(x, x)
146-
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
146+
// expected-error @-1 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
147147
// expected-note @-2 {{conflicting access is here}}
148148
// expected-note @-3 {{used here}}
149149
// expected-note @-4 {{used here}}
@@ -975,7 +975,7 @@ func testLocalLetClosureCaptureConsuming(_ x: consuming SingleElt) {
975975
consumeVal(x) // expected-note {{consumed here}}
976976
// expected-note @-1 {{consumed again here}}
977977
borrowConsumeVal(x, x) // expected-note {{used here}}
978-
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
978+
// expected-error @-1 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
979979
// expected-note @-2 {{conflicting access is here}}
980980
// expected-note @-3 {{consumed here}}
981981
// expected-note @-4 {{used here}}

test/SILOptimizer/exclusivity_static_diagnostics.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,9 @@ func callsClosureLiteralImmediately() {
263263

264264
func callsStoredClosureLiteral() {
265265
var i = 7;
266-
let c = { (p: inout Int) in i}
266+
let c = { (p: inout Int) in i} // expected-note {{conflicting access is here}}
267267

268-
// Closure literals that are stored and later called are treated as escaping
269-
// We don't expect a static exclusivity diagnostic here, but the issue
270-
// will be caught at run time
271-
_ = c(&i) // no-error
268+
_ = c(&i) // expected-error {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
272269
}
273270

274271

0 commit comments

Comments
 (0)