Skip to content

WIP: redundancy cleanup B+C — dead machinery removal and copy convergence - #1429

Merged
caomengxuan666 merged 9 commits into
mainfrom
clean/winx-redundancy
Oct 28, 2026
Merged

caomengxuan666 merged 9 commits into
mainfrom
clean/winx-redundancy

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Redundancy cleanup from the 2026-10-28 three-repo redundancy audit (WinuxCmd REPORT items R1–R6), classes B (dead machinery) + C (hand-copied duplicates), user-ruled for construction on 2026-10-28. Freeze exception by the user's direct order. Draft — not to be merged from the cluster side; the merge gate is this PR's Windows CI, now green (see CI accounting).

One commit per item. Net: +175 / −489 across 15 files (plus the B1b example removal).

B1 — container:constexpr_map deleted (audit R3)

171-line exported template (ConstexprMap, make_constexpr_map); repo-wide grep over src/ + tests/ found zero instantiations outside the definition file and the container.cppm aggregator (contrast small_vector: dozens of consumers). Removed: the partition file, its export import line, and its entry in the per-command executable source list (the winuxcmd-commands target globs src/**/*.cppm, no list edit needed there).

Correction to the audit premise, caught by CI: the audit's "zero consumers" scope was src/ + tests/. examples/container/constexpr_map_example.cpp did instantiate it and examples/container/CMakeLists.txt compiled the partition — first CI run failed at configure on exactly that. The example exists solely to demonstrate the template, i.e. it is part of the dead apparatus rather than a consumer of it (same shape as a dead feature kept alive only by its own tests). Removed together with its subject in commit B1b; full-tree grep for ConstexprMap|constexpr_map|make_constexpr_map is now zero hits.

B2 — dir/vdir external-spawn ls fallback deleted (audit R2)

Each file carried ~65 lines of fallback behind !CommandRegistry::hasCommand("ls"): command-line quoting builder + resolve_child_command execvp-semantics resolution + CreateProcessW of an external ls.exe.

