Skip to content

rust2(find): GNU findutils 4.9 find library port + 317-row gate (#1488) - #1634

Closed
caomengxuan666 wants to merge 4 commits into
mainfrom
rust2/find-impl
Closed

caomengxuan666 wants to merge 4 commits into
mainfrom
rust2/find-impl

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Library landing for the find big-ticket lane (5072 lines, 9 modules) + review-wave gate additions. C++ body retirement / dispatch wiring follows at wire time.

Scope (semantic checklist all-green vs findutils 4.9):

  • Expression grammar with GNU diagnostics at the same token (fd051-058); DEP loose parsing incl. artificial wrapping + implied -print
  • Position-sensitive options (-follow runtime-global attested, -daystart via parse-time reft capture) vs global options with post-test warnings (fd344/345)
  • Actions: print family, exec family (; and {} +, per-dir batching, 32767 UTF-16 cap - 2048 headroom), -delete/-prune/-quit semantics
  • Tests: fnmatch -name/-path family, -regex all 12 dialects + leading-.* split (self-attesting equivalence test), -type/-xtype, -size, time family incl. decimals/-daystart/-newerXY, -perm (incl. GNU 4.9's invalid '+644'), -links/-inum/-user/-group/-samefile/-fstype/-readable...
  • Windows face: 24-entry DOS device table via resolve_pseudo_device, /mnt/X + /cygdrive/X folding per niubash#346 boundary, junction/reparse as -type l with -P/-L/-H semantics, perm value model shared with stat/ls

Evidence: gate 317 rows = 307 GNU-gated PASS / 0 FAIL + 10 win PASS / 0 FAIL (13 review rows probe-attested before entry); cargo test find 24/0. fd362 (-fprint /dev/stdout) documented as harness-transport-only, to be pinned by a unit test at wire time.

Known deviations (declared): warnings default OFF (injected-IO contract; -warn enables), -D debug flags accepted without GNU's diagnostic streams, -execdir insecure-PATH check skipped, -exec {} + Windows command-line cap, %B/-newerB* uses creation time, -type b accepted but never produced.

Expected CI status: i18n-drift will report keys until the wire commit lands tr! keys (checkpoint I18N prerequisite — find's message face is currently hardcoded English). Compile/test legs should be green.

Cross-lane note: #1617 precedence deviation of the C++ pre-scan tracked in #1633; rust2's sequential predicate-table parse is the authoritative semantics.

caomengxuan666 and others added 4 commits November 14, 2026 12:42
… awk family) (#1488)

Adds winux_regex::dialect: the 13 findutils -regextype syntax families
(lib/regextype.c order) rewritten onto the native grep BRE/ERE pair.
emacs (the GNU find default) keeps \( \| groups, bare + ? operators,
literal ( ) | { }, no intervals, no char classes; posix-basic/ed/sed
reject dup-after-dup; posix-extended/posix-awk reject a leading
operator; the awk family escapes inside brackets. Every rule pinned
against find 4.9.0 probes; glibc_message() renders REG_* wording.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Library-form find over the Windows value model:

* parse: leading -H -L -P -D -O, start points, GNU's flat predicate
  list (implicit -a, global options as no-op primaries, artificial
  "( ... ) -print" wrapping) folded by the tree.c get_expr/scan_rest
  algorithm, so every GNU diagnostic fires at the same token;
* every test/action of 4.9: -name/-path/-lname (+i) fnmatch, -regex
  through winux_regex::dialect (emacs default, all 13 -regextype),
  -type/-xtype lists, -size rounding, -empty, -mtime/-mmin/-used/
  -daystart/-newer/-newerXY (dates via touch's parse_datetime), -perm
  (modemap), -user/-group/-uid/-gid/-nouser/-nogroup, -readable/
  -writable/-executable, -links/-inum/-samefile/-fstype, -print/-print0/
  -printf (print.c port, all directives and quirks)/-fprint*/-ls/-fls,
  -prune/-quit/-delete, -exec/-execdir/-ok/-okdir with {} + batching;
* lazy iterative walk (one FindFirstFileExW handle per level, no tree
  materialization; enumeration records answer the cheap predicates, a
  handle open only for ctime/nlink/ino/dev/alloc), junctions and
  symlinks are links, -L loop detection, -xdev, post-order for
  -depth/-delete;
* children launch through childproc (resolve_child +
  build_child_command, inherited stdio, stdout flushed first).

touch::parse_datetime becomes pub(crate) for -newermt; winux-cmds gains
the in-workspace winux-regex path dependency (no crates.io deps).

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
`.*TAIL` whole-matches a path iff TAIL whole-matches a suffix that
starts on a codepoint boundary. The split is taken only when exact (no
top-level alternation, no quantified .*, no left-context token in
TAIL, no newline in the path) and turns one state-per-position
interpreter run into a few first-byte-filtered suffix attempts:
200k-entry tree `-regex '.*/f0[0-4][0-9]\.rs'` 7.77 s -> 0.92 s (C++
1.x find 5.70 s). rx tests pin split == full-match on a mixed corpus.

Also pins two test expectations to the GNU probes (printf %o flag
string; an unrunnable `;` command is a false test with rc 0).

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…#1488)

Review-lane additions on top of the find library port:
- find.tsv: 317 rows total (was 304); fd350-363 add the dangling-link
  family (-H/-L dangling starts, -L -type l, %Y='N', -delete on the
  link), -path start matching, -iname bracket-class case folding,
  -perm -000, -ok Y prompt, -exec {} + with no matches, multi-root
  -quit, multi-letter -type with links. Every row probe-attested
  against WSL findutils 4.9 before entry (scratch/find-review/).
- fd362 (-fprint /dev/stdout) deliberately omitted: the gate host
  rewrites the literal in native-child argv (CONOUT$) — a harness
  transport boundary, not a find semantics bug; open_file's special
  case is correct. Pin via a unit test at wire time (comment left in
  gen-cases.py).
- gen-cases.py: find_rows + find table registration + a sorted-
  comparison mode for the diagnostic rows (GNU reorders adjacent
  stdout/stderr lines).
- run-gate.sh: +16 lines harness fix; lib.rs registers find.

Gate: 317 rows = 183 strict + 119 sorted + 4 exit + 10 win + 1 note;
GNU-gated 307 PASS / 0 FAIL, win-gated 10 PASS / 0 FAIL.
cargo test -p winux-cmds find: 24/0.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Review verdict: FAIL (F1 — blocking)

PR #1634 (head 1fcf555a, base b781ff35) cannot merge on this head: the -used formula is sign-flipped vs GNU.

F1 — -used windows are the mirror image of GNU's

The code (parse.rs "used" arm + expr.rs Prim::Used) stores reft = -N·86400e9 (reft = -((n * 86_400.0 * 1e9) as i128)) and evaluates window(d - reft, cmp, 86400e9) with d = atime − ctime. Effective windows (days):

  • plain N → d ∈ [−N, −(N−1)); plain 0 → [0, 1); −N → d > −N; +N → d < −N.

GNU findutils 4.9, probed by the reviewer locally (two matrices + the d==0 boundary case, files with atime set to exact offsets from ctime, d verified in ns):

  • plain N≥1 → (N−1, N] (d==0 matches N=1); plain 0 → never matches, even d==0; −N → [0, N]; +N → d > N.

Key data points: -used 1 matches d=+0.5 but not +1.5; -used +0 matches all positive d; -used 0 matches nothing; a fresh file (atime_ns == ctime_ns exactly) matches -used 1/-1/-2 but not 0/+0. The code's windows are the mirror image — +0 is the exact opposite (code: d<0; GNU: d>0). I confirmed the sign-flipped reft and the window(d - reft, …) evaluation in the diff myself.

Why the gate missed it: the only -used row, fd220 (t -type f -used -1), has fixture d values ≈0 (fresh files) and ≈−2509d (touched 2020 files) — both formulas agree there (both print the 4 fresh files). No unit test covers -used (0 hits in tests.rs). The divergence is entirely uncaught by the PR's evidence.

Rework spec (focused)

  1. Fix the formula to GNU's windows above, preserving the d==0 edge.
  2. Add discriminating gate rows (d=+0.5, +1.5, −0.5 via future/past touch -d on atime) under -used -1/1/0/+0/+1, at minimum extending fd220 so it fails on the current formula.
  3. Re-run the full gate + 24 unit tests + CI on the new head; the focused re-review judges only the -used fix and the new rows.

Note the PR is conflicting vs the current tip (lib.rs registry tail — the PR adds find, tip's #1625 adds xargs at the same spot; resolution is mechanical, keep both). Resolve it as part of the rework.

What verified PASS-grade

  • Gate table verified on disk (correct path rust2/gate/cases/find.tsv): 317 rows = 183 strict + 119 sorted + 4 exit + 1 note + 10 win. fd362 absent by design (dropped with recorded reason in gen-cases.py:4020 — niubash rewrites /dev/stdout to CONOUT$). The note row fd219 is record-only.
  • CI head (run 43571432854): the sole red is i18n-drift, and it is transient, not caused by this PR — I verified the timeline myself: the single drift line is command.echo.option.repeat (echo.cpp:31); the i18n repo dropped that key at 07:19:52Z (commit 627738bc, "drop orphan echo repeat key retired by WinuxCmd#1621"), before the PR-head drift job started at 07:31:31Z and after the base run passed; the PR's diff contains zero occurrences of the key; base and tip both pass i18n-drift. All other checks pass (rust-tests, oracle, baseline, baseline-growth, compare, build-windows ×4, rust2-surface-check).
  • Unit tests verified from the CI log (not the lane's word): rust-tests 726 passed / 0 failed; all 24 find:: tests ok by name.
  • Mechanism read end-to-end (all 5072 lines): parse (precedence climbing, GNU diagnostics verbatim, -newerXY, -perm +644 quirk, -type errors), eval (-quit short-circuit verified against GNU probes, -xtype, -size div_ceil, -delete/-prune), exec (32767−2048 batch cap, per-dir batching, -ok prompt), rx (leading-.* split with exactness guards + self-attesting test), printf (%Z getfilecon error, %S, -ls 6-month rule), 13 dialects, DOS devices, junctions as links, cycle detection, perm model. Other time predicates formula-checked against GNU (only -used is wrong).
  • Merge vs tip 8be156e: exactly one text conflict — lib.rs registry tail (mechanical, keep both). touch.rs / winux-regex lib.rs merge clean; i18n.rs is tip-only new file. No file overlap with fix(find): let --help/--version act where the expression parser reaches them (Refs #1633) #1658 (head 942af22) or rust2(i18n): batch-1 — tr! keys for the 8 small wired commands + Ctx host seam (#1488) #1636.

W findings (non-blocking)

  • W1: -O level validated but discarded — no cost-based reordering; undisclosed in the body (disclose one line at rework, or file a follow-up).
  • W2: the body's "i18n-drift will report keys until the wire commit lands tr! keys" is inaccurate in detail (see the transient analysis above).
  • W3: -fprint /dev/stdout special case (parse.rs:554) unpinned by any test — wire-time owed.
  • W4: -type s also never-produced, body lists only b.
  • W5: run-gate.sh header omits note mode.
  • W6: merge round must resolve the lib.rs conflict and re-verify on the merged shape (registry differs from the reviewed head).

Merge notes

Do not merge on this head. On eventual merge: Refs #1488 only (library landing; #1488 stays open until wire time).

@caomengxuan666

Copy link
Copy Markdown
Member Author

Library landed on main via #1696 (find wire).

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.
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