Skip to content

Emit custom character classes like an alternation #590

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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3b6b676
Copy over new ascii bitset
rctcwyvrn Jul 5, 2022
33caa79
Add matchBuiltin
rctcwyvrn Jul 5, 2022
139daa5
Remove debug prints
rctcwyvrn Jul 5, 2022
9abf4af
Remove bitset fast path
rctcwyvrn Jul 5, 2022
286f5d8
Fully remove remnants of the bitset fast path
rctcwyvrn Jul 6, 2022
9e915cd
Merge branch 'main' into speedy-builtins
rctcwyvrn Jul 7, 2022
e593ddb
Completely replace AssertionFunction with regexAssert(by:)
rctcwyvrn Jul 11, 2022
25dc277
Merge branch 'main' into speedy-builtins
rctcwyvrn Jul 12, 2022
3e38ac6
Cleanup
rctcwyvrn Jul 12, 2022
e5d8b4a
Move match builtin and assert + Add AssertionPayload
rctcwyvrn Jul 12, 2022
0466c25
Cleanup assertions
rctcwyvrn Jul 12, 2022
87078ad
Merge branch 'main' into speedy-builtins
rctcwyvrn Jul 12, 2022
f401e84
Fix tests
rctcwyvrn Jul 13, 2022
b09f45f
Update opcode description for assertBy
rctcwyvrn Jul 13, 2022
c581ea2
Merge branch 'main' into speedy-builtins
rctcwyvrn Jul 14, 2022
2a82231
Merge branch 'main' into speedy-builtins
rctcwyvrn Jul 15, 2022
fb1576a
Update branch to match main
rctcwyvrn Jul 15, 2022
3b9485e
Use the newly cleaned up _CharacterClassModel
rctcwyvrn Jul 16, 2022
64d1ed9
Add characterClass DSLTree node
rctcwyvrn Jul 16, 2022
2a6fe3c
Bugfixes
rctcwyvrn Jul 19, 2022
206bfc6
Add documentation for matchBuiltin
rctcwyvrn Jul 21, 2022
b53f524
Lots of cleanup
rctcwyvrn Jul 25, 2022
bb5245f
Move assertion payload
rctcwyvrn Jul 25, 2022
0746847
More minor cleanup
rctcwyvrn Jul 25, 2022
c718543
Perform boundary check for .anyScalar when in grapheme mode
rctcwyvrn Jul 25, 2022
3f0ece5
Emit custom character classes via saves and branches
rctcwyvrn Jul 25, 2022
79aabab
Add some comments
rctcwyvrn Jul 26, 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
Prev Previous commit
Next Next commit
Remove bitset fast path
  • Loading branch information
rctcwyvrn committed Jul 5, 2022
commit 9abf4afd6309d3c57aca02ee8404d77d639c4c22
10 changes: 5 additions & 5 deletions Sources/_StringProcessing/Engine/InstPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,20 @@ extension Instruction.Payload {
interpret()
}

init(_ cc: BuiltinCC, _ isStrict: Bool, _ isScalar: Bool, bitset: AsciiBitsetRegister) {
init(_ cc: BuiltinCC, _ isStrict: Bool, _ isScalar: Bool) {
let strictBit = isStrict ? 1 << 15 : 0
let scalarBit = isScalar ? 1 << 14 : 0
// val must be 16 bits, reserve the top 2 bits for if it is strict ascii or scalar
assert(cc.rawValue <= 0x3F_FF)
let val = cc.rawValue + UInt64(strictBit) + UInt64(scalarBit)
self.init(val, bitset)
self.init(val)
}
var builtinCCPayload: (cc: BuiltinCC, isStrict: Bool, isScalar: Bool, bitset: AsciiBitsetRegister) {
let (val, bitset): (UInt64, AsciiBitsetRegister) = self.interpretPair()
var builtinCCPayload: (cc: BuiltinCC, isStrict: Bool, isScalar: Bool) {
let val = self.rawValue
let cc = BuiltinCC(rawValue: val & 0x3F_FF)!
let isStrict = (val >> 15) & 1 == 1
let isScalar = (val >> 14) & 1 == 1
return (cc, isStrict, isScalar, bitset)
return (cc, isStrict, isScalar)
}

init(consumer: ConsumeFunctionRegister) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/MEBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extension MEProgram.Builder {
isScalar: Bool
) {
instructions.append(.init(
.matchBuiltin, .init(cc, isStrict, isScalar, bitset: makeAsciiBitset(bitset))))
.matchBuiltin, .init(cc, isStrict, isScalar)))
}

mutating func buildConsume(
Expand Down
31 changes: 5 additions & 26 deletions Sources/_StringProcessing/Engine/Processor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,13 @@ extension Processor {

mutating func matchBuiltin(
_ cc: BuiltinCC,
_ isStrictAscii: Bool,
_ bitset: DSLTree.CustomCharacterClass.AsciiBitset
_ isStrictAscii: Bool
) -> Bool {
guard let c = load() else {
signalFailure()
return false
}

// Fast path: See if c is a single scalar ascii character
// If so, and it matches, consume a character
// Note: CR-LF will fall through because it is not a single scalar
if bitset.matches(char: c) && cc != .anyScalar {
_uncheckedForcedConsumeOne()
return true
}

// Slow path: Do full match
var matched: Bool
var next = input.index(after: currentPosition)
Expand Down Expand Up @@ -300,23 +291,12 @@ extension Processor {

mutating func matchBuiltinScalar(
_ cc: BuiltinCC,
_ isStrictAscii: Bool,
_ bitset: DSLTree.CustomCharacterClass.AsciiBitset
_ isStrictAscii: Bool
) -> Bool {
guard let c = loadScalar() else {
signalFailure()
return false
}

// Fast path: See if c is a single scalar ascii character
// If so, and it matches, consume a character
// Note: CR-LF must be matched fully if we are matching a .newlineSequence
// so exclude "\r" from the fast path
if bitset.matches(scalar: c) && cc != .anyGrapheme && c != "\r" {
input.unicodeScalars.formIndex(after: &currentPosition)
return true
}

// Slow path: Do full match
var matched: Bool
var next = input.unicodeScalars.index(after: currentPosition)
Expand Down Expand Up @@ -501,14 +481,13 @@ extension Processor {
}

case .matchBuiltin:
let (cc, isStrict, isScalar, reg) = payload.builtinCCPayload
let bitset = registers[reg]
let (cc, isStrict, isScalar) = payload.builtinCCPayload
if isScalar {
if matchBuiltinScalar(cc, isStrict, bitset) {
if matchBuiltinScalar(cc, isStrict) {
controller.step()
}
} else {
if matchBuiltin(cc, isStrict, bitset) {
if matchBuiltin(cc, isStrict) {
controller.step()
}
}
Expand Down