Unreachability evidence chain, re-verified at this tip (d28a920):

  • The only multiplexer image is winuxcmd.exe, linking winuxcmd-commands, built from a glob of all src/commands/*.cpp (CMakeLists.txt:386, 412) — ls.cpp's REGISTER_COMMAND is always in the same image as dir/vdir.
  • The per-command standalone-executable macro that could have produced a split-applet dir.exe (create_command_executable, CMakeLists.txt:564) is defined but never invoked.
  • Shipped layouts (usr\bin hardlinks, wpm shim layout) all run that same multiplexer image.

Reachable behaviour unchanged (the in-process dispatch path is untouched); the unreachable branch keeps the fallback's failure shape (dir: failed to execute ls, exit 1) minus the spawn machinery.

C1 — literal-argument command table: one source of truth (audit R1)

The 8-name set {echo, yes, test, [, true, false, printf, expr} was hand-copied in src/Main/main.cpp (top-level --version pre-scan) and src/core/dispatcher.cppm (abbreviation-expansion exclusion), synced only by a comment; it already drifted once (#1215: main's copy missed expr). core:dispatcher now owns the table behind the exported is_literal_arg_command(); both consumers call it. Post-change grep: kLiteralArgCommands exists exactly once in the tree.

Before/after, same input (code walk): the two tables were byte-identical at convergence time, so winuxcmd expr 1 --version, winuxcmd printf '%s\n' --version, expr --hel etc. take the same branches before and after — now by construction rather than by copy discipline. Corroboration: full ctest + GNU master differential both green (below).

C2 — diff family: one raw-args helper, no more re-parsing the process command line (audit R5)

diff's diff_command_tail(), diff3's and sdiff's last_raw_argument() lambdas (the latter two verbatim duplicates) each re-ran CommandLineToArgvW(GetCommandLineW()) to rebuild operand text — although the dispatcher already parsed the same command line and hands it to every command as ctx.raw_args, with argv[0] and the multiplexer verb token already dropped (exactly the tokens the three copies dropped by hand).

One shared implementation now lives in diff_engine.h (already included by all three): command_tail_from_raw_args and last_raw_argument, computed from the raw_args span. CommandLineToArgvW no longer appears in any of the three files.

Before/after, same inputs (code walk): winuxcmd diff -r a b → old tail tokens [−r, a, b] after hand-dropping the verb, new tail from raw_args [−r, a, b] → identical "diff -r a b"; diff3 x (missing operand) → old last token x, new raw_args.back() = x; empty-args → program name in both. Side benefit: under a host process (FFI DLL form) the old code read the host's command line; the new code reads the command's own arguments. The two helpers were also extracted verbatim from the header and logic-tested under g++ (−Wall −Wextra −Werror): tail join, empty-args, last-arg and fallback cases all pass.

C3 — utils:path dead exports deleted (audit R4)

Per-function consumer grep over src/ + tests/ (qualified path:: calls; no using namespace path exists anywhere in the tree):

  • Zero call sites (24 of 25 exports, deleted): normalize_path, get_parent_path, get_filename, get_stem, get_extension, exists, is_directory, is_regular_file, create_directory, create_directories, current_path, current_path_w, get_executable_path, join (both overloads each where present).
  • Sole live export (kept): get_executable_name — src/Main/main.cpp:514.

The tree had already voted with its feet: applets call native_path:: directly (normalize_api_operand / make_api_path_operand alone have 250+ call sites). Any caller of a removed name would fail to compile; the grep is the proof there are none. The partition remains as a one-function shell (full retirement — folding get_executable_name into native_path — is a possible follow-up, out of this batch's scope).

C4 — argv adapter table: one shared header (audit R6) — and a third copy the audit missed

The awk/gawk → -v BINMODE=3 rule (niubash#467) was hand-copied per binary: wide-char table in the shim (kArgvAdapters), narrow rewrite in the multiplexer (opt_forward_argv_prefix), each pointing at the other in comments. The table + both-width lookups now live once in src/shared/argv_adapters.h; the BINMODE rationale moved into that header; consumers keep pointer comments.

Residue grep after the first convergence found a third copy the audit had not catalogued: wpm.cpp's opt_forward_adapted() hardcoded lowered == "awk" || lowered == "gawk" with a "mirrors…" comment. It now queries the shared table too (commit C4b). The awk/gawk adapter set now exists exactly once in the tree (remaining "awk" hits in find.cpp are -printf format-style names, unrelated).

Before/after, same input: table contents byte-identical (awk, gawk → L" -v BINMODE=3"), ASCII case-insensitive matching at all three sites; the header was logic-tested under g++ (−Wall −Wextra −Werror) in both API forms: exact/case-variant matches, non-matches, empty name, and prefix-truncation (awkx with length 3 matches, with length 4 does not) all pass. One theoretical delta, noted for the record: the shim's old lookup lowered with towlower, under which a payload name containing U+212A (KELVIN SIGN) would fold to k and could match awk; the shared lookup is ASCII-only, so such a name no longer matches. No real payload name contains a Kelvin sign.

Implementation lesson from CI (commit C4c): the header's first form used std::string_view, and wpm.cpp's textual include of it inside the unity-built commands TU — after other amalgamated files had done import std — redefined the std module's entities (C2953/C2371 cascade). This tree's command TUs take std from the PCH + import std only. The header therefore speaks plain C types (pointer + length in, const wchar_t* or nullptr out, only <stddef.h> included); callers pass .data()/.size().

Explicitly out of scope (per the ruling)

  • rm's raw-argv re-check — adjudicated dual insurance with a real job (dispatcher abbreviation expansion destroys information GNU's refusal logic needs).
  • dispatcher's classify_args_for_dispatch dual getopt walk — audit item P1, undecided class, not approved.
  • Anything GCC-related (official toolchain is MSVC).

No user-visible message text is added, removed, or altered by any commit → no i18n catalog impact (AGENTS.md sync rule not triggered).

CI accounting

  • Run 40692864363 (head 4cac885): failure at CMake configure — examples/container/CMakeLists.txt referenced the deleted partition. Fixed by B1b.
  • Run 40693168816 (head 869f8ac): failure in Build Project — unity-TU std redefinition cascade from the header's <string_view> (see C4c). Fixed by the std-free header.
  • Run 40693854565 (head ffad5f0): success — build-windows (x64) success including PGO rebuild, build-windows (arm64) success; ctest x64: 100% tests passed out of 3417, matching the current main baseline (3417/3417).
  • GNU master differential, run 40693854553: success (byte-level stdout/stderr/exit comparison against GNU master).

…late with zero consumers

Redundancy audit R3: ConstexprMap/make_constexpr_map were defined in
src/container/constexpr_map.cppm and re-exported by container.cppm, but a
repo-wide grep over src/ + tests/ finds no instantiation or reference
outside the definition file and the aggregator (unlike small_vector,
which has dozens of consumers). Uninstantiated, it cost no runtime, but
every TU importing container parsed the template and the tree carried it
like a live subsystem.

Remove the partition file, its export from container.cppm, and its entry
in the per-command executable source list (the winuxcmd-commands target
globs src/**/*.cppm, so it needs no list edit).
…in every built layout)

