Skip to content

[Concurrency] Allow isolated parameters to have optional type. #70758

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 4 commits into from
Jan 11, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 8, 2024

Allow isolated parameters to have optional type. This is the primary generalization of isolated parameters described in https://github.com/apple/swift-evolution/blob/d4bfe25e12115f70b691f782a2dc99a7a7d1406a/proposals/NNNN-generalize-async-sequence.md#generalized-isolated-parameters.

This change requires the hop_to_executor instruction to handle optional actor operands in SILGen. The LowerHopToActor pass then projects out the optional executor value from the optional actor value. LowerHopToActor inserts the executor derivation in dominating position to allow reusing the executor value in reachable hop_to_executor instructions, but dominance analysis relies on the CFG not changing. This is handled by changing LowerHopToActor to perform two passes over the given function:

  1. The first pass records all actor operands of hop_to_executor and extract_executor instructions and records the dominating instruction that will derive the executor value.
  2. The second pass iterates over the multi-map of dominating instructions, derives the executor value (which can include switching over an optional actor), and rewrites the operands of all reachable hop_to_executor and extract_executor instructions to use that executor value.

Writing optional isolated parameters in source is currently gated behind -enable-experimental-feature OptionalIsolatedParameters.

@hborla hborla force-pushed the generalize-isolated-param branch 5 times, most recently from 8ba4dad to b8fa2ac Compare January 10, 2024 04:49
@hborla hborla marked this pull request as ready for review January 10, 2024 05:36
hborla added 3 commits January 9, 2024 21:37
… the

LowerHopToActor pass instead of during SILGen.
…lues

in LowerHopToActor.

In order to project an optional executor value from an optional actor value,
the executor lowering needs to modify the CFG. This is done by splitting
LowerHopToActor into two passes. The first pass records all actor operands
of hop_to_executor and extract_executor instructions and records the
dominating instruction that will derive the executor value. The second pass
iterates over the multi-map of dominating instructions, derives the executor
value, and rewrites the operands of all reachable hop_to_executor and
extract_executor instructions to reuse that executor value.
@hborla hborla force-pushed the generalize-isolated-param branch from f651a14 to 5858e52 Compare January 10, 2024 05:38
@hborla hborla requested review from gottesmm and rjmccall January 10, 2024 05:44
@hborla
Copy link
Member Author

hborla commented Jan 10, 2024

@swift-ci please test

@hborla hborla force-pushed the generalize-isolated-param branch from 5858e52 to 74d7a25 Compare January 10, 2024 15:18
@hborla
Copy link
Member Author

hborla commented Jan 10, 2024

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This is fantastic, thank you!

@hborla hborla merged commit 22d9e85 into swiftlang:main Jan 11, 2024
@hborla hborla deleted the generalize-isolated-param branch January 11, 2024 03:07
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