flexr 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/CONTRIBUTING.md +10 -7
- data/Rakefile +11 -1
- data/benchmark/golden/calculator_lexer.rb +6 -14
- data/benchmark/golden/graphql_lexer.rb +6 -14
- data/benchmark/golden/json_lexer.rb +18 -28
- data/benchmark/golden/regexp_tokenizer.rb +6 -14
- data/benchmark/golden/ruby_subset_lexer.rb +6 -14
- data/benchmark/golden/sql_lexer.rb +6 -14
- data/benchmark/golden/toml_lexer.rb +6 -14
- data/benchmark/golden/toy_lang_lexer.rb +6 -14
- data/benchmark/golden/with_lrama_lexer.rb +6 -14
- data/benchmark/golden/with_racc_lexer.rb +6 -14
- data/benchmark/matrix.rb +31 -4
- data/docs/RELEASING.md +13 -2
- data/docs/adr/0003-leftmost-longest.md +3 -0
- data/docs/adr/0019-measured-performance-floor.md +4 -9
- data/docs/adr/0027-per-engine-performance-targets.md +45 -0
- data/docs/adr/0028-dfa-absence-groups.md +28 -0
- data/docs/adr/0029-pattern-algebra.md +30 -0
- data/docs/adr/0030-classify-keywords-after-matching.md +24 -0
- data/docs/adr/0031-trivia-channels.md +24 -0
- data/docs/adr/0032-explicit-rule-priority.md +18 -0
- data/docs/migration-v2.md +4 -3
- data/docs/perf-log.md +258 -0
- data/docs/reference/compatibility.md +5 -0
- data/docs/reference/diagnostics.md +36 -7
- data/docs/reference/dsl.md +113 -8
- data/docs/reference/public-api.md +1 -0
- data/docs/reference/regexp.md +33 -1
- data/docs/reference/runtime.md +6 -2
- data/docs/reference/tokens-and-locations.md +33 -0
- data/lib/flexr/automaton/accel.rb +1 -0
- data/lib/flexr/automaton/analysis.rb +8 -5
- data/lib/flexr/automaton/compiler.rb +327 -54
- data/lib/flexr/automaton/dfa.rb +1 -1
- data/lib/flexr/automaton/dfa_operations.rb +63 -0
- data/lib/flexr/automaton/keyword_tables.rb +113 -0
- data/lib/flexr/automaton/nfa.rb +22 -1
- data/lib/flexr/cli.rb +64 -6
- data/lib/flexr/codegen/table.rb +44 -30
- data/lib/flexr/configuration.rb +14 -0
- data/lib/flexr/diagnostics.rb +1 -0
- data/lib/flexr/dsl.rb +28 -7
- data/lib/flexr/generated.rb +4 -1
- data/lib/flexr/generator.rb +62 -14
- data/lib/flexr/importer.rb +1 -1
- data/lib/flexr/ir.rb +9 -1
- data/lib/flexr/keywords.rb +65 -0
- data/lib/flexr/pattern.rb +76 -0
- data/lib/flexr/regexp/ast.rb +28 -2
- data/lib/flexr/regexp/normalizer.rb +35 -1
- data/lib/flexr/regexp/parser.rb +7 -4
- data/lib/flexr/regexp/tokenizer.rb +8 -16
- data/lib/flexr/runtime/channels.rb +70 -0
- data/lib/flexr/runtime/core.rb +12 -5
- data/lib/flexr/runtime/interpreter.rb +11 -7
- data/lib/flexr/runtime/token.rb +6 -0
- data/lib/flexr/runtime.rb +6 -3
- data/lib/flexr/source/prism_reader.rb +52 -10
- data/lib/flexr/source/static_eval.rb +19 -0
- data/lib/flexr/trace.rb +18 -12
- data/lib/flexr/version.rb +1 -1
- data/lib/ruby_lsp/flexr/addon.rb +30 -4
- data/sig/flexr.rbs +18 -4
- data/site/README.md +16 -0
- data/site/astro.config.mjs +8 -0
- data/site/package.json +3 -2
- data/site/ruby/playground.rb +9 -0
- data/site/ruby/presets/absence.flexr.rb +7 -0
- data/site/ruby/presets/keywords.flexr.rb +9 -0
- data/site/ruby/presets/pattern.flexr.rb +11 -0
- data/site/ruby/presets/priority.flexr.rb +7 -0
- data/site/ruby/presets/trivia.flexr.rb +8 -0
- data/site/scripts/prepare-docs.mjs +23 -0
- data/site/scripts/prepare-playground.mjs +26 -2
- data/site/scripts/stable-release.mjs +16 -0
- data/site/src/components/DocsTitle.astro +30 -0
- data/site/src/content/docs/benchmarks.md +11 -1
- data/site/src/docs-navigation.ts +14 -0
- data/site/src/pages/playground.astro +7 -0
- data/site/tests/browser/documentation-versions.spec.mjs +33 -0
- data/site/tests/browser/playground.spec.mjs +35 -0
- data/site/tests/playground-release.test.mjs +71 -0
- data/site/tests/playground-runtime.test.mjs +70 -0
- data/test/ruby_lsp_addon_spec.rb +71 -0
- data/tools/release_notes.rb +15 -0
- metadata +24 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9f29243c0399d336c8a00ebf358ba0f6586f1cbf84d54a30913b7aef431926c
|
|
4
|
+
data.tar.gz: 7b0d2ef0f5a6812f5dd46f8d9c01a2c85afbcb34808ff5a7e5f4bc5d65a0ff86
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 889086c628ade02d5239e754ca174b3e2a6e930011e6efce4ec6291623ea4ecf90c01bcc6adb7507431a41b80bf076be06bc631430ba89d83c011fc378e138e3
|
|
7
|
+
data.tar.gz: 72857d5415c72b010b4abe48693a9f351fb3133909e68084f67d018068cc099328a3143b0ca09c3445a6fe0c1c0b5e657d6f0060f91e0fcbc3d23a274407b158
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
Notable changes to flexr, newest first. Release dates use Japan Standard Time
|
|
4
4
|
(UTC+09:00).
|
|
5
5
|
|
|
6
|
+
## [2.1.0](https://github.com/ydah/flexr/compare/v2.0.0...v2.1.0)
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Use `(?~X)` in DFA rules to match text containing no substring matched
|
|
11
|
+
by `X`. For example, `%r{/\*(?~\*/)\*/}` matches a C-style comment.
|
|
12
|
+
- Reuse named patterns across rules and combine them with alternatives,
|
|
13
|
+
concatenation, intersection, difference, and complement. Use `upto` to
|
|
14
|
+
consume through the first match of a terminator.
|
|
15
|
+
- Use `keywords` to turn exact identifier spellings into keyword tokens after
|
|
16
|
+
the identifier rule matches. A longer identifier such as `ifx` still emits
|
|
17
|
+
the identifier token.
|
|
18
|
+
- Retain comments and whitespace in named token channels for source tools.
|
|
19
|
+
Collect them in input order with `tokens(channels: :all)` or read
|
|
20
|
+
`leading_trivia` on structured tokens. Default iteration and parser token
|
|
21
|
+
streams still return only default-channel tokens.
|
|
22
|
+
- Set `priority:` to break ties between equal-length DFA matches. Rules with
|
|
23
|
+
equal priority continue to use source order.
|
|
24
|
+
- `flexr check` can flag shadowed keyword spellings and suggest replacing
|
|
25
|
+
consecutive literal rules with a keyword table. With `--warn all`, it can
|
|
26
|
+
also suggest `emit:` for simple emission blocks.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- DFA scanning allocates fewer temporary objects. Regenerate lexer files to include the updated scanner paths.
|
|
31
|
+
- Generated lexers that use token channels or nonzero rule priorities require
|
|
32
|
+
the Flexr 2.1 runtime. Standalone files include their runtime.
|
|
33
|
+
|
|
6
34
|
## [2.0.0](https://github.com/ydah/flexr/compare/v1.1.0...v2.0.0) - 2026-11-22
|
|
7
35
|
|
|
8
36
|
### Added
|
data/CONTRIBUTING.md
CHANGED
|
@@ -40,18 +40,21 @@ under `tmp/golden/`. Review that diff before accepting an intentional generator
|
|
|
40
40
|
change with `bundle exec rake golden:update`, then review the committed snapshot
|
|
41
41
|
diffs. Verification never updates the expected snapshots.
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
Changes to Ruby code or configuration run runtime and generator checks on
|
|
44
|
+
Ruby 3.4 and 4.0 across Linux, macOS, and Windows. Runtime checks also exercise
|
|
45
|
+
YJIT on Linux. Daily runs add Ruby head and macOS YJIT to the matrix.
|
|
46
|
+
The Ubuntu Ruby 4.0 interpreter job runs the suite with the 95% coverage
|
|
47
|
+
gate. The runtime and generator jobs run the full example verification tasks.
|
|
48
|
+
Those workflows skip changes limited to Markdown and the product site.
|
|
48
49
|
|
|
49
50
|
## Replay a verification mismatch
|
|
50
51
|
|
|
51
52
|
`test:differential` and `fuzz` save the first mismatch in
|
|
52
53
|
`tmp/verification-failures/` and exit with status 1.
|
|
53
|
-
The differential-fuzz workflow
|
|
54
|
-
`
|
|
54
|
+
The differential-fuzz workflow splits the seeded fuzz cases across three jobs.
|
|
55
|
+
To run one shard locally, set `FLEXR_FUZZ_SHARD` to a zero-based `INDEX/TOTAL`,
|
|
56
|
+
such as `2/3`. Each job attaches any saved failures as a
|
|
57
|
+
`verification-failures-<index>` artifact.
|
|
55
58
|
Replay one case from the repository root.
|
|
56
59
|
|
|
57
60
|
```sh
|
data/Rakefile
CHANGED
|
@@ -566,6 +566,11 @@ desc "Compare runtime and generated lexers on randomized inputs"
|
|
|
566
566
|
task :fuzz do
|
|
567
567
|
cases = Integer(ENV.fetch("FLEXR_FUZZ_CASES", "10000"), 10)
|
|
568
568
|
seed = Integer(ENV.fetch("FLEXR_SEED", "17"), 10)
|
|
569
|
+
shard = ENV.fetch("FLEXR_FUZZ_SHARD", "0/1")
|
|
570
|
+
shard_parts = %r{\A(\d+)/(\d+)\z}.match(shard)
|
|
571
|
+
shard_index, shard_count = shard_parts.captures.map(&:to_i) if shard_parts
|
|
572
|
+
abort "FLEXR_FUZZ_SHARD must be INDEX/TOTAL with 0 <= INDEX < TOTAL" unless shard_parts && shard_index < shard_count
|
|
573
|
+
|
|
569
574
|
random = Random.new(seed)
|
|
570
575
|
FlexrVerification::VERIFICATION_SPECS.each do |spec|
|
|
571
576
|
FlexrVerification.with_fuzz_lexers(spec) do |runtime_lexer, generated_lexer|
|
|
@@ -581,6 +586,9 @@ task :fuzz do
|
|
|
581
586
|
(FlexrVerification.random_unicode_string(random, max_codepoints: 16) +
|
|
582
587
|
Array.new(random.rand(64)) { random.rand(32..126) }.pack("C*")).force_encoding(Encoding::UTF_8)
|
|
583
588
|
end
|
|
589
|
+
# Generate skipped inputs so every shard uses the same seeded sequence.
|
|
590
|
+
next unless index % shard_count == shard_index
|
|
591
|
+
|
|
584
592
|
expected = FlexrVerification.lexer_outcome(runtime_lexer, input, **FlexrVerification::FUZZ_OPTIONS)
|
|
585
593
|
actual = FlexrVerification.lexer_outcome(generated_lexer, input, **FlexrVerification::FUZZ_OPTIONS)
|
|
586
594
|
next if expected == actual
|
|
@@ -595,7 +603,9 @@ task :fuzz do
|
|
|
595
603
|
end
|
|
596
604
|
end
|
|
597
605
|
end
|
|
598
|
-
|
|
606
|
+
checked_cases = [cases - shard_index, 0].max.ceildiv(shard_count)
|
|
607
|
+
shard_label = shard_count == 1 ? "" : " (shard #{shard})"
|
|
608
|
+
puts "fuzz: #{checked_cases} inputs per example passed#{shard_label}"
|
|
599
609
|
end
|
|
600
610
|
|
|
601
611
|
namespace :verification do
|
|
@@ -85,23 +85,12 @@ module CalculatorExample
|
|
|
85
85
|
rules = self.class.__flexr_rules
|
|
86
86
|
source = buffer.stable_source
|
|
87
87
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
88
|
check_token_limit = token_limit_required?
|
|
91
89
|
cursor = position
|
|
92
90
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
while cursor < source.bytesize
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
91
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
92
|
+
while (byte = source.getbyte(cursor))
|
|
93
|
+
current = dfa.transition(current, byte)
|
|
105
94
|
break unless current
|
|
106
95
|
cursor += 1
|
|
107
96
|
acceptance = accepts[current].first
|
|
@@ -115,6 +104,9 @@ module CalculatorExample
|
|
|
115
104
|
end
|
|
116
105
|
return best
|
|
117
106
|
end
|
|
107
|
+
token_start = more_text_start || position
|
|
108
|
+
token_limit = max_token_size
|
|
109
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
110
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
111
|
if accelerate
|
|
120
112
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -85,23 +85,12 @@ module GraphqlExample
|
|
|
85
85
|
rules = self.class.__flexr_rules
|
|
86
86
|
source = buffer.stable_source
|
|
87
87
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
88
|
check_token_limit = token_limit_required?
|
|
91
89
|
cursor = position
|
|
92
90
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
while cursor < source.bytesize
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
91
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
92
|
+
while (byte = source.getbyte(cursor))
|
|
93
|
+
current = dfa.transition(current, byte)
|
|
105
94
|
break unless current
|
|
106
95
|
cursor += 1
|
|
107
96
|
acceptance = accepts[current].first
|
|
@@ -115,6 +104,9 @@ module GraphqlExample
|
|
|
115
104
|
end
|
|
116
105
|
return best
|
|
117
106
|
end
|
|
107
|
+
token_start = more_text_start || position
|
|
108
|
+
token_limit = max_token_size
|
|
109
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
110
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
111
|
if accelerate
|
|
120
112
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -20,11 +20,11 @@ module JsonExample
|
|
|
20
20
|
machine = self.class.__flexr_compiled.machines.fetch(@state)
|
|
21
21
|
@__flexr_generated_scan_state = @state
|
|
22
22
|
@__flexr_generated_scan_dfa = machine.dfa
|
|
23
|
-
@
|
|
23
|
+
@__flexr_generated_scan_layout = __flexr_generated_direct_layout(@__flexr_generated_scan_dfa)
|
|
24
24
|
@__flexr_generated_scan_simple = __flexr_generated_simple_fast_path?(@__flexr_generated_scan_dfa)
|
|
25
25
|
end
|
|
26
26
|
dfa = @__flexr_generated_scan_dfa
|
|
27
|
-
return Flexr::Runtime::Interpreter.new(self).scan unless @
|
|
27
|
+
return Flexr::Runtime::Interpreter.new(self).scan unless @__flexr_generated_scan_layout
|
|
28
28
|
position = byte_pos
|
|
29
29
|
return nil unless valid_utf8_at?(position)
|
|
30
30
|
return __flexr_generated_scan_simple(dfa, position) if @__flexr_generated_scan_simple
|
|
@@ -76,33 +76,16 @@ module JsonExample
|
|
|
76
76
|
best
|
|
77
77
|
end
|
|
78
78
|
def __flexr_generated_scan_simple(dfa, position)
|
|
79
|
-
current =
|
|
80
|
-
direct = dfa.direct
|
|
81
|
-
direct_nxt = direct&.fetch(:nxt)
|
|
82
|
-
direct_classes = direct&.fetch(:classes)
|
|
83
|
-
ec = dfa.ec
|
|
84
|
-
accepts = dfa.accepts
|
|
85
|
-
rules = self.class.__flexr_rules
|
|
79
|
+
current, direct_nxt, direct_classes, ec, accepts, rules = @__flexr_generated_scan_layout
|
|
86
80
|
source = buffer.stable_source
|
|
87
81
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
82
|
check_token_limit = token_limit_required?
|
|
91
83
|
cursor = position
|
|
92
84
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
105
|
-
break unless current
|
|
85
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
86
|
+
while (byte = source.getbyte(cursor))
|
|
87
|
+
current = direct_nxt[(current * direct_classes) + ec[byte]]
|
|
88
|
+
break if current < 0
|
|
106
89
|
cursor += 1
|
|
107
90
|
acceptance = accepts[current].first
|
|
108
91
|
next unless acceptance
|
|
@@ -115,6 +98,9 @@ module JsonExample
|
|
|
115
98
|
end
|
|
116
99
|
return best
|
|
117
100
|
end
|
|
101
|
+
token_start = more_text_start || position
|
|
102
|
+
token_limit = max_token_size
|
|
103
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
104
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
105
|
if accelerate
|
|
120
106
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -213,12 +199,16 @@ module JsonExample
|
|
|
213
199
|
@__flexr_generated_disabled_auto_accel ||= {}
|
|
214
200
|
@__flexr_generated_disabled_auto_accel[region] = true
|
|
215
201
|
end
|
|
216
|
-
def
|
|
202
|
+
def __flexr_generated_direct_layout(dfa)
|
|
217
203
|
@__flexr_generated_fast_paths ||= {}
|
|
218
204
|
return @__flexr_generated_fast_paths[dfa] if @__flexr_generated_fast_paths.key?(dfa)
|
|
219
|
-
rules =
|
|
220
|
-
|
|
221
|
-
|
|
205
|
+
rules = self.class.__flexr_rules
|
|
206
|
+
active_rules = dfa.rule_ids.map { |rule_index| rules.fetch(rule_index) }
|
|
207
|
+
@__flexr_generated_fast_paths[dfa] = if self.class.__flexr_config.backend != :firstmatch &&
|
|
208
|
+
self.class.__flexr_config.options[:allow_empty_match] != true && active_rules.none?(&:trailing)
|
|
209
|
+
direct = dfa.direct
|
|
210
|
+
[dfa.start, direct.fetch(:nxt), direct.fetch(:classes), dfa.ec, dfa.accepts, rules].freeze
|
|
211
|
+
end
|
|
222
212
|
end
|
|
223
213
|
def __flexr_generated_simple_fast_path?(dfa)
|
|
224
214
|
@__flexr_generated_simple_fast_paths ||= {}
|
|
@@ -88,23 +88,12 @@ module Flexr
|
|
|
88
88
|
rules = self.class.__flexr_rules
|
|
89
89
|
source = buffer.stable_source
|
|
90
90
|
guarded_steps = scan_steps_guarded?
|
|
91
|
-
token_start = more_text_start || position
|
|
92
|
-
token_limit = max_token_size
|
|
93
91
|
check_token_limit = token_limit_required?
|
|
94
92
|
cursor = position
|
|
95
93
|
best = nil
|
|
96
|
-
accel_mode
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
while cursor < source.bytesize
|
|
100
|
-
byte = source.getbyte(cursor)
|
|
101
|
-
current = if direct_nxt
|
|
102
|
-
class_id = ec[byte]
|
|
103
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
104
|
-
value >= 0 ? value : nil
|
|
105
|
-
else
|
|
106
|
-
dfa.transition(current, byte)
|
|
107
|
-
end
|
|
94
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
95
|
+
while (byte = source.getbyte(cursor))
|
|
96
|
+
current = dfa.transition(current, byte)
|
|
108
97
|
break unless current
|
|
109
98
|
cursor += 1
|
|
110
99
|
acceptance = accepts[current].first
|
|
@@ -118,6 +107,9 @@ module Flexr
|
|
|
118
107
|
end
|
|
119
108
|
return best
|
|
120
109
|
end
|
|
110
|
+
token_start = more_text_start || position
|
|
111
|
+
token_limit = max_token_size
|
|
112
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
121
113
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
122
114
|
if accelerate
|
|
123
115
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -93,23 +93,12 @@ module RubySubset
|
|
|
93
93
|
rules = self.class.__flexr_rules
|
|
94
94
|
source = buffer.stable_source
|
|
95
95
|
guarded_steps = scan_steps_guarded?
|
|
96
|
-
token_start = more_text_start || position
|
|
97
|
-
token_limit = max_token_size
|
|
98
96
|
check_token_limit = token_limit_required?
|
|
99
97
|
cursor = position
|
|
100
98
|
best = nil
|
|
101
|
-
accel_mode
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
while cursor < source.bytesize
|
|
105
|
-
byte = source.getbyte(cursor)
|
|
106
|
-
current = if direct_nxt
|
|
107
|
-
class_id = ec[byte]
|
|
108
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
109
|
-
value >= 0 ? value : nil
|
|
110
|
-
else
|
|
111
|
-
dfa.transition(current, byte)
|
|
112
|
-
end
|
|
99
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
100
|
+
while (byte = source.getbyte(cursor))
|
|
101
|
+
current = dfa.transition(current, byte)
|
|
113
102
|
break unless current
|
|
114
103
|
cursor += 1
|
|
115
104
|
acceptance = accepts[current].first
|
|
@@ -123,6 +112,9 @@ module RubySubset
|
|
|
123
112
|
end
|
|
124
113
|
return best
|
|
125
114
|
end
|
|
115
|
+
token_start = more_text_start || position
|
|
116
|
+
token_limit = max_token_size
|
|
117
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
126
118
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
127
119
|
if accelerate
|
|
128
120
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -87,23 +87,12 @@ module SqlExample
|
|
|
87
87
|
rules = self.class.__flexr_rules
|
|
88
88
|
source = buffer.stable_source
|
|
89
89
|
guarded_steps = scan_steps_guarded?
|
|
90
|
-
token_start = more_text_start || position
|
|
91
|
-
token_limit = max_token_size
|
|
92
90
|
check_token_limit = token_limit_required?
|
|
93
91
|
cursor = position
|
|
94
92
|
best = nil
|
|
95
|
-
accel_mode
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
while cursor < source.bytesize
|
|
99
|
-
byte = source.getbyte(cursor)
|
|
100
|
-
current = if direct_nxt
|
|
101
|
-
class_id = ec[byte]
|
|
102
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
103
|
-
value >= 0 ? value : nil
|
|
104
|
-
else
|
|
105
|
-
dfa.transition(current, byte)
|
|
106
|
-
end
|
|
93
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
94
|
+
while (byte = source.getbyte(cursor))
|
|
95
|
+
current = dfa.transition(current, byte)
|
|
107
96
|
break unless current
|
|
108
97
|
cursor += 1
|
|
109
98
|
acceptance = accepts[current].first
|
|
@@ -117,6 +106,9 @@ module SqlExample
|
|
|
117
106
|
end
|
|
118
107
|
return best
|
|
119
108
|
end
|
|
109
|
+
token_start = more_text_start || position
|
|
110
|
+
token_limit = max_token_size
|
|
111
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
120
112
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
121
113
|
if accelerate
|
|
122
114
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -85,23 +85,12 @@ module TomlExample
|
|
|
85
85
|
rules = self.class.__flexr_rules
|
|
86
86
|
source = buffer.stable_source
|
|
87
87
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
88
|
check_token_limit = token_limit_required?
|
|
91
89
|
cursor = position
|
|
92
90
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
while cursor < source.bytesize
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
91
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
92
|
+
while (byte = source.getbyte(cursor))
|
|
93
|
+
current = dfa.transition(current, byte)
|
|
105
94
|
break unless current
|
|
106
95
|
cursor += 1
|
|
107
96
|
acceptance = accepts[current].first
|
|
@@ -115,6 +104,9 @@ module TomlExample
|
|
|
115
104
|
end
|
|
116
105
|
return best
|
|
117
106
|
end
|
|
107
|
+
token_start = more_text_start || position
|
|
108
|
+
token_limit = max_token_size
|
|
109
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
110
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
111
|
if accelerate
|
|
120
112
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -88,23 +88,12 @@ module ToyLang
|
|
|
88
88
|
rules = self.class.__flexr_rules
|
|
89
89
|
source = buffer.stable_source
|
|
90
90
|
guarded_steps = scan_steps_guarded?
|
|
91
|
-
token_start = more_text_start || position
|
|
92
|
-
token_limit = max_token_size
|
|
93
91
|
check_token_limit = token_limit_required?
|
|
94
92
|
cursor = position
|
|
95
93
|
best = nil
|
|
96
|
-
accel_mode
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
while cursor < source.bytesize
|
|
100
|
-
byte = source.getbyte(cursor)
|
|
101
|
-
current = if direct_nxt
|
|
102
|
-
class_id = ec[byte]
|
|
103
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
104
|
-
value >= 0 ? value : nil
|
|
105
|
-
else
|
|
106
|
-
dfa.transition(current, byte)
|
|
107
|
-
end
|
|
94
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
95
|
+
while (byte = source.getbyte(cursor))
|
|
96
|
+
current = dfa.transition(current, byte)
|
|
108
97
|
break unless current
|
|
109
98
|
cursor += 1
|
|
110
99
|
acceptance = accepts[current].first
|
|
@@ -118,6 +107,9 @@ module ToyLang
|
|
|
118
107
|
end
|
|
119
108
|
return best
|
|
120
109
|
end
|
|
110
|
+
token_start = more_text_start || position
|
|
111
|
+
token_limit = max_token_size
|
|
112
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
121
113
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
122
114
|
if accelerate
|
|
123
115
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -85,23 +85,12 @@ module WithLrama
|
|
|
85
85
|
rules = self.class.__flexr_rules
|
|
86
86
|
source = buffer.stable_source
|
|
87
87
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
88
|
check_token_limit = token_limit_required?
|
|
91
89
|
cursor = position
|
|
92
90
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
while cursor < source.bytesize
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
91
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
92
|
+
while (byte = source.getbyte(cursor))
|
|
93
|
+
current = dfa.transition(current, byte)
|
|
105
94
|
break unless current
|
|
106
95
|
cursor += 1
|
|
107
96
|
acceptance = accepts[current].first
|
|
@@ -115,6 +104,9 @@ module WithLrama
|
|
|
115
104
|
end
|
|
116
105
|
return best
|
|
117
106
|
end
|
|
107
|
+
token_start = more_text_start || position
|
|
108
|
+
token_limit = max_token_size
|
|
109
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
110
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
111
|
if accelerate
|
|
120
112
|
region = __flexr_generated_acceleration_region(dfa, current)
|
|
@@ -85,23 +85,12 @@ module WithRacc
|
|
|
85
85
|
rules = self.class.__flexr_rules
|
|
86
86
|
source = buffer.stable_source
|
|
87
87
|
guarded_steps = scan_steps_guarded?
|
|
88
|
-
token_start = more_text_start || position
|
|
89
|
-
token_limit = max_token_size
|
|
90
88
|
check_token_limit = token_limit_required?
|
|
91
89
|
cursor = position
|
|
92
90
|
best = nil
|
|
93
|
-
accel_mode
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
while cursor < source.bytesize
|
|
97
|
-
byte = source.getbyte(cursor)
|
|
98
|
-
current = if direct_nxt
|
|
99
|
-
class_id = ec[byte]
|
|
100
|
-
value = direct_nxt[(current * direct_classes) + class_id]
|
|
101
|
-
value >= 0 ? value : nil
|
|
102
|
-
else
|
|
103
|
-
dfa.transition(current, byte)
|
|
104
|
-
end
|
|
91
|
+
if source && !guarded_steps && !check_token_limit && (@accel_mode == :auto || @accel_mode == :none)
|
|
92
|
+
while (byte = source.getbyte(cursor))
|
|
93
|
+
current = dfa.transition(current, byte)
|
|
105
94
|
break unless current
|
|
106
95
|
cursor += 1
|
|
107
96
|
acceptance = accepts[current].first
|
|
@@ -115,6 +104,9 @@ module WithRacc
|
|
|
115
104
|
end
|
|
116
105
|
return best
|
|
117
106
|
end
|
|
107
|
+
token_start = more_text_start || position
|
|
108
|
+
token_limit = max_token_size
|
|
109
|
+
accelerate = @accel_mode != :none && !(@accel_mode == :auto && @__flexr_generated_auto_accel_off)
|
|
118
110
|
while cursor < (source ? source.bytesize : buffer.bytesize) || buffer.ensure_available?(cursor + 1)
|
|
119
111
|
if accelerate
|
|
120
112
|
region = __flexr_generated_acceleration_region(dfa, current)
|
data/benchmark/matrix.rb
CHANGED
|
@@ -27,17 +27,23 @@ module Flexr
|
|
|
27
27
|
@benchmark = benchmark || method(:benchmark_engine)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def run(engines: FLAGS.keys)
|
|
30
|
+
def run(engines: FLAGS.keys, verify_ratio: false)
|
|
31
31
|
results = engines.to_h do |engine|
|
|
32
32
|
availability = @probe.call(engine)
|
|
33
33
|
result = if availability.fetch("available")
|
|
34
|
-
|
|
34
|
+
measurement = verify_ratio ? measure_ratio(engine) : { "result" => @benchmark.call(engine) }
|
|
35
|
+
{ "status" => "measured", "ruby" => availability["ruby"], **measurement }
|
|
35
36
|
else
|
|
36
37
|
{ "status" => "unavailable", "reason" => availability.fetch("reason") }
|
|
37
38
|
end
|
|
38
39
|
[engine, result]
|
|
39
40
|
end
|
|
40
|
-
{ "schema" => 1, "engines" => results }
|
|
41
|
+
report = { "schema" => 1, "engines" => results }
|
|
42
|
+
if verify_ratio
|
|
43
|
+
failed = results.keys.reject { |engine| results.fetch(engine).fetch("median_generated_runtime_ratio", 0) >= 1.0 }
|
|
44
|
+
report["generated_runtime_ratio_check"] = { "minimum" => 1.0, "passed" => failed.empty?, "failed_engines" => failed }
|
|
45
|
+
end
|
|
46
|
+
report
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
def self.command(argv, out: $stdout, err: $stderr)
|
|
@@ -45,7 +51,13 @@ module Flexr
|
|
|
45
51
|
return Benchmarking.usage(out) if options[:help]
|
|
46
52
|
raise ArgumentError, "matrix results cannot share a baseline output file" if options[:write_baseline]
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
verify_ratio = ENV["FLEXR_BENCHMARK_CHECK_MATRIX"] == "1"
|
|
55
|
+
report = new(arguments: argv).run(verify_ratio: verify_ratio)
|
|
56
|
+
out.puts JSON.pretty_generate(report)
|
|
57
|
+
if (check = report["generated_runtime_ratio_check"]) && !check.fetch("passed")
|
|
58
|
+
err.puts "matrix error: generated/runtime ratio check failed for #{check.fetch('failed_engines').join(', ')}"
|
|
59
|
+
return 1
|
|
60
|
+
end
|
|
49
61
|
0
|
|
50
62
|
rescue ArgumentError, Errno::ENOENT => e
|
|
51
63
|
err.puts "matrix error: #{e.message}"
|
|
@@ -57,6 +69,21 @@ module Flexr
|
|
|
57
69
|
|
|
58
70
|
private
|
|
59
71
|
|
|
72
|
+
def measure_ratio(engine)
|
|
73
|
+
samples = Array.new(3) { @benchmark.call(engine) }
|
|
74
|
+
ratios = samples.map do |sample|
|
|
75
|
+
modes = sample.fetch("modes")
|
|
76
|
+
runtime = modes.fetch("runtime").fetch("tokens_per_s")
|
|
77
|
+
generated = modes.fetch("generated").fetch("tokens_per_s")
|
|
78
|
+
runtime.positive? ? generated.fdiv(runtime) : 0.0
|
|
79
|
+
end
|
|
80
|
+
median = ratios.each_index.sort_by { |index| ratios.fetch(index) }.fetch(1)
|
|
81
|
+
{
|
|
82
|
+
"result" => samples.fetch(median), "ratio_samples" => ratios,
|
|
83
|
+
"median_generated_runtime_ratio" => ratios.fetch(median)
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
60
87
|
def probe_engine(engine)
|
|
61
88
|
stdout, stderr, status = Open3.capture3({ "RUBYOPT" => nil }, RbConfig.ruby, *FLAGS.fetch(engine),
|
|
62
89
|
"-e", PROBE, engine, chdir: ROOT)
|
data/docs/RELEASING.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Releasing
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Run these checks from a clean checkout on the target Ruby versions before
|
|
4
|
+
pushing a release tag:
|
|
5
5
|
|
|
6
6
|
```sh
|
|
7
7
|
bundle exec rake test
|
|
@@ -25,6 +25,17 @@ Then:
|
|
|
25
25
|
4. Confirm generated golden files and the Unicode snapshot are intentional.
|
|
26
26
|
5. Create the release tag only after the working tree and CI are clean.
|
|
27
27
|
|
|
28
|
+
Pushing a tag such as `v2.1.0` starts the release workflow. The tag must match
|
|
29
|
+
`lib/flexr/version.rb` and have a corresponding numbered changelog section.
|
|
30
|
+
The workflow runs the checks on Ruby 3.4 and 4.0, publishes the gem with
|
|
31
|
+
RubyGems Trusted Publishing, then creates the GitHub Release from that
|
|
32
|
+
changelog section. Prerelease tags create GitHub prereleases.
|
|
33
|
+
|
|
34
|
+
The hosted benchmark uses the portable gate because shared runner speed
|
|
35
|
+
varies. Run the local benchmark command above on the reference machine to
|
|
36
|
+
check the absolute throughput floor before publishing. If the GitHub Release
|
|
37
|
+
step fails after the gem is published, rerun the failed jobs.
|
|
38
|
+
|
|
28
39
|
Unicode snapshot changes are minor-version compatibility changes because they
|
|
29
40
|
can change generated output. Stable runtime and generated-file contracts are
|
|
30
41
|
preserved within a major version unless this document and the changelog
|