Skip to content

Commit ca66442

Browse files
committed
Add programmers manual
1 parent 95478ee commit ca66442

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Documentation/ProgrammersManual.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Programmer's Manual
2+
3+
## Programming patterns
4+
5+
### Engine quick checks and fast paths
6+
7+
In the engine nomenclature, a quick-check results in a yes/no/maybe while a thorough check always results in a definite answer.
8+
9+
The nature of quick checks and fast paths is that they bifurcate testing coverage. One easy way to prevent this in simple cases is to assert that a definite quick result matches the thorough result.
10+
11+
One example of this pattern is matching against a builtin character class. The engine has a `_doMatchBuiltinCC`
12+
13+
```swift
14+
func _doMatchBuiltinCC(...) -> Input.Index? {
15+
// Calls _quickMatchBuiltinCC, if that gives a definite result
16+
// asserts that it is the same as the result of
17+
// _thoroughMatchBuiltinCC and returns it. Otherwise returns the
18+
// result of _thoroughMatchBuiltinCC
19+
}
20+
21+
@inline(__always)
22+
func _quickMatchBuiltinCC(...) -> QuickResult<Input.Index?>
23+
24+
@inline(never)
25+
func _thoroughMatchBuiltinCC(...) -> Input.Index?
26+
```
27+
28+
The thorough check is never inlined, as it is a lot of cold code. Note that quick and thorough functions should be pure, that is they shouldn't update processor state.
29+
30+

Sources/_StringProcessing/Engine/MEBuiltins.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension Processor {
2828
return true
2929
}
3030

31+
// Mentioned in ProgrammersManual.md, update docs if redesigned
3132
func _doMatchBuiltinCC(
3233
_ cc: _CharacterClassModel.Representation,
3334
isInverted: Bool,
@@ -54,6 +55,7 @@ extension Processor {
5455
isScalarSemantics: isScalarSemantics)
5556
}
5657

58+
// Mentioned in ProgrammersManual.md, update docs if redesigned
5759
@inline(__always)
5860
func _quickMatchBuiltinCC(
5961
_ cc: _CharacterClassModel.Representation,
@@ -69,6 +71,7 @@ extension Processor {
6971
return .definite(result == isInverted ? nil : next)
7072
}
7173

74+
// Mentioned in ProgrammersManual.md, update docs if redesigned
7275
@inline(never)
7376
func _thoroughMatchBuiltinCC(
7477
_ cc: _CharacterClassModel.Representation,

0 commit comments

Comments
 (0)