Skip to content

[Exclusivity] fix diagnostics for conditional noescape closures. #18234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2018
Merged

[Exclusivity] fix diagnostics for conditional noescape closures. #18234

merged 2 commits into from
Jul 30, 2018

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 25, 2018

Add support to static diagnostics for tracking noescape closures through block
arguments.

Improve the noescape closure SIL verification logic to match. Cleanup noescape
closure handling in both diagnostics and SIL verification to be more
robust--they must perfectly match each other.

Fixes rdar://problem/42560459 [Exclusivity] Failure to statically diagnose a
conflict when passing conditional noescape closures.

Initially reported in [SR-8266] Compiler crash when checking exclusivity of
inout alias.

Example:

struct S {
var x: Int

mutating func takeNoescapeClosure(_ f: ()->()) { f() }

mutating func testNoescapePartialApplyPhiUse(z : Bool) {
func f1() {
x = 1 // expected-note {{conflicting access is here}}
}
func f2() {
x = 1 // expected-note {{conflicting access is here}}
}
takeNoescapeClosure(z ? f1 : f2)
// expected-error@-1 2 {{overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable}}
}
}

@atrick
Copy link
Contributor Author

atrick commented Jul 25, 2018

@shajrawi please review.

@atrick
Copy link
Contributor Author

atrick commented Jul 25, 2018

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented Jul 25, 2018

@swift-ci test source compatibility.

@atrick
Copy link
Contributor Author

atrick commented Jul 25, 2018

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented Jul 25, 2018

@swift-ci test source compatibility.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 69e18eee7598facc6044cc7b2a93f23a6280ff5d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 69e18eee7598facc6044cc7b2a93f23a6280ff5d

@atrick
Copy link
Contributor Author

atrick commented Jul 26, 2018

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented Jul 26, 2018

@swift-ci test source compatibility.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ea024e82c43b4dac363e94e696020ddecdb08965

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ea024e82c43b4dac363e94e696020ddecdb08965

@atrick
Copy link
Contributor Author

atrick commented Jul 30, 2018

@shajrawi can I get a review?

Copy link

@shajrawi shajrawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! I think you can add llvm_unreachable (see above) but that's just cosmetic

return cast<SILPHIArgument>(getFalseBB()->getArgument(
operIdx - getFalseOperands().front().getOperandNumber()));
}
return nullptr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be llvm_unreachable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the doc comment:

  /// Returns nullptr for an operand with no block argument
  /// (i.e the branch condition).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops! missed that 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it too. Thanks.

atrick added 2 commits July 30, 2018 14:42
Allows a SIL pass to follow a def-use chain through phis.

Other terminators can also propagate values through block arguments, but they
always need special handling.
Add support to static diagnostics for tracking noescape closures through block
arguments.

Improve the noescape closure SIL verification logic to match. Cleanup noescape
closure handling in both diagnostics and SIL verification to be more
robust--they must perfectly match each other.

Fixes <rdar://problem/42560459> [Exclusivity] Failure to statically diagnose a
conflict when passing conditional noescape closures.

Initially reported in [SR-8266] Compiler crash when checking exclusivity of
inout alias.

Example:

struct S {
  var x: Int

  mutating func takeNoescapeClosure(_ f: ()->()) { f() }

  mutating func testNoescapePartialApplyPhiUse(z : Bool) {
    func f1() {
      x = 1 // expected-note {{conflicting access is here}}
    }
    func f2() {
      x = 1 // expected-note {{conflicting access is here}}
    }
    takeNoescapeClosure(z ? f1 : f2)
    // expected-error@-1 2 {{overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable}}
  }
}
@atrick
Copy link
Contributor Author

atrick commented Jul 30, 2018

@swift-ci smoke test and merge.

1 similar comment
@atrick
Copy link
Contributor Author

atrick commented Jul 30, 2018

@swift-ci smoke test and merge.

@swift-ci swift-ci merged commit d2cc353 into swiftlang:master Jul 30, 2018
@atrick atrick deleted the exclusivity-pa-phi-use branch July 30, 2018 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants