Skip to content

[SE-0313] Implement type system, ABI, and runtime support for isolated parameters #37794

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 7 commits into from
Jun 9, 2021

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jun 4, 2021

Implement core support for isolated parameters:

  • Parsing isolated on parameters and ensuring that said parameters are of actor type
  • Representing isolated as a parameter modifier in the type system
  • Making the self parameter of actor-isolated methods be isolated, unless they are explicitly marked as nonisolated
  • Implementing a subtyping rule that allows conversion of (MyActor) -> Void functions to (isolated MyActor) -> Void but not vice-versa
  • Mangle isolated parameter and update the various demangler/remangler paths
  • Ensure that isolated gets into function type metadata and round-trips through runtime type demangling and reflection
  • Check that members of actors are only referenced via "isolated" parameters and captures thereof.
  • Ensure that "isolated" parameters are initialize by "isolated" arguments, or the access will be asynchronous.

Implements the majority of rdar://75389492

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor force-pushed the isolated-parameters branch from ce5131a to cc05833 Compare June 4, 2021 21:46
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 4, 2021

Build failed
Swift Test Linux Platform
Git Sha - cc05833c6f09ac5ec51c36109a083b364e0fd36b

…ated'.

The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
With isolated parameters being part of a function's type, check to
ensure that isolated and non-isolated parameters aren't incorrectly
matched. Specifically, it is okay to add `isolated` to a parameter
when there is a subtyping relationship, but not remove it:

```swift
actor A { }
func f(_: isolated A) { }
func g(_: A) { }

func test() {
  let _: (isolated A) -> Void = g    // okay to add 'isolated'
  let _: (A) -> Void = f             // error when removing 'isolated'
}
```
…ers.

Isolated parameters are part of function types. Encode them in function
type manglings and metadata, and ensure that they round-trip through
the various mangling and metadata facilities. This nails down the ABI
for isolated parameters.
Rework the checking of actor member access to rely on "isolated" parameters
(and captures thereof) to determine whether one can synchronously access
an actor or not. This allows synchronous access via an "isolated" parameter
as a general notion, which subsumes the declaration-based "self" access.

Simplify the checking of and diagnostic reporting for actor member
access by collapsing a number of redundant diagnostics down into a
single, parameterized diagnostic with a single point of emission. This
normalizes the logic a bit.
@DougGregor DougGregor force-pushed the isolated-parameters branch from 979fd23 to 5bcd5a8 Compare June 8, 2021 07:00
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 8, 2021

Build failed
Swift Test Linux Platform
Git Sha - 5bcd5a8

@swift-ci
Copy link
Contributor

swift-ci commented Jun 8, 2021

Build failed
Swift Test OS X Platform
Git Sha - 5bcd5a8

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor DougGregor merged commit 0cd0cbc into swiftlang:main Jun 9, 2021
@DougGregor DougGregor deleted the isolated-parameters branch June 9, 2021 02:46
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