Skip to content

Commit e1926b6

Browse files
authored
Update swift/main with main (#741)
1 parent c22a6f9 commit e1926b6

File tree

9 files changed

+659
-310
lines changed

9 files changed

+659
-310
lines changed

Package.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ let package = Package(
5858
.executable(
5959
name: "VariadicsGenerator",
6060
targets: ["VariadicsGenerator"]),
61-
.executable(
62-
name: "RegexBenchmark",
63-
targets: ["RegexBenchmark"])
61+
// Disable to work around rdar://126877024
62+
// .executable(
63+
// name: "RegexBenchmark",
64+
// targets: ["RegexBenchmark"])
6465
],
6566
dependencies: [
6667
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
@@ -142,17 +143,17 @@ let package = Package(
142143
"_StringProcessing"
143144
],
144145
swiftSettings: [availabilityDefinition]),
145-
.executableTarget(
146-
name: "RegexBenchmark",
147-
dependencies: [
148-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
149-
"_RegexParser",
150-
"_StringProcessing",
151-
"RegexBuilder"
152-
],
153-
swiftSettings: [
154-
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
155-
]),
146+
// .executableTarget(
147+
// name: "RegexBenchmark",
148+
// dependencies: [
149+
// .product(name: "ArgumentParser", package: "swift-argument-parser"),
150+
// "_RegexParser",
151+
// "_StringProcessing",
152+
// "RegexBuilder"
153+
// ],
154+
// swiftSettings: [
155+
// .unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
156+
// ]),
156157

157158
// MARK: Exercises
158159
.target(

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ extension DSLTree.CustomCharacterClass.Member {
208208

209209
return { input, bounds in
210210
let curIdx = bounds.lowerBound
211-
let nextIndex = isCharacterSemantic
212-
? input.index(after: curIdx)
213-
: input.unicodeScalars.index(after: curIdx)
211+
let nextIndex = input.index(
212+
after: curIdx, isScalarSemantics: !isCharacterSemantic)
214213

215214
// Under grapheme semantics, we compare based on single NFC scalars. If
216215
// such a character is not single scalar under NFC, the match fails. In
@@ -353,9 +352,9 @@ extension AST.Atom.CharacterProperty {
353352
if p(input, bounds) != nil { return nil }
354353

355354
// TODO: bounds check
356-
return opts.semanticLevel == .graphemeCluster
357-
? input.index(after: bounds.lowerBound)
358-
: input.unicodeScalars.index(after: bounds.lowerBound)
355+
return input.index(
356+
after: bounds.lowerBound,
357+
isScalarSemantics: opts.semanticLevel == .unicodeScalar)
359358
}
360359
}
361360

Sources/_StringProcessing/Engine/InstPayload.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ struct QuantifyPayload: RawRepresentable {
381381
case asciiBitset = 0
382382
case asciiChar = 1
383383
case any = 2
384-
case builtin = 4
384+
case builtinCC = 4
385385
}
386386

387387
// TODO: figure out how to better organize this...
@@ -408,6 +408,14 @@ struct QuantifyPayload: RawRepresentable {
408408
var typeMask: UInt64 { 7 }
409409
var payloadMask: UInt64 { 0xFF_FF }
410410

411+
// Calculate the maximum number of trips, else UInt64.max if unbounded
412+
var maxTrips: UInt64 {
413+
guard let maxExtraTrips else {
414+
return UInt64.max
415+
}
416+
return minTrips + maxExtraTrips
417+
}
418+
411419
static func packInfoValues(
412420
_ kind: AST.Quantification.Kind,
413421
_ minTrips: Int,
@@ -489,7 +497,7 @@ struct QuantifyPayload: RawRepresentable {
489497
+ (model.isInverted ? 1 << 9 : 0)
490498
+ (model.isStrictASCII ? 1 << 10 : 0)
491499
self.rawValue = packedModel
492-
+ QuantifyPayload.packInfoValues(kind, minTrips, maxExtraTrips, .builtin, isScalarSemantics: isScalarSemantics)
500+
+ QuantifyPayload.packInfoValues(kind, minTrips, maxExtraTrips, .builtinCC, isScalarSemantics: isScalarSemantics)
493501
}
494502

495503
var type: PayloadType {
@@ -535,7 +543,7 @@ struct QuantifyPayload: RawRepresentable {
535543
(self.rawValue & 1) == 1
536544
}
537545

538-
var builtin: _CharacterClassModel.Representation {
546+
var builtinCC: _CharacterClassModel.Representation {
539547
_CharacterClassModel.Representation(rawValue: self.rawValue & 0xFF)!
540548
}
541549
var builtinIsInverted: Bool {

Sources/_StringProcessing/Engine/MEBuiltins.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,25 @@ extension String {
223223
else { return nil }
224224
return next
225225
}
226+
227+
internal func matchRegexDot(
228+
at currentPosition: Index,
229+
limitedBy end: Index,
230+
anyMatchesNewline: Bool,
231+
isScalarSemantics: Bool
232+
) -> Index? {
233+
guard currentPosition < end else { return nil }
234+
235+
if anyMatchesNewline {
236+
return index(
237+
after: currentPosition, isScalarSemantics: isScalarSemantics)
238+
}
239+
240+
return matchAnyNonNewline(
241+
at: currentPosition,
242+
limitedBy: end,
243+
isScalarSemantics: isScalarSemantics)
244+
}
226245
}
227246

228247
// MARK: - Built-in character class matching

0 commit comments

Comments
 (0)