Skip to content

WIP: 2036 S3 dispatch tables project from the registry + KD-2 source alignment - #2080

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2036-s3-dispatch
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2036-s3-dispatch

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: #2036 S3 — four dispatch tables project from the single registry; KD-2 execution side closed

Refs #2036. Does not close it (S4–S6 remain). Base: master b587937f (S1 #2050 + S2 #2075 in).

Item 1 — the four dispatch tables project from the registry (behavior-preserving)

command_registry gains one typed slot table per dispatch entry (PRIMARY_DISPATCH / LATE_DISPATCH / CMD_PRIMARY_DISPATCH / CMD_LATE_DISPATCH — each is its entry's registry claim set, sorted const data), and the four dispatch functions (command_dispatch_primary, command_dispatch_late, command_no_alias, command_no_alias_late) match on slots instead of string literals. Lookup is one binary search over ≤43 short strings (the builtin_names shape): const data only — no runtime-mutable registry, no locks/hash maps, no added syscalls, stand-down judgment untouched (audit §5 C1/C2).

Every per-name body moved verbatim; arm order is preserved where semantic:

T7 is reworked to prove equality on the dispatch data itself (table names == row claims per entry, sortedness/uniqueness, hidden slots == HiddenFastpath rows, lookup/table agreement); the old source scan survives as a one-directional shadow-arm guard. The S1 well-formedness pin (no row yields to a resolved real body) is unchanged — this slice changes no stand-down value.

Item 2 — KD-2 execution-side residual (the one sanctioned behavior change)

GNU's special-builtin table is name-based (builtins/mkbuiltins.c:148-154, 16 names, source included; flag applied by name at 819-820), but support_names::is_posix_special_builtin named 15. In POSIX mode the source spelling therefore escaped the definition rejection (fatal, exit 2), the invocation preclusion (execute_cmd.c:4657-4676), and the readonly-tempenv fatality (execute_cmd.c:4693) that . gets; assignment persistence hung on a || command == "source" workaround in variable_state. The predicate gains source (single classification point), the registry row's function_shadow flips to PosixSpecialBlock, the workaround is removed, and the two pins that carried the difference at exactly {"source"} now assert equality at 16.

New behavior pins: tests/issue2036_s3_posix_source_special.rs (5 tests, both spellings, GNU bash 5.3.20 script-file probe expectations: definition rejection / invocation shadowing / assignment persistence / readonly fatality / missing-file matrix incl. the command exemption).

Item 3 — stand_down two-axis adjudication table

Delivered as a table in the cluster REPORT (§裁定表), no behavior changed: every row with a stand-down face, its current two-axis values, the WinuxCmd/GNU sync face, the impact and performance cost of flipping it, and a recommendation per row — including the non-standard cells (pipeline sed InvertedSed, yes HashStandin, the per-face comsub basename Unchecked cell, the timed-consumer sleep non-consult, tput's separate hash record). Awaiting main-session adjudication cell by cell.

Gates

CI (this PR): the full set — the reworked registry pins (18 consistency tests incl. T7) run in the lib test jobs; -D warnings via the niu canary check.

Local (build slot, this tree):

  • cargo check --locked + RUSTFLAGS=-D warnings: clean.
  • Registry consistency pins: 18/18.
  • S1 probe battery issue2036_precedence_introspection_regressions: 20/20, expectations unchanged.
  • KD-2 pins: 5/5; the same shapes were run as script-file probes against GNU 5.3.20 and against the pre-change binary — pre-fix the source spelling diverged on definition/invocation/readonly exactly as analyzed, post-fix byte-identical to GNU.

Adjacent findings (recorded, NOT fixed here — separate homes requested in the cluster report)

  1. Pipeline stages ignore the POSIX special-builtin preclusion for all special names (measured: eval/./source functions all run as pipeline stages in POSIX mode; GNU runs the builtin). Class-wide, not a source gap; the pipeline face's effective route does not consult the predicate.
  2. Redirect failure on a special builtin in POSIX non-interactive mode does not exit (measured for :/./source/eval with <&9; GNU exits via execute_cmd.c:4869 EX_REDIRFAIL). Again class-wide and predicate-independent.

…KD-2)

GNU's special-builtin table is name-based: special_builtins[]
(builtins/mkbuiltins.c:148-154) lists 16 names with `source`
included as the synonym spelling of `.`, and the SPECIAL flag is
applied by name wherever it appears (mkbuiltins.c:819-820). The
executor's is_posix_special_builtin named only 15 — the registry's
SPECIAL_BUILTINS (S2, report side) already had 16 — so in POSIX
mode the `source` spelling escaped every execution-side special
treatment its synonym got:

- defining `source() { ...; }` was accepted where `.` errors
  fatally ("`source': is a special builtin", exit 2;
  function_calls.rs definition gate);
- a pre-defined `source` function shadowed the builtin at the
  simple-command face (execute_cmd.c:4657-4676: special builtins
  are found before functions) while `.` was precluded;
- a failed readonly assignment before `source` merely discarded
  the list where before `.` it exits the shell
  (execute_cmd.c:4693 tempenv arm, subst.c:11169-11180);
- assignment persistence (execute_cmd.c:4893) was held up by a
  one-off `|| command == "source"` workaround in
  variable_state::keeps_temporary_assignments.

Fix: add `source` to the predicate (single classification
point), flip the registry row's function_shadow to
PosixSpecialBlock, remove the variable_state workaround, and
move the two registry pins that carried the difference at
exactly {"source"} (now: sets equal, 16 names). Behavior pins in
tests/issue2036_s3_posix_source_special.rs run both spellings
through definition rejection, invocation shadowing, assignment
persistence, readonly fatality and the missing-file matrix, all
with GNU bash 5.3.20 expectations measured by script-file
probes.

Refs #2036.
#2036 S3)

The four hand-maintained dispatch matches (audit M3-M6:
command_dispatch_primary, command_dispatch_late,
command_no_alias, command_no_alias_late) now take their name
sets from the single registry: command_registry gains a typed
slot table per entry (PRIMARY_DISPATCH / LATE_DISPATCH /
CMD_PRIMARY_DISPATCH / CMD_LATE_DISPATCH — each entry's claim
set, sorted for binary search) and the four dispatch functions
match on slots instead of string literals.

Every per-name body moved verbatim, and the match-arm order is
preserved where it is semantic:

- the late table's function guard arm keeps its position
  between the ordinary slots and the hidden fast-path slots
  (uname/arch/stty, rubash#154) — a function still wins over
  the hidden claims and loses to the ordinary builtins at this
  layer, exactly as before;
- the per-arm `enable -n` checks (audit R4) stay per-arm,
  inside the bodies;
- `sudo` is not a registry claim (host elevation capability,
  issue #759): its cfg(windows) handler check becomes an
  explicit pre-check ahead of the table in the primary and
  `command` tables, with the historical fall-throughs
  (Ok(None) / late-table external) preserved;
- the late table's `((` arm is the tables' single unregistered
  entry — a parser pseudo-word, not a claimable name — and is
  listed as such in the pin.

Performance contract (audit §5 C1/C2): the tables are const
slices of plain data; lookup is one binary search over at most
43 short strings (the builtin_names shape). No runtime-mutable
registry, no locks, no hash maps, no added syscalls; the
stand-down judgment is untouched.

The T7 consistency pin is reworked accordingly: equality is
now proven on the dispatch data itself (table names == row
claims per entry, sortedness, the hidden-slot set ==
HiddenFastpath rows), and the old source scan survives as a
one-directional shadow-arm guard (a dispatch file may not
reintroduce a claim its entry does not project). The S1 probe
battery passes 20/20 with expectations unchanged.

Refs #2036.
@caomengxuan666

Copy link
Copy Markdown
Member Author

S3 cluster final state (main-session merge adjudication):

CI: all green on head bf939a8e — Rust tests / Rust tests (macOS) / GNU regression goldens and canaries / Shell functionality / Cross-target (darwin) / Cross-target (linux/android) / API ledger tripwire / niubash builds against this tree. mergeable clean.

Local gates (build slot): cargo check + -D warnings clean; registry consistency pins 18/18 (T7 reworked onto the dispatch data; KD-2 pins updated to equality at 16; the well-formedness pin — no row yields — is unchanged); S1 battery 20/20 with expectations untouched; new KD-2 pins 5/5; lib full suite 959 passed / 1 failed / 3 ignored with the single failure being the known baseline name (ownership_unary_operators_check_existing_file).

Two items for the main session (full text in the cluster REPORT §3/§5):

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