Skip to content

[Integration] main (005e0fb) -> swift/main #492

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 34 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
57a5092
Allow unbounded quoted sequences `\Q...`
hamishknight May 26, 2022
5bee0ce
Remove outdated comment
hamishknight May 31, 2022
d9869ea
Use inits instead of as methods (#448)
milseman May 31, 2022
a149466
Merge pull request #461 from hamishknight/remove-comment
hamishknight Jun 1, 2022
32afc43
Make the `Regex` type Sendable (#457)
natecook1000 Jun 1, 2022
5e05b61
Handle AnyRegexOutput when casting to new Regex (#468)
Azoy Jun 3, 2022
a877e24
Obtain match output elements without materializing the output.
rxwei Jun 4, 2022
a7001b1
Merge pull request #469 from rxwei/fix-267
rxwei Jun 7, 2022
17d8362
Add additional capture transform tests.
rxwei Jun 7, 2022
efb86dd
Disable Prototypes to work around a CI failure
rxwei Jun 9, 2022
da50de9
Merge pull request #477 from rxwei/remove-prototypes
rxwei Jun 9, 2022
9d5280e
Fully generalize "whole match" in the engine and enable transforming …
rxwei Jun 5, 2022
fa72f5a
Merge pull request #470 from rxwei/whole-match-tracked
rxwei Jun 9, 2022
4665622
Back out Sendable conformance and annotations (#474)
natecook1000 Jun 13, 2022
18f2d61
Merge pull request #471 from rxwei/test-267
rxwei Jun 13, 2022
894cb39
Remove `buildEither`.
rxwei Jun 14, 2022
9624436
Remove (?X) and (?u) for now
Azoy Jun 13, 2022
e6fec4b
Merge pull request #480 from Azoy/remove-some-flags
Azoy Jun 14, 2022
857dd7b
Merge pull request #482 from rxwei/no-buildeither
rxwei Jun 14, 2022
2265620
Merge pull request #432 from hamishknight/unbounded-quote
hamishknight Jun 15, 2022
98992b0
v1 benchmarker
rctcwyvrn Jun 14, 2022
3e650cb
Remove top level code
rctcwyvrn Jun 15, 2022
4ea430c
Adjust benchmark loads for release builds (oops)
rctcwyvrn Jun 15, 2022
1384a69
Benchmarking housekeeping
rctcwyvrn Jun 15, 2022
fb7459d
Add basic CLI
rctcwyvrn Jun 15, 2022
4292b7a
Remove redundant string inits
rctcwyvrn Jun 15, 2022
73b0482
Remove some comments
rctcwyvrn Jun 15, 2022
55ffc5c
Add tests for substring / anchor interaction (#490)
natecook1000 Jun 16, 2022
0b46160
Move some LexTests over to ParseTests
hamishknight Jun 16, 2022
027ccc7
Allow `(?)`
hamishknight Jun 16, 2022
e861af5
Fix `\o` parsing crash
hamishknight Jun 16, 2022
0878029
Merge pull request #487 from hamishknight/separate-these
hamishknight Jun 16, 2022
005e0fb
Merge pull request #491 from rctcwyvrn/benchmarker
rctcwyvrn Jun 16, 2022
d0c007b
Merge branch 'main' into main-merge
hamishknight Jun 16, 2022
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
41 changes: 30 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ let package = Package(
.library(
name: "_StringProcessing",
targets: ["_StringProcessing"]),
.library(
name: "Prototypes",
targets: ["Prototypes"]),
// FIXME: Disabled due to rdar://94763190.
// .library(
// name: "Prototypes",
// targets: ["Prototypes"]),
.library(
name: "_RegexParser",
targets: ["_RegexParser"]),
.executable(
name: "VariadicsGenerator",
targets: ["VariadicsGenerator"])
targets: ["VariadicsGenerator"]),
.executable(
name: "RegexBenchmark",
targets: ["RegexBenchmark"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
Expand All @@ -62,7 +66,10 @@ let package = Package(
dependencies: []),
.target(
name: "_StringProcessing",
dependencies: ["_RegexParser", "_CUnicode"],
dependencies: [
"_RegexParser",
"_CUnicode",
],
swiftSettings: publicStdlibSettings),
.target(
name: "RegexBuilder",
Expand All @@ -80,12 +87,13 @@ let package = Package(
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
]),
.testTarget(
name: "Prototypes",
dependencies: ["_RegexParser", "_StringProcessing"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
]),
// FIXME: Disabled due to rdar://94763190.
// .testTarget(
// name: "Prototypes",
// dependencies: ["_RegexParser", "_StringProcessing"],
// swiftSettings: [
// .unsafeFlags(["-Xfrontend", "-disable-availability-checking"])
// ]),

// MARK: Scripts
.executableTarget(
Expand All @@ -107,6 +115,17 @@ let package = Package(
"_RegexParser",
"_StringProcessing"
]),
.executableTarget(
name: "RegexBenchmark",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"_RegexParser",
"_StringProcessing",
"RegexBuilder"
],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
]),

// MARK: Exercises
.target(
Expand Down
116 changes: 116 additions & 0 deletions Sources/RegexBenchmark/Benchmark.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import _StringProcessing
import Foundation

public protocol RegexBenchmark {
var name: String { get }
func run()
}

public struct Benchmark: RegexBenchmark {
public let name: String
let regex: Regex<Substring>
let ty: MatchType
let target: String

public enum MatchType {
case whole
case first
case allMatches
}

public func run() {
switch ty {
case .whole: blackHole(target.wholeMatch(of: regex))
case .allMatches: blackHole(target.matches(of: regex))
case .first: blackHole(target.firstMatch(of: regex))
}
}
}

public struct NSBenchmark: RegexBenchmark {
public let name: String
let regex: NSRegularExpression
let ty: NSMatchType
let target: String

var range: NSRange {
NSRange(target.startIndex..<target.endIndex, in: target)
}

public enum NSMatchType {
case all
case first
}

public func run() {
switch ty {
case .all: blackHole(regex.matches(in: target, range: range))
case .first: blackHole(regex.firstMatch(in: target, range: range))
}
}
}

public struct BenchmarkRunner {
// Register instances of Benchmark and run them
let suiteName: String
var suite: [any RegexBenchmark]
let samples: Int

public init(_ suiteName: String) {
self.suiteName = suiteName
self.suite = []
self.samples = 20
}

public init(_ suiteName: String, _ n: Int) {
self.suiteName = suiteName
self.suite = []
self.samples = n
}

public mutating func register(_ new: some RegexBenchmark) {
suite.append(new)
}

func measure(benchmark: some RegexBenchmark) -> Time {
var times: [Time] = []

// initial run to make sure the regex has been compiled
benchmark.run()

// fixme: use suspendingclock?
for _ in 0..<samples {
let start = Tick.now
benchmark.run()
let end = Tick.now
let time = end.elapsedTime(since: start)
times.append(time)
}
// todo: compute stdev and warn if it's too large

// return median time
times.sort()
return times[samples/2]
}

public func run() {
print("Running")
for b in suite {
print("- \(b.name) \(measure(benchmark: b))")
}
}

public func profile() {
print("Starting")
for b in suite {
print("- \(b.name)")
b.run()
print("- done")
}
}
}

// nom nom nom, consume the argument
@inline(never)
public func blackHole<T>(_ x: T) {
}
33 changes: 33 additions & 0 deletions Sources/RegexBenchmark/CLI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import ArgumentParser

@main
struct Runner: ParsableCommand {
@Argument(help: "Names of benchmarks to run")
var specificBenchmarks: [String] = []

@Option(help: "Run only once for profiling purposes")
var profile = false

@Option(help: "How many samples to collect for each benchmark")
var samples = 20

func makeRunner() -> BenchmarkRunner {
var benchmark = BenchmarkRunner("RegexBench", samples)
benchmark.addReluctantQuant()
benchmark.addBacktracking()
benchmark.addCSS()
benchmark.addFirstMatch()
return benchmark
}
mutating func run() throws {
var runner = makeRunner()
if !self.specificBenchmarks.isEmpty {
runner.suite = runner.suite.filter { b in specificBenchmarks.contains(b.name) }
}
if profile {
runner.profile()
} else {
runner.run()
}
}
}
45 changes: 45 additions & 0 deletions Sources/RegexBenchmark/Suite/Backtracking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import _StringProcessing
import RegexBuilder
import Foundation

// Tests that involve heavy backtracking

extension BenchmarkRunner {
mutating func addBacktracking() {
let r = "^ +A"
let s = String(repeating: " ", count: 10000)

let basicBacktrack = Benchmark(
name: "BasicBacktrack",
regex: try! Regex(r),
ty: .allMatches,
target: s
)

let basicBacktrackNS = NSBenchmark(
name: "BasicBacktrackNS",
regex: try! NSRegularExpression(pattern: r),
ty: .all,
target: s
)

let basicBacktrackFirstMatch = Benchmark(
name: "BasicBacktrackFirstMatch",
regex: try! Regex(r),
ty: .first,
target: s
)

let basicBacktrackNSFirstMatch = NSBenchmark(
name: "BasicBacktrackNSFirstMatch",
regex: try! NSRegularExpression(pattern: r),
ty: .first,
target: s
)

register(basicBacktrack)
register(basicBacktrackNS)
register(basicBacktrackFirstMatch)
register(basicBacktrackNSFirstMatch)
}
}
Loading