Repository navigation
rust2(grep): GNU grep 3.11 library port on winux-regex (#1488) - #1631
Closed
caomengxuan666 wants to merge 3 commits into
Closed
caomengxuan666 wants to merge 3 commits into
caomengxuan666 wants to merge 3 commits into
Conversation
Adds the `dfa` module (additive: one `pub mod` line in lib.rs, no change
to the parser/matcher/fastpath): the same parsed node tree the
interpreter runs on is compiled into a Thompson NFA and determinized
lazily per (state, byte class), answering "does this line match" for a
SET of regexes in one table lookup per byte — GNU grep's dfa.c/regexec
split (DFA selects lines, the interpreter only runs for back-references
and match spans).
Equivalence contract (tests/dfa_equiv.rs, 6000-round generated
differential + every matrix.tsv row, 150000 rounds clean locally):
LineMode::Contains == find_at_bytes(line, 0).is_some(), LineMode::Entire
== matches_entire_bytes(line). Literals/brackets reuse chars_equal /
class_matches (identical -i folding); the unanchored scan attempts
exactly the interpreter's scan_positions through a next-is-not-a-
continuation lookahead. `.` is exact on well-formed UTF-8, word
assertions on ASCII lines (input_requirement() tells the caller which
lines to route to the interpreter); back-references, oversized NFAs and
counted repeats over conditionally-empty bodies (where the interpreter's
empty-iteration rule reaches fewer positions than GNU, e.g.
`(^|\w){2} +` on "_ ") return None and stay on the interpreter.
find_line() scans a whole buffer of eol-terminated lines (eol = \n, or
\0 for grep -z) and returns the first matching line's bounds.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
) Additive method on Regex (no change to existing entry points): the deduplicated end positions of all matches anchored at a start, longest first. grep -w needs it for GNU EGexecute's "try a shorter match at the same place" walk (re_match with a shrinking limit), which the best-end-only match_at_bytes cannot express. The longest end always equals match_at_bytes; a tripped work budget is the conservative empty answer. Tests: tests/match_ends.rs (expected end lists + every listed end re-verified as an anchored full match of the prefix). Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Eight-module port (mod/opts/pattern/scan/walk/bytes/text/tests): - -F literal multi-pattern via LitSet trie + LineDfa; packed-pair Finder for single case-sensitive literal patterns - -E/-G carried by winux-regex Basic/Extended; -P stays on the C++ PCRE2 path (bridge route lands with the wire commit, uses_perl already exported); -X awk approximated as Extended (documented) - exit-code contract 0/1/2 with -q early-exit ordering; binary-file two-state reporting incl. NUL zap and UTF-8 encoding-error trigger - recursive -r/-R symlink semantics + gnulib excluded_file_name last-match-wins include/exclude handling - full getopt_long grammar incl. ambiguity disambiguation and POSIXLY_CORRECT reordering; glibc regerror wording mapping Differential: 162 gate rows green (grep 142 / egrep 11 / fgrep 9, 14 rows added during review); 28-case oracle probe set byte-identical (target/grep-review/). Perf on 64MiB -c literal: ~99-138 ms vs GNU grep 3.11 ~103 ms warm; C++ release ~370-554 ms. Documented deviations (mod.rs header): --color=auto never colors (injected handles), -T stdin width, -i folds ASCII only (engine-level gap, tracked separately), -X awk approximation, no stdin rewinding. I18N prerequisite for the wire PR: regerror/walk messages need stable tr! keys per the 2.0 continuation checkpoint.
Member
Author
|
Superseded by the wire PR — the library commits ride inside it (rust2/grep-wire). Will be linked from there; this one stays as the library-landing record. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Library landing for the grep big-ticket lane. Wire (bridge route + dispatcher + PCRE2 split + C++ body retirement) follows in a second commit series — this PR is the library + differential evidence.
Scope
Evidence
rust2/target/gate/ledger.tsvtarget/grep-review/)Known deviations (documented in mod.rs header)
--color=auto never colors (injected handles); -T stdin width; -i folds ASCII only (engine-level, tracked separately); no stdin rewinding.
Expected CI status: i18n-drift may report new keys until the wire commit lands tr! keys for the walk/regerror message face (2.0 checkpoint I18N prerequisite). Compile/test legs should be green.