mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
|
||||||
P.addDiagnoseInvalidEscapingCaptures();
|
P.addDiagnoseInvalidEscapingCaptures();
|
||||||
P.addReferenceBindingTransform();
|
P.addReferenceBindingTransform();
|
||||||
P.addDiagnoseStaticExclusivity();
|
|
||||||
P.addNestedSemanticFunctionCheck();
|
P.addNestedSemanticFunctionCheck();
|
||||||
P.addCapturePromotion();
|
P.addCapturePromotion();
|
||||||
|
|
||||||
@@ -130,6 +129,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
|
|||||||
#else
|
#else
|
||||||
P.addLegacyAllocBoxToStack();
|
P.addLegacyAllocBoxToStack();
|
||||||
#endif
|
#endif
|
||||||
|
// Needs to run after MandatoryAllocBoxToStack, because MandatoryAllocBoxToStack
|
||||||
|
// can convert dynamic accesses to static accesses.
|
||||||
|
P.addDiagnoseStaticExclusivity();
|
||||||
|
|
||||||
P.addNoReturnFolding();
|
P.addNoReturnFolding();
|
||||||
P.addBooleanLiteralFolding();
|
P.addBooleanLiteralFolding();
|
||||||
addDefiniteInitialization(P);
|
addDefiniteInitialization(P);
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func testLocalLetClosureCaptureVar() {
|
|||||||
consumeVal(x) // expected-note {{consumed here}}
|
consumeVal(x) // expected-note {{consumed here}}
|
||||||
// expected-note @-1 {{consumed again here}}
|
// expected-note @-1 {{consumed again here}}
|
||||||
borrowConsumeVal(x, x)
|
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 @-2 {{conflicting access is here}}
|
||||||
// expected-note @-3 {{used here}}
|
// expected-note @-3 {{used here}}
|
||||||
// expected-note @-4 {{used here}}
|
// expected-note @-4 {{used here}}
|
||||||
@@ -975,7 +975,7 @@ func testLocalLetClosureCaptureConsuming(_ x: consuming SingleElt) {
|
|||||||
consumeVal(x) // expected-note {{consumed here}}
|
consumeVal(x) // expected-note {{consumed here}}
|
||||||
// expected-note @-1 {{consumed again here}}
|
// expected-note @-1 {{consumed again here}}
|
||||||
borrowConsumeVal(x, x) // expected-note {{used 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 @-2 {{conflicting access is here}}
|
||||||
// expected-note @-3 {{consumed here}}
|
// expected-note @-3 {{consumed here}}
|
||||||
// expected-note @-4 {{used here}}
|
// expected-note @-4 {{used here}}
|
||||||
|
|||||||
@@ -263,12 +263,9 @@ func callsClosureLiteralImmediately() {
|
|||||||
|
|
||||||
func callsStoredClosureLiteral() {
|
func callsStoredClosureLiteral() {
|
||||||
var i = 7;
|
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
|
_ = c(&i) // expected-error {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
|
||||||
// We don't expect a static exclusivity diagnostic here, but the issue
|
|
||||||
// will be caught at run time
|
|
||||||
_ = c(&i) // no-error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user