Skip to content

[5.3] Diagnose exclusivity in the presence of coroutines. #31483

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 1 commit into from
May 2, 2020
Merged

[5.3] Diagnose exclusivity in the presence of coroutines. #31483

merged 1 commit into from
May 2, 2020

Conversation

atrick
Copy link
Contributor

@atrick atrick commented May 1, 2020

Potentially source breaking: SR-11700 Diagnose exclusivity violations
with Dictionary.subscript._modify:

Exclusivity violations within code that computes the default
argument during Dictionary access are now diagnosed.

struct Container {
   static let defaultKey = 0

   var dictionary = [defaultKey:0]

   mutating func incrementValue(at key: Int) {
     dictionary[key, default: dictionary[Container.defaultKey]!] += 1
   }
}
error: overlapping accesses to 'self.dictionary', but modification requires exclusive access; consider copying to a local variable
     dictionary[key, default: dictionary[Container.defaultKey]!] += 1
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: conflicting access is here
     dictionary[key, default: dictionary[Container.defaultKey]!] += 1
                              ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

This reworks the logic so that four problems end up being fixed:

Fixes three problems related to coroutines:

(1) DiagnoseStaticExclusivity must consider begin_apply as a user of accessed variables. This was an undefined behavior hole in the diagnostics.

(2) AccessedSummaryAnalysis should consider begin_apply as a user of accessed arguments. This does not show up in practice because coroutines don't capture things.

(3) AccessedSummaryAnalysis must consider begin_apply a valid user of
noescape closures.

And fixes one problem related to resilience:

(4) AccessedSummaryAnalysis must conservatively consider arguments to external functions.

Fixes rdar://problem/56378713 Investigate why AccessSummaryAnalysis is crashing

(cherry picked from commit 6823b10)

@atrick atrick changed the title Diagnose exclusivity in the presence of coroutines. [5.3] Diagnose exclusivity in the presence of coroutines. May 1, 2020
@atrick
Copy link
Contributor Author

atrick commented May 1, 2020

@swift-ci test

Potentially source breaking: SR-11700 Diagnose exclusivity violations
with Dictionary.subscript._modify:

  Exclusivity violations within code that computes the `default`
  argument during Dictionary access are now diagnosed.

  ```swift
  struct Container {
     static let defaultKey = 0

     var dictionary = [defaultKey:0]

     mutating func incrementValue(at key: Int) {
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
     }
  }
  error: overlapping accesses to 'self.dictionary', but modification requires exclusive access; consider copying to a local variable
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  note: conflicting access is here
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
                                ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
  ```

This reworks the logic so that four problems end up being fixed:

Fixes three problems related to coroutines:

(1) DiagnoseStaticExclusivity must consider begin_apply as a user of accessed variables. This was an undefined behavior hole in the diagnostics.

(2) AccessedSummaryAnalysis should consider begin_apply as a user of accessed arguments. This does not show up in practice because coroutines don't capture things.

(3) AccessedSummaryAnalysis must consider begin_apply a valid user of
    noescape closures.

And fixes one problem related to resilience:

(4) AccessedSummaryAnalysis must conservatively consider arguments to external functions.

Fixes <rdar://problem/56378713> Investigate why AccessSummaryAnalysis is crashing

(cherry picked from commit 6823b10)
@atrick
Copy link
Contributor Author

atrick commented May 1, 2020

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 56b457048779f27d0082acaea93d6277b39affa0

@atrick
Copy link
Contributor Author

atrick commented May 1, 2020

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented May 2, 2020

@shahmishal I'm not sure why OS X testing won't kick off

@compnerd compnerd added the r5.3 label May 2, 2020
@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - 56b457048779f27d0082acaea93d6277b39affa0

@atrick atrick merged commit a2ff89b into swiftlang:release/5.3 May 2, 2020
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants