Skip to content

[Integration] main (d2ff78f6) -> swift/main #235

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 17 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let package = Package(
name: "Prototypes",
targets: ["Prototypes"]),
.library(
name: "_MatchingEngine",
targets: ["_MatchingEngine"]),
name: "_RegexParser",
targets: ["_RegexParser"]),
.executable(
name: "VariadicsGenerator",
targets: ["VariadicsGenerator"])
Expand All @@ -27,27 +27,27 @@ let package = Package(
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "_MatchingEngine",
name: "_RegexParser",
dependencies: [],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"])
]),
.testTarget(
name: "MatchingEngineTests",
dependencies: [
"_MatchingEngine", "_StringProcessing"]),
"_RegexParser", "_StringProcessing"]),
.target(
name: "_CUnicode",
dependencies: []),
.target(
name: "_StringProcessing",
dependencies: ["_MatchingEngine", "_CUnicode"],
dependencies: ["_RegexParser", "_CUnicode"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
]),
.target(
name: "RegexBuilder",
dependencies: ["_StringProcessing", "_MatchingEngine"],
dependencies: ["_StringProcessing", "_RegexParser"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
Expand All @@ -63,7 +63,7 @@ let package = Package(
]),
.target(
name: "Prototypes",
dependencies: ["_MatchingEngine", "_StringProcessing"]),
dependencies: ["_RegexParser", "_StringProcessing"]),

// MARK: Scripts
.executableTarget(
Expand All @@ -75,14 +75,14 @@ let package = Package(
name: "PatternConverter",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"_MatchingEngine",
"_RegexParser",
"_StringProcessing"
]),

// MARK: Exercises
.target(
name: "Exercises",
dependencies: ["_MatchingEngine", "Prototypes", "_StringProcessing", "RegexBuilder"],
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
]),
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ See [Declarative String Processing Overview][decl-string]

## Integration with Swift

`_MatchingEngine`, `_CUnicode` and `_StringProcessing` are specially integrated modules that are built as part of apple/swift.
`_RegexParser` and `_StringProcessing` are specially integrated modules that are built as part of apple/swift.

Specifically, `_MatchingEngine` contains the parser for regular expression literals and is built both as part of the compiler and as a core library. `_CUnicode` and `_StringProcessing` are built together as a core library named `_StringProcessing`.
Specifically, `_RegexParser` contains the parser for regular expression literals and is built both as part of the compiler and as a core library. `_CUnicode` and `_StringProcessing` are built together as a core library named `_StringProcessing`.

| Module | Swift toolchain component |
| ------------------- | ------------------------------------------------------------------------------------ |
| `_MatchingEngine` | `SwiftCompilerSources/Sources/ExperimentalRegex` and `stdlib/public/_MatchingEngine` |
| `_RegexParser` | `SwiftCompilerSources/Sources/_RegexParser` and `stdlib/public/_RegexParser` |
| `_CUnicode` | `stdlib/public/_StringProcessing` |
| `_StringProcessing` | `stdlib/public/_StringProcessing` |

Expand Down Expand Up @@ -65,10 +65,9 @@ To integrate the latest changes in apple/swift-experimental-string-processing to

### Development notes

Compiler integration can be tricky. Use special caution when developing `_MatchingEngine`, `_CUnicode` and `_StringProcessing` modules.
Compiler integration can be tricky. Use special caution when developing `_RegexParser` and `_StringProcessing` modules.

- Do not change the names of these modules without due approval from compiler and infrastructure teams.
- Do not modify the existing ABI (e.g. C API, serialization format) between the regular expression parser and the Swift compiler unless absolutely necessary.
- Always minimize the number of lockstep integrations, i.e. when apple/swift-experimental-string-processing and apple/swift have to change together. Whenever possible, introduce new API first, migrate Swift compiler onto it, and then deprecate old API. Use versioning if helpful.
- In `_StringProcessing`, do not write fully qualified references to symbols in `_CUnicode`, and always wrap `import _CUnicode` in a `#if canImport(_CUnicode)`. This is because `_CUnicode` is built as part of `_StringProcessing` with CMake.
- In `_MatchingEngine`, do not write fully qualified references to `_MatchingEngine` itself. This is because `_MatchingEngine` is built as `ExperimentalRegex` in `SwiftCompilerSources/` with CMake.
4 changes: 2 additions & 2 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

add_subdirectory(_Unicode)
add_subdirectory(_MatchingEngine)
add_subdirectory(RegexBuilder)
add_subdirectory(_RegexParser)
add_subdirectory(_StringProcessing)
add_subdirectory(Prototypes)
add_subdirectory(VariadicsGenerator)
13 changes: 8 additions & 5 deletions Sources/Exercises/Participant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@ public protocol Participant {
// ...
}

// Errors that may be thrown from default implementations
private enum ParticipantError: Error {
case unsupported
}

// Default impls
extension Participant {
static var unsupported: Error { "Unsupported" }

// Produce a function that will parse a grapheme break entry from a line
public static func graphemeBreakProperty() throws -> (String) -> GraphemeBreakEntry? {
throw unsupported
throw ParticipantError.unsupported
}

// Produce a function that will extract the bodies of C-style comments from its input
public static func cComments() throws -> (String) -> [Substring] {
throw unsupported
throw ParticipantError.unsupported
}

// Produce a function that will extract the bodies of Swift-style comments from its input
public static func swiftComments() throws -> (String) -> [Substring] {
throw unsupported
throw ParticipantError.unsupported
}
}
4 changes: 2 additions & 2 deletions Sources/PatternConverter/PatternConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// swift run PatternConverter <regex>

import ArgumentParser
import _MatchingEngine
import _RegexParser
import _StringProcessing

@main
Expand Down Expand Up @@ -52,7 +52,7 @@ struct PatternConverter: ParsableCommand {
let delim = experimentalSyntax ? "|" : "/"
print("Converting '\(delim)\(regex)\(delim)'")

let ast = try _MatchingEngine.parse(
let ast = try _RegexParser.parse(
regex,
experimentalSyntax ? .experimental : .traditional)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Prototypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ add_library(Prototypes
TourOfTypes/CharacterClass.swift
TourOfTypes/Literal.swift)
target_link_libraries(Prototypes PUBLIC
_MatchingEngine)
_RegexParser)
2 changes: 1 addition & 1 deletion Sources/Prototypes/Combinators/Combinators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

/*

Expand Down
36 changes: 23 additions & 13 deletions Sources/RegexBuilder/Anchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

public struct Anchor {
Expand Down Expand Up @@ -107,16 +107,26 @@ extension Anchor {
}
}

public func lookahead<R: RegexComponent>(
negative: Bool = false,
@RegexComponentBuilder _ content: () -> R
) -> Regex<R.Output> {
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, content().regex.root))
}

public func lookahead<R: RegexComponent>(
_ component: R,
negative: Bool = false
) -> Regex<R.Output> {
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, component.regex.root))
public struct Lookahead<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

init(_ regex: Regex<Output>) {
self.regex = regex
}

public init<R: RegexComponent>(
_ component: R,
negative: Bool = false
) where R.Output == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component.regex.root))
}

public init<R: RegexComponent>(
negative: Bool = false,
@RegexComponentBuilder _ component: () -> R
) where R.Output == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component().regex.root))
}
}
10 changes: 10 additions & 0 deletions Sources/RegexBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

add_library(RegexBuilder
Anchor.swift
Builder.swift
DSL.swift
Match.swift
Variadics.swift)
target_compile_options(RegexBuilder PRIVATE
-enable-library-evolution
-Xfrontend -enable-experimental-pairwise-build-block)
8 changes: 2 additions & 6 deletions Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

extension Regex {
public init<Content: RegexComponent>(
@RegexComponentBuilder _ content: () -> Content
) where Content.Output == Output {
self.init(content())
self = content().regex
}
}

Expand Down Expand Up @@ -165,10 +165,6 @@ public struct Repeat<Output>: _BuiltinRegexComponent {
// Variadics.swift.
}

postfix operator .?
postfix operator .*
postfix operator .+

// MARK: Alternation

// TODO: Variadic generics
Expand Down
Loading