Repository navigation
2.0 机械替换打样: true/false 接线 rust2 staticlib 并删除 C++ 实现 (#1488) - #1550
Merged
Merged
Conversation
…1488) GNU coreutils true.c recognizes --help/--version only when argc == 2 and keeps EXIT_STATUS afterwards, so `false --help` prints and exits 1 while `true --help x` is a silent success. The wave1 pilot scanned every argument and returned 0 after printing, which the gate never caught because those rows were classified `note`. Probe (WSL coreutils 9.4): false --help -> rc 1 + text; true x --help -> rc 0, no output; POSIXLY_CORRECT=1 true --help still prints. - truefalse.rs: sole-argument rule, status kept; 2 new unit tests - gen-cases.py: t06/t14/f06/f14 -> strict, f07 -> win (branded text) - run-gate.sh: derive the WSL tree path from the checkout instead of the hard-coded /mnt/d/repo/wc-20rust (gate ran GNU-less elsewhere) - GATE-REPORT.md: true/false rows re-measured, 38 GNU-gated + 2 win green This is the wiring wave's precondition: winuxcmd.exe now runs this function for true/false.
First mechanical replacement of the 2.0 command-library track: winuxcmd.exe now runs rust2's truefalse.rs for `true`/`false`; the C++ implementation is deleted (no dual track). Link shape: staticlib, not cdylib. #1487/niubash#727 traced the FFI damage to the DLL boundary (load-time CRT stdio binding); a staticlib is folded into winuxcmd.exe by the same link - one image, one CRT. winuxcmd-ffi now builds both crate types from one ABI source; Rust is compiled with +crt-static so the archive asks for libcmt, matching USE_STATIC_CRT (/MT). - CMakeLists.txt: WINUXCMD_ENABLE_RUST2 (default ON iff cargo is found; explicit ON without cargo is a configure error), WINUXCMD_RUST2_COMMANDS list, `cargo rustc --release --locked --crate-type staticlib` custom command with CARGO_TARGET_DIR=<build>/rust2-target, imported static lib with the rustc-reported native libs. OFF filters out the replaced commands and the bridge: a machine without Rust still builds, without true/false. - src/shared/rust2_abi.h: C mirror of the winuxcmd_run ABI (v1). - src/bridge/rust2_bridge.cppm: module rust2_bridge, run_command(): env and cwd snapshot via Win32 (no throwing calls; no /EHsc here), stdout/ stderr drained through the console layer. stdin is not forwarded (ABI v1 is buffer-only), so only non-stdin commands may use it. - src/commands/true.cpp, false.cpp: registration metadata unchanged (the dispatcher's branded sole --help/--version stays shared); handler body is `return winux::rust2::run_command(name, ctx.raw_args);`. Gates (Debug build-vs, WSL coreutils 9.4 oracle): - GNU oracle, 22-case matrix x2: rc 44/44, stderr 44/44, stdout 34/44 (the 10 rows are sole --help/--version: branded text, identical to 1.x); rust2/gate/run-gate.sh with RUST_BIN=<new exe>: 38 strict + 2 win green. - ctest: 3830 tests, failing set identical before/after (20, none true/false related); true_cmd/false_cmd 10/10; differential corpus true/false 4/4 on old and new exe. - old exe vs new exe: rc/stdout/stderr 44/44/44 (also on a Release/unity /LTCG build); run-gate r=c 40/40. - no-cargo machine (cargo hidden): configures OFF, builds, runs.
REPLACEMENT-RECIPE.md distills the first real replacement into reusable steps: the fixed decisions (staticlib + crt-static, ABI v1, what stays C++), the per-command procedure (baseline capture, Rust-side gate refresh, the one-line handler rewrite, CMake list append), the three gates and how to run them with the existing harness (RUST_BIN/CPP_BIN pointing at the product exe), and the pitfalls met on the way (note rows hiding pilot divergence, argv[0] multicall naming, probe-loop stdin loss, WSL env forwarding, the #1412 pre-include vs clang-format, /EHsc-less bridge code, no-Rust configure simulation). gate/wire/ holds the wiring-wave matrix probe (22 cases x true/false, rc/stdout/stderr) and the comparator; README.md and GATE-REPORT.md updated (true/false rows re-measured: 19 strict + 1 win each, C++ parity 19/20).
This was referenced Nov 9, 2026
Closed
Merged
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
note rows are record-only and never gate; that made them a blind spot. The `false --help` pilot bug (#1550) lived inside a note row until manual wiring checks caught it. This tool ends indefinite immunity: 1. inventory — every note-mode row with its expected-deviation claim from gate/note-registry.tsv (undocumented notes are a finding). 2. GNU re-check — each note case re-run against GNU (WSL), Rust, C++; verdicts: UPGRADE-STRICT Rust byte-matches GNU; the row can gate again (C++ divergence stays recorded via r=c:no) UPGRADE-EXIT rc matches GNU, stdout platform-form-bound MASKED-DIVERGENCE the note hides a live Rust-vs-GNU divergence — the exact #1550 class 3. upgrade-candidate list — promotion decisions owned by the command lane; this sweep only reports. First sweep (df wave1, real data): - df/df12-output-subset — UPGRADE-STRICT candidate (Rust rc+stdout byte-match GNU; C++ deviation inherited-not-fixed) - df/df13-drive-path — MASKED-DIVERGENCE: GNU rc=1 (no such file under WSL), Rust rc=0 prints a filesystem table (registered deviation: Rust follows the C++ drive model). Command lane must fix or re-justify; the registry claim documents it, the probe keeps it visible. Exit 1 when masked divergences exist (CI-wireable). Refs #1488, #1550.
aphrody-labs Bot
pushed a commit
to aphrody-labs/WinuxCmd
that referenced
this pull request
Nov 15, 2026
…st (winx#1488, unixwin#1531) Port of the C++ engine's compile-time prefilters (regex.cppm Pattern::fast_ / build_fast_path — the kwset/dfa "must" analysis precedent of unixwin#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 (unixwin#1550 lesson). Correctness gates: the unixwin#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, unixwin#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 unixwin#1603 caps are untouched.
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.
#1488 的第一次真实机械替换打样:
true+false从 C++ 实现换成 rust2 库实现,链进 winuxcmd.exe,C++ 旧实现同 PR 删除(不双轨)。配方沉淀在rust2/REPLACEMENT-RECIPE.md,下一个命令照做。决策
winuxcmd-ffi同一 ABI 源出两种 crate-type(cdylib 留给宿主实验)。/defaultlib:msvcrt(/MD),winuxcmd 是 /MT。Rust 侧加-C target-feature=+crt-static后归档要的是libcmt;链接零 LNK4098。USE_STATIC_CRT=OFF时自动去掉该 flag。REGISTER_COMMAND注册(help/man/补全元数据)和调度器共用的前置机制(唯一参数--help/--version拦截、改写钩子、选项策略);handler 体换成一行 Rust 调用。产品的 help/version 文本是全部 176 个 applet 共享的 WinuxCmd 品牌格式,逐命令搬走会破坏门 c 并分叉 help 体系。改动(3 个 commit,一事一 commit)
rust2(true/false):接线前的 Oracle 复核发现 pilot 本身偏离 GNU。true.c 只在argc == 2时认--help/--version,并保持 EXIT_STATUS(false --help打印后仍 rc 1);pilot 却是任意位置都认,而且返回 0。这些行当时被分类为note,从不进门。修正为唯一参数规则,新增 2 个单测(55/55 绿);t06/t14/f06/f14 升为strict,f07 改为win。run-gate.sh的TREE_MNT原先硬编码成wc-20rust,换个工作树 GNU 侧就静默 MISSING,现改为从 checkout 推导。CMakeLists.txt:WINUXCMD_ENABLE_RUST2开关(检测到 cargo 才默认 ON;显式 ON 但没有 cargo 时配置期报错);WINUXCMD_RUST2_COMMANDS清单;custom command 执行cargo rustc --release --locked --crate-type staticlib,CARGO_TARGET_DIR=<build>/rust2-target(不污染rust2/target);imported lib 加上 rustc 报告的 native libs。src/shared/rust2_abi.h(ABI v1 的 C 镜像)和src/bridge/rust2_bridge.cppm(modulerust2_bridge:用 Win32 取 env/cwd 快照,不抛异常,输出经 console 层出口)。true.cpp/false.cpp的 handler 改为return winux::rust2::run_command(name, ctx.raw_args);。rust2/REPLACEMENT-RECIPE.md;wiring 矩阵探针rust2/gate/wire/;README 指针。未装 Rust 的机器
隐藏 cargo(PATH、
CARGO_HOME、USERPROFILE\.cargo\bin)后实测:配置自动设为 OFF,winuxcmd.exe构建成功、可运行;true/false不随包发布(command not found)。这是"换完即弃、不双轨"的代价:没有 C++ 兜底体。CI/打包机需要装 Rust 工具链。三重门账本(Debug build-vs;Oracle = WSL coreutils 9.4;rebase 到 c9ed2a1 之后复跑)
-h、唯一--help/--version、带多余操作数的 help/version、非法长/短选项、--、-、---、--help=x、stdin、POSIXLY_CORRECT…)--help/--version的品牌文本,与 1.x 逐字节相同,rc 仍对齐 GNUrun-gate.sh true false,RUST_BIN=新 exe体积:Debug winuxcmd.exe 增大 1.0 MB(Rust std,一次性成本,后续命令共享)。
遗留(已写入配方 §5)
safePrint,后者会对整串做translate_legacy目录查找。true/false 没有输出,不受影响;要打印数据的命令(basename/dirname/printenv…)接线前,先在 console 层加一个不翻译的原样写出口。备注
本机 git 到 github.com 的传输不通(本地代理 127.0.0.1:65532 拒绝连接),分支是经 GitHub Git Data API 重放推上来的。每个 blob/tree/commit 的 SHA 都与本地逐一核对一致(HEAD
5aba132f)。