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

[Regex] Infer capture types of regex literals. #40630

Merged
merged 1 commit into from
Dec 22, 2021

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Dec 20, 2021

When parsing a regular expression literal, accept a serialized capture structure from the regex parser. During type checking, decode it and form Swift types.

Examples:

'/(.)(.)/' // ==> `Regex<(Substring, Substring)>`
'/(?<label>.)(.)/' // ==> `Regex<(label: Substring, Substring)`
'/((.))*((.)?)/' //==> `Regex<([Substring], [Substring], Substring, Substring?)>`

Also:

  • Fix a bug where a regex literal parsing error is not returning an error parser result.

Note:

Resolves rdar://83253511.

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1721e431578f50816f1359acb0df69dfb4d3531d

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1721e431578f50816f1359acb0df69dfb4d3531d

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

CI didn't seem to like the nonexistent dev/4 tag (the comment mentioning the PR should ideally override that). I've created a temporary dev/4 tag off of main to get this CI rolling. We'll move this tag later.

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1721e431578f50816f1359acb0df69dfb4d3531d

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

swiftlang/swift-experimental-string-processing#92

@swift-ci please clean test linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1721e431578f50816f1359acb0df69dfb4d3531d

@rxwei
Copy link
Contributor Author

rxwei commented Dec 20, 2021

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1721e431578f50816f1359acb0df69dfb4d3531d

@rxwei rxwei force-pushed the capture-inference branch 7 times, most recently from a0eafe2 to 780b5d6 Compare December 22, 2021 10:55
When parsing a regular expression literal, accept a serialized capture structure from the regex parser. During type checking, decode it and form Swift types.

Examples:
```swift
'/(.)(.)/' // ==> `Regex<(Substring, Substring)>`
'/(?<label>.)(.)/' // ==> `Regex<(label: Substring, Substring)`
'/((.))*((.)?)/' //==> `Regex<([Substring], [Substring], Substring, Substring?)>`
```

Also:
- Fix a bug where a regex literal parsing error is not returning an error parser result.

Note:
- This needs to land after swiftlang/swift-experimental-string-processing#92 and after `dev/4` tag has been created.
- See swiftlang/swift-experimental-string-processing#92 for regex parser changes and the capture structure encoding.
- The `RegexLiteralParsingFn` `CaptureStructureOut` pointer type change from `char *` to `void *` will not break builds due to implicit pointer conversion (SE-0324) and unchanged ABI.

Resolves rdar://83253511.
@rxwei rxwei force-pushed the capture-inference branch from 780b5d6 to 1b3c0b7 Compare December 22, 2021 10:58
@rxwei
Copy link
Contributor Author

rxwei commented Dec 22, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1b3c0b7

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1b3c0b7

@rxwei
Copy link
Contributor Author

rxwei commented Dec 22, 2021

@swift-ci please test

@rxwei rxwei merged commit 6645f0d into swiftlang:main Dec 22, 2021
@rxwei rxwei deleted the capture-inference branch December 22, 2021 22:57
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.

4 participants