Repository navigation
fix(alias): same-read guard stamps monotonic read-unit generation — cross-unit line collisions expand like GNU (rubash#817) - #833
Merged
Conversation
…ross-unit line collisions expand like GNU (rubash#817)
The executor-level alias same-read visibility guard compared the
definition's PHYSICAL line against __RUBASH_CURRENT_LINE, so a
definition recorded inside a nested read unit collided with the
caller's own later physical lines: a sourced file restarts group
numbering at 1 and an eval string renumbers caller_line+i-1, so a
definition at the unit's line N suppressed a perfectly legal use at
the sourcer's line N ('command not found', rc=127) where GNU expands
— the rule is same-READ, not same-line (parse.y read-time expansion).
Identity is now (read-generation, line): each alias definition also
records __RUBASH_ALIAS_GEN_<name> from ShellState::read_generation,
and alias_defined_on_current_line suppresses only when BOTH match.
The generation boundary is exactly the existing CURRENT_LINE
save/restore seam: builtins/source/execution.rs pushes at the
evalfile.c:253-257 push_stream point and pops where run_unwind_frame
restores line_number (evalfile.c:395); execute_eval_source wraps its
body with enter/exit_read_unit (evalstring.c parse_and_execute's
pushed string). A monotonic ceiling keeps sibling units from ever
sharing a value (a depth counter would collide on back-to-back
sources); ShellState cloning carries the current generation across
the subshell fork boundary, where the body stays the same read unit.
unalias / unalias -a clear both marker halves.
Verified against WSL GNU bash 5.3.0(1) (stdin oracle): both ticket
repros (stdin+source, eval) now print AX/AY rc=0; the i368 audit's
9-row guard-rail table is byte-matched row by row (same-line
suppression on stdin scripts / inside sourced files / inside eval
strings stays 127 with GNU's diagnostics, N/N+1 and non-colliding
source/eval uses expand, sibling sources expand, -i piped
multi-submission expands, -i -c expand_aliases defaults on, $LINENO
stays cumulative, the -c grouped-driver collision layout expands).
tests/issue817_alias_read_generation_regressions.rs pins the two
repros, the control, the sibling-generation shape, and rows 1-4+9.
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.
Closes #817.
Root cause
The executor-level alias same-read visibility guard used the definition's physical line as identity:
__RUBASH_ALIAS_LINE_<name>(= the defining command's AST line) compared against__RUBASH_CURRENT_LINE, equal values suppress expansion (src/executor/arithmetic_aliases.rsalias_defined_on_current_line; record atsrc/executor/alias_set_builtins.rs). But nested read units renumber lines — asourced file restarts at 1 per file (run_source→read_next_source_group) and anevalstring renumberscaller_line + i - 1(src/executor/trap_exec.rsexecute_eval_source) — so a definition at the unit's line N collided with the sourcer's own later physical line N: a perfectly legal use was suppressed withcommand not found/ rc=127 where GNU expands. GNU's rule is same-read, not same-line (parse.y read-time expansion; the nested unit is a distinct input stream — evalfile.cpush_stream/ evalstring.cparse_and_executepushed string).Fix — monotonic read-unit generation (audited direction)
Identity becomes (read-generation, line):
ShellStategainsread_generation(the stream the executing commands were read by) +read_generation_ceiling(monotonic high-water; sibling units never share a value — a depth counter would collide on back-to-backsources, which is load-bearing for the sibling shape below). Cloned across the subshell fork boundary like every C global: a subshell body is the same read unit as its parent.enter_read_unit()/exit_read_unit()(src/executor/public_accessors.rs) push/pop at exactly the existing__RUBASH_CURRENT_LINEsave/restore seam:src/builtins/source/execution.rspushes at the evalfile.c:253-257push_streampoint and pops whererun_unwind_framerestores line_number (evalfile.c:395, before the RETURN trap);execute_eval_source(src/executor/trap_exec.rs) wraps its body with the pair.__RUBASH_ALIAS_GEN_<name>alongside the line (record_alias_definition_lines); the guard suppresses only when generation AND line both match;unalias/unalias -aclear both marker halves. The line marker's value format is untouched (${__RUBASH_ALIAS_LINE_x}still reads the physical line —tests/issue367_alias_line_hygiene_regressions.rspasses unchanged).GNU differential evidence (WSL GNU bash 5.3.0(1), stdin oracle
bash --noprofile --norc < probe)Both ticket repros, executor level:
source def5.sh, def file-line 5 == caller use-line 5AXrc=0line 5: x: command not foundrc=127AXrc=0AYrc=0line 6: y: command not foundrc=127AYrc=0AYrc=0AYrc=0AYrc=0AXrc=0AXrc=0AXrc=0 (needs the monotonic ceiling)NNrc=0NNrc=0NNrc=0i368 audit must-survive semantics table, row by row (all matched GNU before on
8ab35e89; re-verified after the fix on this branch):alias ll='echo LL'; llsame line, stdin scriptline 2: ll: command not founddef2.shline 2)def2.sh: line 2: x2: command not foundevalstringline 2: z: command not foundWWrc=0)AXrc=0)-i(piped) multi-submission alias useMM)MM)-i -cshopt expand_aliasesdefault$LINENOacross-isubmissions1,2cumulative1,2bash -ccollision layout (. def5.sh… use at line 5)AXrc=0)Tests
tests/issue817_alias_read_generation_regressions.rs(9 tests): both repros, the audit control, the sibling-generation shape (pins the monotonic ceiling), and guard-rail rows 1-4 + 9 including the byte-identical row-2 diagnostic. Existingtests/issue367_alias_line_hygiene_regressions.rspasses unchanged (marker namespace untouched).Full-suite differential vs baseline (db4aaf7)
cargo test --no-fail-faston this branch vs a baseline worktree at db4aaf7, bidirectional: 0 vanished failures, 0 real new failures. The only name-level diff between runs is two pre-existing environment-flaky families that fail/pass identically on both sides in matched runs: thecommand -pstandard-path pair andexecutor_command_chaining::part_071::test_shellmath_decimal_divide_script_path(needs thethird_party/bashsubmodule, which fresh worktrees don't populate; passes on both sides once the submodule is checked out).Intersection check
fix/720-713, PR fix(trap): ERR-trap nested-context semantics — collapse suppression, flat-region fire, return attribution (rubash#720) #831, open): file overlap =src/executor/trap_exec.rs+src/executor/init.rs, but hunks are disjoint (theirs: trap_exec.rs ~1261-1380 ERR-adjudication region and init.rs:351; mine: trap_exec.rs ~300 + ~478-500 eval seam and init.rs ShellState literal ~300-305). Rebased check done at push time:origin/masteris stilldb4aaf7b, this branch sits directly on it; no textual conflict expected on either merge order.200771b1); its prompt/source surface is in the baseline this diff was produced against — no intersection.GPL: no vendored/GPL source copied; only factual
file:lineanchors in comments.cargo fmt --checkclean. PR to master, not merged.