mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Optimizer: move DiagnoseStaticExclusivity after MandatoryAllocBoxToStack
This is needed because MandatoryAllocBoxToStack can convert dynamic accesses to static accesses. Also, it improves diagnostics for closure captures.
This commit is contained in:
@@ -117,7 +117,6 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
|
||||
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
|
||||
P.addDiagnoseInvalidEscapingCaptures();
|
||||
P.addReferenceBindingTransform();
|
||||
P.addDiagnoseStaticExclusivity();
|
||||
P.addNestedSemanticFunctionCheck();
|
||||
P.addCapturePromotion();
|
||||
|
||||
@@ -130,6 +129,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
|
||||
#else
|
||||
P.addLegacyAllocBoxToStack();
|
||||
#endif
|
||||
// Needs to run after MandatoryAllocBoxToStack, because MandatoryAllocBoxToStack
|
||||
// can convert dynamic accesses to static accesses.
|
||||
P.addDiagnoseStaticExclusivity();
|
||||
|
||||
P.addNoReturnFolding();
|
||||
P.addBooleanLiteralFolding();
|
||||
addDefiniteInitialization(P);
|
||||
|
||||
@@ -143,7 +143,7 @@ func testLocalLetClosureCaptureVar() {
|
||||
consumeVal(x) // expected-note {{consumed here}}
|
||||
// expected-note @-1 {{consumed again here}}
|
||||
borrowConsumeVal(x, x)
|
||||
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
|
||||
// expected-error @-1 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
|
||||
// expected-note @-2 {{conflicting access is here}}
|
||||
// expected-note @-3 {{used here}}
|
||||
// expected-note @-4 {{used here}}
|
||||
@@ -975,7 +975,7 @@ func testLocalLetClosureCaptureConsuming(_ x: consuming SingleElt) {
|
||||
consumeVal(x) // expected-note {{consumed here}}
|
||||
// expected-note @-1 {{consumed again here}}
|
||||
borrowConsumeVal(x, x) // expected-note {{used here}}
|
||||
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
|
||||
// expected-error @-1 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
|
||||
// expected-note @-2 {{conflicting access is here}}
|
||||
// expected-note @-3 {{consumed here}}
|
||||
// expected-note @-4 {{used here}}
|
||||
|
||||
@@ -263,12 +263,9 @@ func callsClosureLiteralImmediately() {
|
||||
|
||||
func callsStoredClosureLiteral() {
|
||||
var i = 7;
|
||||
let c = { (p: inout Int) in i}
|
||||
let c = { (p: inout Int) in i} // expected-note {{conflicting access is here}}
|
||||
|
||||
// Closure literals that are stored and later called are treated as escaping
|
||||
// We don't expect a static exclusivity diagnostic here, but the issue
|
||||
// will be caught at run time
|
||||
_ = c(&i) // no-error
|
||||
_ = c(&i) // expected-error {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user