Repository navigation
wire(grep): route non-Perl grep through rust2, retire the dead C++ face (#1488) - #1660
Merged
Merged
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.
… start (grep.c:1612) prtext's leading-context walk dropped the beg > bufbeg boundary. With a saturating -B/-C clamp (INTMAX_MAX, grep.c:826) gcc eliminates the dead loop; the Rust side spun 9.2e18 iterations and hung (ctest #1322 reproduces). Same boundary + regression test saturating_before_context_terminates.
…ce (#1488) - FFI export winuxcmd_grep_uses_perl (additive query; ABI version stays 2 — no run-contract change); bridge export winux::rust2::grep_uses_perl with POSIXLY_CORRECT from the process env (same source as the run entries' env snapshot) - grep handler splits on uses_perl: non-Perl -> run_command_with_stdin_streaming (true streaming stdin reader, REPLACEMENT-RECIPE section 5); -P stays on the C++ PCRE2 face - egrep/fgrep route unconditionally: upstream 3.11 wrappers are exec grep -E/-F, so egrep -P is a matcher conflict (rc 2), never Perl; the 1.x body running Perl there was a standing oracle deviation, retired with the wire (gate eg02) - Rust egrep_cmd/fgrep_cmd carry the obsolescent warning + preset themselves; C++ registration keeps only help/man - grep.cpp 3096 -> ~2280 lines: Aho-Corasick fixed family, ERE literal/class fast paths, fixed scan fast path, BRE/ERE compile branches - all unreachable from -P (build_config rejects the combos pre-compile); scan/print/color/walk/binary pipeline and the Perl matcher kept - CMake WINUXCMD_RUST2_COMMANDS union line += grep (egrep/fgrep share grep.cpp; the OFF filter drops all three applets) - bridge drain_result write-error status per command: grep family keeps GNU EXIT_TROUBLE 2 (WSL probe: grep x a.txt b.txt >&- -> rc 2 + 'grep: write error: Bad file descriptor'), other commands stay 1 Gate 162 rows all green (r=c:no deltas all classified, zero new); ctest grep-family failure set identical to the pre-wire baseline; 60x3 old-exe byte matrix classified; -P split smoke 10/10; default and full editions build clean. Evidence under rust2/target/wire-i18n/.
7 rows strict->win per the wire decision (egrep/fgrep conflict and obsolescent semantics); re-gen idempotent. cmd-matrix.sh: grep-family 60x3 block (recursive/-o/-v/-c/-l/-L/-q/-b/-T/-Z/-z/-i/-w/-x/-m/-U/ -s/--label/binary four states/stdin/wrapper/conflict) + restores the sha224sum block's missing ';;' (syntax error broke any invocation).
10 tests pinning retired extensions re-pinned per the e7ddc43 precedent (6 operand-glob + 2 BOM/UTF-16 + exclude-from 2), each with its WSL probe citation; failure set vs pre-wire baseline verified identical.
Full gate/ctest/matrix evidence summary; records the one walk.rs open gap (empty operand '' parses as cwd -> 'Is a directory' vs GNU 'No such file or directory') as grep-impl lane scope, unfixed here.
19 print sites migrated to tr! with stable command.grep/.{egrep,fgrep}
keys (24 error + 8 warning + 2 wrapper), batch-1 style: GNU error()
inner-wording fallbacks, program prefixes stay in code, named
placeholders, {{ }} escaping for brace text.
- Tier 1 (ctx in hand, zero structure change): obsolescent wrapper
warnings, write error, context-length overflow x4 (unified helper),
matcher conflicts, -D/-P/-X/-u/-m/--binary-files argmatch failures,
GREP_COLOR deprecation
- Tier 2: walk.rs recursive-directory-loop (Runner already held ctx)
- Tier 3 (single-parameter threading, Runner precedent): Printer.ctx
for the binary-file report; compile/dfa_lex_pass ctx for the 13
glibc regerror classes + 5 dfa warnings
Not migrated (recorded, out of grep's ownership): fsutil errno/reason
layer (shared strerror mapping - belongs to a shared-layer batch, same
as batch-1), help/version/usage constants (independent catalog
category).
Byte stability: gate 162 rows green on the rebuilt binary; 60x3
stderr matrix hashes identical to pre-migration; ctest grep failure
set == baseline. cargo winux-cmds 772/0, ffi 16/0, fmt clean.
Extraction: 34 new keys, zero fallback conflicts.
Companion catalog commit cd9980d (i18n repo, VERSION 0.6.35) held
unpushed until this merges - captain sequences.
…e 1.x 'cyclic' The x64-default CI leg failed on grep_R_warns_and_terminates_on_ junction_cycle: it still expected the 1.x wording "cyclic" while the rust2 walk emits GNU grep 3.11's "warning: recursive directory loop" (walk.rs FTS_DC detection; WSL oracle probe ln -s to self attests the exact line, comment updated with the probe). The mismatch was invisible locally: create_directory_symlink_or_skip early-returns on hosts without symlink privilege (this dev machine), so the test scored green here with zero assertions while the CI runner — which HAS the privilege — ran it for real. Same split that the checkpoint's rust-tests lesson recorded; the other symlink grep test (r skips cross-junction trees) asserts stdout shape only and matches GNU as-is.
caomengxuan666
force-pushed
the
rust2/grep-wire
branch
from
November 14, 2026 11:02
d90bdc6 to
3e09851
Compare
caomengxuan666
marked this pull request as ready for review
November 14, 2026 11:07
This was referenced Nov 14, 2026
This was referenced Nov 15, 2026
aphrody-dev
pushed a commit
to aphrody-labs/WinuxCmd
that referenced
this pull request
Nov 20, 2026
The inventory still called six commands c++-only after their rust2 library/wire landed. Rows now say state=wired, status=rust2-wired, engine=rust2, with commit evidence in the anchor: - ls: unixwin#1762 library 3025942; f87be22 wire (this branch) - rm: unixwin#1751 library 38e6835; f14bc60 wire (this branch) - find: unixwin#1634 library; 792c31f (unixwin#1696 wire); unixwin#1633/unixwin#1658 help/version - grep: unixwin#1660 library; 0eb0d28 (unixwin#1660 wire); -P face stayed on the C++ PCRE2 path per DOCS/2.0-regex-engine-decision.md - mv: unixwin#1649; a0cfcd7 (unixwin#1773 reland that wired the 1.x retirement) - sed: unixwin#1635 library; f36f306 (unixwin#1690 wire) No code changes; loc/oracle/test columns are historical measurements and stay as recorded.
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.
Stacks the grep library (#1631, included) with the product-path wire. Supersedes #1631 on merge.
Wire shape
winuxcmd_grep_uses_perl(additive; ABI version stays 2); bridge export; the grep handler splits on it — non-Perl → rust2 streaming reader,-P→ the retained C++ PCRE2 face; egrep/fgrep route unconditionally (upstream wrappers areexec grep -E/-F;egrep -Pis a matcher conflict rc 2, never Perl — the 1.x body running Perl there was a standing oracle deviation, retired)Wiring surfaced two product fixes (in this series)
beg > bufbegboundary — saturating -B/-C hung the Rust side where gcc dead-loop-eliminates (ctest [xargs] -I keeps leading blanks; -t trace not quoted; -E with -0/-d warns in GNU only; --show-limits prints to stderr then still runs the command #1322);;Verification (evidence: rust2/target/wire-i18n/): gate 162 rows green (r=c:no deltas all classified, zero new); ctest grep-family failure set == pre-wire baseline; 60×3 old-exe byte matrix classified (one walk.rs empty-operand gap recorded, grep-impl scope, unfixed here); -P split smoke 10/10 byte-equal; default+full editions build; lib tests 752/0 (incl. the #1659 Ctx::new migration, rebased).
Expected CI: i18n-drift may report grep message-face keys until the tr! migration commit lands on this branch (in progress — checkpoint I18N prerequisite). Compile/test legs should be green.