Skip to content

Add primary associated type to RegexComponent #454

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
May 29, 2022

Conversation

natecook1000
Copy link
Member

@natecook1000 natecook1000 commented May 28, 2022

This PR makes the RegexOutput associated type primary for RegexComponent, and adopts the new lightweight generics syntax across the algorithms methods. With this change, methods that don't rely on the specific output type no longer have an explicit generic parameter:

-  public func contains<R: RegexComponent>(_ regex: R) -> Bool {
+  public func contains(_ regex: some RegexComponent) -> Bool {

And methods that do are generic over that type instead of over the regex component type:

-  public func firstMatch<R: RegexComponent>(
-    of r: R
-  ) -> Regex<R.RegexOutput>.Match? {
+  public func firstMatch<Output>(
+    of r: some RegexComponent<Output>
+  ) -> Regex<Output>.Match? {

(Technically these are all just sugared versions of the old ones, but they do look nicer.)

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit dcf7dd8 into swiftlang:main May 29, 2022
natecook1000 added a commit to natecook1000/swift-experimental-string-processing that referenced this pull request May 29, 2022
* Add a primary associated type to RegexComponent
* Switch algorithms methods to using opaque params
* Use primary assoc type in RegexBuilder algorithms
Comment on lines 51 to 56
@available(SwiftStdlib 5.7, *)
public func contains<R: RegexComponent>(
@RegexComponentBuilder _ content: () -> R
public func contains(
@RegexComponentBuilder _ content: () -> some RegexComponent
) -> Bool {
contains(content())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately I believe these will fail to integrate with the current Swift compiler due to rdar://92459215, see the comment at the top of the file (I don't know if some RegexComponent<Output> works tho)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh huh, I see swiftlang/swift#42532 passed, maybe that's just an issue on main?

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #458 to verify

Copy link
Contributor

@hamishknight hamishknight May 30, 2022

Choose a reason for hiding this comment

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

Hmm, seems to be fixed now (other test failure unrelated)

Edit: Looks like it was fixed by swiftlang/swift#58991

hamishknight pushed a commit to hamishknight/swift-experimental-string-processing that referenced this pull request May 30, 2022
* Add a primary associated type to RegexComponent
* Switch algorithms methods to using opaque params
* Use primary assoc type in RegexBuilder algorithms
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.

3 participants