Skip to content

#1488 winux-regex fast-path - #1615

Merged
caomengxuan666 merged 3 commits into
mainfrom
rust2/regex-fastpath
Nov 13, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
rust2/regex-fastpath

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

What

Ports the #1531-class literal pre-filter (C++ precedent: src/utils/regex.cppm Pattern::fast_ / build_fast_path, kwset/dfa "must"-analysis style) to the rust2 winux-regex engine. Four compile-time necessary conditions, all computed from the same parsed node tree the interpreter runs — no text-layer re-lexing (#117):

  1. anchored — first consumable element is ^ → single attempt at position 0 (none when start > 0).
  2. prefix — required literal prefix (Literal runs, single-member classes, {m} literal expansions, zero-width assertions transparent) → memchr-style candidate jumps; the interpreter still validates every candidate through the unchanged local_attempt path.
  3. first — 256-byte first-byte set, expanded per byte through the engine's own class_matches/fold rule (hoisted to a pub(crate) free fn so the sets cannot drift from the matcher); legacy advance rule kept, only futile attempts skipped.
  4. pure_literal — whole tree Literal-only, no captures → a prefix candidate IS the match.

Unmodeled shapes fall back to the legacy scan; a continuation-range prefix first byte is rejected in build (candidates would sit on positions the legacy traversal never attempts — the regex.cppm rule). Necessary conditions only, no semantic fork (#1550 lesson). New code: rust2/crates/winux-regex/src/fastpath.rs; integration: checked_find_at_bytes / checked_match_at_bytes / matches_entire_bytes (find_all derives). Filters sit behind the default fast-path cargo feature plus a #[doc(hidden)] disable_fast_path() knob for A/B.

Correctness (all gates green)

  • #1488 winux-regex Phase 1-3 #1603 138-row GNU grep -o matrix: byte-identical to the pre-change baseline — verified with examples/matrix_harness in BOTH modes (feature on / --no-default-features), cmp clean against output captured before the change.
  • Full existing suite (23 tests) passes in both modes.
  • New tests/fastpath_equiv.rs: per-tier hand corpus (UTF-8/continuation traps, -i folding, raw bytes, caps) + 120k-case deterministic fuzz — fast vs disable_fast_path must agree byte-for-byte across checked_find_at_bytes / checked_match_at_bytes (every start offset) / find_all_bytes / matches_entire_bytes, WorkLimit included. Tier engagement itself pinned by fastpath.rs unit tests.

Performance (examples/fastpath_bench, release, 47 MiB / 819k lines — the #1531 shape)

workload interpreter fast path speedup
grep -c fox (prefix/pure-literal tier) 9.713 s 57.979 ms 167x
grep -c (f|F)(o|O)(x|X) (first tier) 16.726 s 405 ms 41x
.{2}fox fallback control 8.749 s 8.657 s ~1% (noise; identical legacy scan)
pathological (.*)*b 4096-byte line 75.6 s (WorkLimit) 78.1 s (WorkLimit) unchanged
pathological \(.*\)*b 4096-byte line 80.4 s (WorkLimit) 78.7 s (WorkLimit) unchanged

Counts match in every pair. The #1603 triple caps (StepBudget / visited / output) are untouched and still bound the pathological family; dot-head patterns keep the filter OFF by construction, so those numbers are structurally the same code in both modes.

Refs #1488, #1531, #1603. Lesson applied: #1550 (necessary conditions only), #117 (no text-layer fast path).

…st (winx#1488, #1531)

Port of the C++ engine's compile-time prefilters (regex.cppm
Pattern::fast_ / build_fast_path — the kwset/dfa "must" analysis
precedent of #1531) to rust2/crates/winux-regex:

- anchored: first consumable element is `^` -> single attempt at 0,
  none when start > 0 (AnchorStart compares absolute positions).
- prefix: required literal prefix (Literal runs, single-member classes,
  {m} literal expansions, zero-width assertions transparent) ->
  memchr-style candidate jumps; the interpreter still validates every
  candidate through the unchanged local_attempt path.
- first: 256-byte first-byte set expanded per byte through the engine's
  own class_matches/fold rule (single source of truth, matcher's rule
  hoisted to a pub(crate) fn); legacy advance rule kept, only the
  futile attempts are skipped.
- pure_literal: whole tree Literal-only with no captures -> a prefix
  candidate IS the match, byte-for-byte the interpreter's result.
- Unmodeled shapes fall back to the legacy scan; a continuation-range
  prefix first byte is rejected in build (candidates would sit on
  positions the legacy traversal never attempts). Necessary conditions
  only — no semantic fork (#1550 lesson).

Correctness gates: the #1603 138-row GNU grep -o matrix is byte-identical
to the pre-change baseline in BOTH feature modes; new
tests/fastpath_equiv.rs (hand corpus per tier + 120k-seed deterministic
fuzz) requires fast vs disable_fast_path equality across checked_find /
checked_match / find_all / matches_entire, WorkLimit surfaced identically.
The filters live behind the default `fast-path` feature plus a
doc(hidden) disable_fast_path() knob for A/B diffing.

Performance (47 MiB / 819k lines, release, #1531 shape): grep -c fox
9.713s -> 57.979ms (167x); first-tier (f|F)(o|O)(x|X) 16.726s ->
405ms (41x); dot-head fallback control unchanged (~1% noise);
pathological (.*)*b and \(.*\)*b long lines stay WorkLimit-bounded in
both modes (75-80s, unchanged) — the #1603 caps are untouched.
…robust unit tests (Refs #1602)

The rust-tests job (added in d2ee03f) is the first CI surface where
symlinks can actually be created (hosted runneradmin has the symlink
privilege; dev hosts soft-skip the guarded tests), so five winux-cmds
lib tests failed there while passing locally:

- fs_win::create_symlink absolutized the symlink TARGET through api_path
  (ctx.cwd.join), baking an absolute path into the reparse point where
  GNU symlink(2) and the 1.x pipeline (src/utils/win32.cppm
  win32_normalize_symlink_target: '/'->'\' only, "store the user-visible
  link text unchanged") keep the given text verbatim. ln -s tgt sl then
  failed readlink == "tgt" on CI. The LINK operand keeps api_path.
- fs_win::file_meta's CreateFileW path missed the lstat symlink size
  fixup (st_size = target-path byte length; #1310 contract, already
  present in the find_first_meta fallback), so stat %s on a symlink
  reported 0 instead of len(target) on NTFS reparse points.
- canon dangling test asserted !r.contains("dang") but the scratch dir
  itself is named canon-dang-*, tripping the check on symlink-capable
  hosts; now checks the link name per path component only.
- chown from_filter hardcoded --from Administrators for the no-match
  case, but elevated hosts (CI runner) create files owned by the
  Administrators group, so it matched and -v printed; the no-match
  account is now picked against the actual owner name.
- nice no_command_prints_niceness assumed the process runs at NORMAL;
  hosted runners spawn processes BELOW_NORMAL and children inherit the
  class (actions/runner-images#7663), so nice correctly printed 10; the
  test now normalizes its own priority class first.

Verification: cargo test --locked -p winux-cmds --lib 577 passed on the
branch tip (dev host, symlink-guarded tests soft-skip); CI rust-tests is
the oracle for the symlink-capable path.
…efs #1602)

Follow-up to 2ad7639: the verbatim-target change kept the drive-dialect
fold out of the reparse point, breaking ctest
ln.ln_symlink_drive_dialect_lands_on_operand_drive — "ln -s /c/Users/...
link" stored the literal POSIX spelling, which no Windows path resolution
can follow (a leading "/" resolves against the current drive root), so
reading through the link returned empty.

create_symlink now folds the target through
winux_core::path::normalize_operand before the '/'->'\' reparse fold
(#1101): the drive-dialect fold maps "/c/x" to "C:\x" (lands on the
operand drive), shell-tree spellings map through the env, and relative
plus already-native spellings are identity, so they keep the GNU-verbatim
text. The LINK operand keeps api_path.

Verification: cargo test --locked -p winux-cmds --lib 577 passed; the
ctest expectation is CI-covered (symlink privilege).
@caomengxuan666
caomengxuan666 merged commit f2edba0 into main Nov 13, 2026
14 of 15 checks passed
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…xwin#1607

The behavioral fix (per-component link-name check instead of a
contains("dang") substring assert, which matched the canon-dang-*
scratch dir itself) already landed on master via 2ad7639
(PR unixwin#1615); the issue stayed open because nothing referenced it.
Pins the tracker link on the owning test. No behavior change.
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…xwin#1608

The behavioral fix (pick the no-match --from account against the
actual file owner instead of hardcoding Administrators, which owns
the files on elevated CI runners) already landed via 2ad7639
(PR unixwin#1615); pins the tracker link on the owning test. No behavior
change.
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…win#1609

The behavioral fix (TARGET keeps the operand text verbatim through
normalize_operand + the '/'->'\' reparse fold — identity for
relative spellings, drive-dialect fold for /c/x — while the LINK
operand keeps api_path) already landed via 2ad7639 + 305b056
(PR unixwin#1615); pins the tracker link on the owning function. No
behavior change. The -r path (ln.rs relative_target -> create_symlink)
is covered by the ln relative_requires_symbolic -rs probe, which
runs privileged on CI rust-tests (green on master).
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…in#1610

The behavioral fix (SetPriorityClass(NORMAL) before asserting the
niceness, since hosted runners spawn BELOW_NORMAL and children
inherit the class) already landed via 2ad7639 (PR unixwin#1615); pins the
tracker link on the owning test. No behavior change.
aphrody-labs Bot pushed a commit to aphrody-labs/WinuxCmd that referenced this pull request Nov 15, 2026
…unixwin#1611

The behavioral fix (stat %s on a symlink = target-path byte length
on the CreateFileW main path; the find_first_meta fallback already
had it) already landed via 2ad7639 (PR unixwin#1615); pins the tracker
link on the owning function. No behavior change.
@caomengxuan666
caomengxuan666 deleted the rust2/regex-fastpath branch November 18, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant