Skip to content
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

Improve Concurrency Isolation, if possible #2

Open
DandyLyons opened this issue Sep 1, 2024 · 0 comments
Open

Improve Concurrency Isolation, if possible #2

DandyLyons opened this issue Sep 1, 2024 · 0 comments

Comments

@DandyLyons
Copy link
Owner

DandyLyons commented Sep 1, 2024

This library follows an old established pattern. It vends out constants to be used. These constants are globally available, kept in a namespace for organization sake (RegexLiterals and RegexBuilders). However, this pattern is no longer recommended. It is a warning in Swift 5.10 when using Strict Concurrency, and it is a non-compiling error when using Swift 6.

This happens because Regex and RegexComponent are not Sendable. My understanding is that they are not Sendable because the Swift Regex engine allows users to insert custom logic, therefore, the compiler can't know ahead of time if it is concurrency safe.

For this reason, I created RegexActor, a global actor to isolate the Regexes. RegexActor is empty, stateless, and only exists to provide an isolation context.

I suspect this might not be the best option available. For example, suppose someone already has an isolation context that they would prefer to use. With this solution, I'm not sure if that would be possible or viable. I would love to hear if anyone has any better solutions.

Possible Solutions to Explore

It's possible that we might be able to create an AnyRegexComponent that is a concrete Sendable type. If so, this might fix our problem.
For more context, see: https://iosdev.space/@dandylyons/113057848940742967

Extra Context

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

No branches or pull requests

1 participant