Redundancy audit R2: dir and vdir each carried a full external fallback
(build_*_command_line quoting + resolve_child_command execvp-semantics
resolution + CreateProcessW of an external ls.exe) behind
!CommandRegistry::hasCommand("ls").

That condition cannot fire in any layout this tree builds:
- The only multiplexer image is winuxcmd.exe, which links the
  winuxcmd-commands static library built from a glob of ALL
  src/commands/*.cpp (CMakeLists.txt:386,412); ls.cpp's REGISTER_COMMAND
  is therefore always in the same image as dir/vdir.
- The per-command standalone-executable macro that could have produced a
  split-applet dir.exe (CMakeLists.txt:564) is defined but never invoked.
- Shipped layouts (usr\\bin hardlinks, wpm shim layout) all run that same
  multiplexer image.

Reachable behaviour is unchanged: the in-process dispatch path is
untouched. The unreachable branch keeps the fallback's failure shape
("dir: failed to execute ls" / exit 1) instead of the spawn machinery.
…e of truth in core

Redundancy audit R1: the 8-name literal-argument set {echo, yes, test, [,
true, false, printf, expr} was hand-copied in two places - main.cpp's
top-level --version pre-scan and dispatcher.cppm's abbreviation-expansion
exclusion - kept in sync only by a comment. The copies already drifted
once: #1215 (main's copy missed "expr").

core:dispatcher now owns the table behind the exported
is_literal_arg_command(); both consumers call it. The sets were
byte-identical at convergence time, so behaviour is unchanged; the
#1215 history moves into the shared function's comment so the next
addition edits exactly one table.
…ne shared helper on ctx.raw_args

Redundancy audit R5: diff (diff_command_tail), diff3 and sdiff (two
verbatim-identical last_raw_argument lambdas) each re-ran
CommandLineToArgvW on GetCommandLineW() to rebuild operand text GNU
echoes in -r/-l headers and in "missing operand after '%s'" - even
though the dispatcher already parsed the same command line and hands it
to every command as ctx.raw_args, with argv[0] and the multiplexer verb
token already dropped (exactly the tokens the three copies dropped by
hand).

One shared implementation now lives in diff_engine.h (the header all
three already include): command_tail_from_raw_args and
last_raw_argument, both computed from the raw_args span. Behaviour on
both entry forms (multiplexer verb and <command>.exe hardlink) is
identical by construction; under a host process (FFI DLL form) the old
code read the host's command line, the new code reads the command's own
arguments.
… live function remains

Redundancy audit R4: utils:path re-exported the native_path surface
under shorter names. Per-function consumer grep over src/ + tests/
(qualified path:: calls, no using-directive for the namespace exists
anywhere in the tree):

  zero call sites: normalize_path, get_parent_path, get_filename,
  get_stem, get_extension, exists, is_directory, is_regular_file,
  create_directory, create_directories, current_path, current_path_w,
  get_executable_path, join (both overloads each) - 24 of 25 exports.
  The tree had already voted with its feet: applets call native_path::
  directly (normalize_api_operand / make_api_path_operand alone have
  250+ call sites).

  sole live export: get_executable_name (src/Main/main.cpp:514).

The 24 dead wrappers are deleted; the partition keeps the one live
function. Callers of the removed names would not compile - the grep
above is the proof there are none.
…red/argv_adapters.h)

Redundancy audit R6: the argv-adapter rule (awk/gawk payloads get
" -v BINMODE=3" spliced ahead of their arguments, niubash#467) was
hand-copied in two binaries that cannot share a module: the package
shim kept a wide-char table (kArgvAdapters), the multiplexer rewrote
the same rule in narrow char (opt_forward_argv_prefix), and each file's
comment pointed at the other as the copy to mirror.

The table and both width lookups now live once in
src/shared/argv_adapters.h, which both files include; the full BINMODE
rationale moved into that header, and each consumer keeps a pointer
comment. The prefix bytes and the name set are unchanged.

One theoretical delta, noted for the record: the shim's old lookup
lowered the payload name with towlower, under which a name containing
U+212A (KELVIN SIGN) would fold to 'k' and could match "awk"; the
shared lookup is ASCII case-insensitive, so such a name no longer
matches. No real payload name contains a Kelvin sign.
…adapter name set

Follow-up to the previous commit, found by its residue grep:
src/commands/wpm.cpp kept its own spelling of the same fact
(lowered == "awk" || lowered == "gawk"), with a comment saying it
mirrored the shim table and main's helper. It now asks the shared table
in src/shared/argv_adapters.h like everyone else, so the awk/gawk set
exists exactly once in the tree.
…e consumer was its own demo)

CI configure caught what the audit's src/+tests/ grep scope missed:
examples/container/constexpr_map_example.cpp did instantiate
make_constexpr_map, and examples/container/CMakeLists.txt compiled the
partition into its demo library.

That does not make the template a live subsystem: the example exists
solely to demonstrate ConstexprMap - it is part of the dead apparatus,
not a consumer of it (same shape as a dead feature kept alive only by
its own tests). No product target, command, or test references it.
Remove the example file and its CMake entry together with the
partition, and record the correction here and in the PR body: the
audit's 'zero consumers' held for src/ + tests/; the examples/ demo was
the one exception, removed with its subject.
…annot textually include <string_view>

Windows CI (run 40693168816) failed in the winuxcmd-commands unity TU:
once any amalgamated file has done `import std`, a later textual
<string_view> include (pulled in by argv_adapters.h through wpm.cpp)
redefines the std module's entities (C2953/C2371 cascade in iosfwd).
This tree's command TUs take std from the PCH + `import std` only -
project headers like diff_engine.h include nothing but pch/pch.h.

The shared header now speaks plain C types: table entries are
const char*/const wchar_t*, lookups take (pointer, length) and return
const wchar_t* or nullptr. It includes only <stddef.h>. The three
callers pass .data()/.size() and wrap the pointer. Semantics unchanged;
the header's comment records why the API looks this way. (main.cpp's TU
had compiled with the std:: API - it is not unity-built - but all three
consumers now use the one safe form.)
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 28, 2026 13:31
@caomengxuan666
caomengxuan666 merged commit 0c9383a into main Oct 28, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the clean/winx-redundancy branch October 30, 2026 01:42
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