-
Notifications
You must be signed in to change notification settings - Fork 45
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
Make the Regex
type Sendable
#457
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Regex stores a `Program` instance, which lazily lowers the DSLTree into a compiled program. In unprotected, this lazy compilation is under concurrency. This change uses UnsafeAtomicLazyReference from `swift-atomics` as storage for the lowered program, which makes storing the compiled program an atomic operation.
This test consistently traps on 'main', but succeeds with this `Sendable` implementation.
@swift-ci Please test |
All the calls here are concrete; there's no need for conformances
@swift-ci Please test |
milseman
reviewed
May 31, 2022
Didn't realize these methods existed; no need for shims or wrappers!
@swift-ci Please test |
rxwei
approved these changes
Jun 1, 2022
We only need to synchronize the lazy initialization; accesses either succeed or don't already.
@swift-ci Please test |
natecook1000
added a commit
to natecook1000/swift-experimental-string-processing
that referenced
this pull request
Jun 1, 2022
This change makes `Regex`, `RegexComponent`, and its component types `Sendable`. Regex stores a `Program` instance, which lazily lowers the DSLTree into a compiled program. Without synchronization, this lazy compilation is unsafe under concurrency. This change uses atomic initialization for the compiled program.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is mostly trivial, with the exception of the lazy compiled regex. For that, we can use atomics to make storing the compiled program safe, even if it might result in an extra, thrown-away compilation.
So that we don't have to importswift-atomics
, I've subset out theUnsafeAtomicLazyReference
type and its dependencies.main
, but succeeds with these changes._stdlib_atomicInitializeARCRef
function to synchronize initialization of the lazily compiled regex.