Skip to content

Global actor function type isolation #36907

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Apr 14, 2021

When referencing a function that is on a global actor, e.g.,

@MainActor func doSomething() -> Int

the result of that reference is a global-actor-qualified function type, e.g.,

@MainActor () -> Int

Check actor isolation of calls to functions with global-actor-qualified
type. This closes a pre-existing loophole where a value of
global-actor-qualified function type could be called from any context.
Paired with this, references to global-actor-qualified function
declarations will get global-actor-qualified function type whenever
they are referenced within an experience, i.e., whenever we form a
value of that type. Such references can occur anywhere (one does not
need to be on the actor), and carrying the global actor along with the
function type ensures that they can only be called from the right
actor. For example:

@MainActor func onlyOnMainActor() { ... }

func callIt(_ fn: @MainActor () -> Void) {
  fn() // error: not on the main actor, so cannot synchronously call
       // this wasn't previously diagnosed
}

func passIt() {
  callIt(onlyOnMainActor)  // okay to pass the function
                           // used to be an error
}

Fixes most of what is covered by rdar://76030136.

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 52e7838611b017386d594d1c64afbe56f66d2c93

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 52e7838611b017386d594d1c64afbe56f66d2c93

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

@swift-ci please test and merge

@DougGregor DougGregor force-pushed the global-actor-function-type-isolation branch from 8846bc3 to 57e7f6b Compare April 16, 2021 05:34
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 57e7f6b095cc4b0f7c1a604ddb8b3b6b35593e3a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 57e7f6b095cc4b0f7c1a604ddb8b3b6b35593e3a

…qualified type.

When referencing a function that is on a global actor, e.g.,

    @mainactor func doSomething() -> Int

the result of that reference is a global-actor-qualified function type, e.g.,

    @mainactor () -> Int

Part of rdar://76030136.
…references

Check actor isolation of calls to functions with global-actor-qualified
type. This closes a pre-existing loophole where a value of
global-actor-qualified function type could be called from any context.
Paired with this, references to global-actor-qualified function
declarations will get global-actor-qualified function type whenever
they are referenced within an experience, i.e., whenever we form a
value of that type. Such references can occur anywhere (one does not
need to be on the actor), and carrying the global actor along with the
function type ensures that they can only be called from the right
actor. For example:

    @mainactor func onlyOnMainActor() { ... }

    func callIt(_ fn: @mainactor () -> Void) {
      fn() // error: not on the main actor, so cannot synchronously call
           // this wasn't previously diagnosed
    }

    func passIt() {
      callIt(onlyOnMainActor)  // okay to pass the function
                               // used to be an error
    }

While here, fix up some broken substitution logic for
global-actor-qualified function types and "override" actor isolation.
We don't want the debugger stepping into these.
@DougGregor DougGregor force-pushed the global-actor-function-type-isolation branch from 57e7f6b to 3dc65c6 Compare April 16, 2021 07:52
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3dc65c6

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3dc65c6

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

Windows CI failed with "There is not enough space on the disk.". Restarting

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3dc65c6

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

swiftlang/llvm-project#2846

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor DougGregor merged commit 3b62296 into swiftlang:main Apr 17, 2021
@DougGregor DougGregor deleted the global-actor-function-type-isolation branch April 17, 2021 04:22
kastiglione added a commit to swiftlang/llvm-project that referenced this pull request Apr 20, 2021
Updates to async codegen, possibly from swiftlang/swift#36907, have changed the execution flow in this test. The fix is to be more liberal with the step-avoid- setting. Also the number of stops has changed in my local testing, and so the assertion has been weakened to check that it stops greater than zero times, which is enough to verify that the test is actually stopping. A follow up is to understand why it changed locally for me.

rdar://76833116
kastiglione added a commit to swiftlang/llvm-project that referenced this pull request Apr 20, 2021
Updates to async codegen, possibly from swiftlang/swift#36907, have changed the execution flow in this test. The fix is to be more liberal with the step-avoid- setting. Also the number of stops has changed in my local testing, and so the assertion has been weakened to check that it stops greater than zero times, which is enough to verify that the test is actually stopping. A follow up is to understand why it changed locally for me.

rdar://76833116

(cherry picked from commit bb79c2b)
shahmishal pushed a commit to swiftlang/llvm-project that referenced this pull request Apr 20, 2021
Updates to async codegen, possibly from swiftlang/swift#36907, have changed the execution flow in this test. The fix is to be more liberal with the step-avoid- setting. Also the number of stops has changed in my local testing, and so the assertion has been weakened to check that it stops greater than zero times, which is enough to verify that the test is actually stopping. A follow up is to understand why it changed locally for me.

rdar://76833116
(cherry picked from commit 8f520b5)
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.

2 participants