Repository navigation
parser/executor: first-element line stamps (time prefix, procsub targets, respawn span, function-body plant) - #3266
Merged
Conversation
…dies GNU bash plants the function name's line in the first body command when that command's first element is a redirection (parse.y:5849-5851 plant, parse.y:810-811 first capture, parse.y:838 consume on completion). The pin covers the plant, the wrappers that do not consume it, and the guards that must not inherit it; every expectation is byte-verified against GNU Bash 5.3.20 script-file probes. Refs #3209
…sub targets, respawn spans, and function definitions Three stamp losses, one per face: A node whose words are a foldable time prefix chain records the end line of the first element after the chain at that element's intake, and the fold applies it when it strips the prefix (GNU parse.y:1055 keeps the timed command's own lineno). Process-substitution redirection targets now run the same first-element correction as plain targets, with the closing paren token as the correction point. Synthetic procsub words carry the assembled word's real end line. The respawn span codec gains a fourth field carrying the first element's end line end to end; three-field entries still parse with no stamp. Both span carriers share one formatter/parser pair (GNU variable.c:5703-5707: the child already runs with SHELL set to the parent's path). A bare name() definition restamps its body's first simple command to the definition line when that command's first element was a redirection, at the function parser and at both executor definition-reparse sites (GNU parse.y:316, parse.y:5849-5851, parse.y:810-811, parse.y:838; execute_cmd.c:936). Refs #3053 Refs #3054 Refs #3209
This was referenced Nov 10, 2026
caomengxuan666
marked this pull request as ready for review
November 10, 2026 17:25
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
…3221) The output process-substitution spawn carries fd>=3 through the __RUBASH_FD_* env channel as inheritable dups delivered AT their stamped numbers; the child's init restores the stamped handle instead of adopting whatever descriptor sits at slot fd. Without this declaration the consumer adopted the inherited outer file at slot 3 (direct-test6: tap.log 7 lines, comsub empty, INNER-RC=1). GNU anchor: subst.c:6362 process_substitute forks the consumer at expansion time inheriting the expansion-time table, which is what the stamped handle carries. The comsub-nesting attribution half of this shape is already in master via #3132 (dollar_group_end opacity, d65441d): a span inside $(...) belongs to the comsub child, so the clone's stage machinery materializes it via this stamped spawn route. This commit carries the stamped-delivery half plus the pin that proves the combination. Verified on the Simular box. run6 (pre-rebase tree): fail-first pin 3 passed / 2 failed (cells 04/05 red); head pin 5 passed / 0 failed; probe-adopt, V1, V2, V3 all pass; direct-test6 INNER-RC=0; RUSTFLAGS="-D warnings" cargo check rc=0; fmt rc=0; marker-lint rc=0; lib head 1207 passed / 0 failed, failure name set empty. run7 (rebased head, box pid 718998): Phase A on pure master d7a3725 — pin 5/0 and probe-adopt PASS without this PR (#3132 + #3234 already fix the reduced shapes); Phase B on the head — probe-adopt, V1, V2, V3 pass, pin 5/0, direct-test6 INNER-RC=0, -D warnings/fmt/marker-lint rc=0, lib head 1230 passed / 0 failed / 4 ignored, failure names none. run8 (discrimination, 917870f binary, box pid 721997): direct-test6 INNER-RC=1 with the byte-identical leak and pin 5/0 — #3266 exonerated, and the stamped insert is what fixes the real bats shape (the reduced pin passes on master without it; the full shape is guarded by the direct-test6 box leg). Adjacent gap, out of scope: the backquote shape (out=`exec 3<&1; ...`) still fails on the head (BQ-FAIL: log non-empty) — #3132's rule covers only $-groups; GNU expects OUT hello twice, log empty. Refs #3221
This was referenced Nov 10, 2026
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.
What this changes
One mechanism family: a simple command's first-element line stamp
(GNU
simplecmd_lineno) and the places that stamp failed to reach.GNU anchors (bash 5.3 sources):
parse.y:316(stamp initialised to-1),
parse.y:5849-5851read_token_word(a word read at commandposition plants the stamp),
parse.y:810-811(a redirection elementcaptures the stamp only while it is still unset, after its target
word was read),
parse.y:832make_simple_command(stored once asSimple->line),parse.y:838clean_simple_command(the plant isconsumed by the first completed simple command, and by nothing
else),
parse.y:1055(the bare-name function definition form plantsthrough the same command-position capture; the keyword forms plant
nothing),
execute_cmd.c:936SET_LINE_NUMBER(diagnostics and$LINENOreport the stored stamp).1.
timeprefix and procsub redirect targets (parser)rubash parsed
timeas the node's own first word, so theprovisional stamp was the
timetoken's and the real first elementcould never restamp it; the prefix fold stripped the head without
restamping. While a node's recorded elements are exactly a foldable
time-prefix chain, every following element's intake now records its
end line as a transient candidate on the node (word intakes re-run
the fold's own chain scan with the word appended, so admission is
the fold's, not a second spelling list), and the fold applies the
candidate at the moment it strips the head. A node that never folds
is byte-identical to before.
The process-substitution target consumption sites were never wired
to the redirect-target stamp correction that plain targets and
heredoc delimiters already had, so the stamp stayed at the
operator's line. The correction token for a procsub target is the
closing
)token the collector stops on — the whole span's endline, i.e. the GNU word end. Wired sites: the RedirectIn /
RedirectErr / RedirectErrAppend / HereString procsub branches in
token actions, and the combined / output / append target paths in
redirect assignment. Deliberately not wired:
collect_trailing_redirections, which only ever collects trailingredirects, never a first element.
2. Respawn span transport (executor)
CommandLineSpancarried only line / end_line / logical_line, so arespawned child re-derived the first-element stamp from its
re-parse of the collapsed body text and the executor's guard
degraded split first elements to their start line. The span now
carries
first_word_end_lineend to end: collect copies it, applywrites it back unconditionally (the parent's value is
authoritative), and the shared wire codec for both span carriers
emits a fourth dotted field. The FN carrier's encoder, which
open-coded the old three-field format, now uses the shared
formatter. The parser still accepts the three-field form (reads as
no stamp), so a hand-built stamp cannot misalign a re-seed; live
transports are always same-binary and always emit four fields.
3. Function body's first command, redirection-first (parser + executor)
New regression pin (24 cells, every expectation byte-verified
against GNU Bash 5.3.20 script-file probes): a bare
name()definition plants the stamp with the definition line; when the
body's first simple command is redirection-first, its stamp is the
definition line, not the line its first element finished on. (The
pin file's tail was lost to a truncated tool output written back
during the write-wall episode and was reconstructed from the
wave's surviving GNU probe runners with every expectation
re-measured; the pin header records this.)
Element order is not stored on the node, so "this command's first
element was a redirection" is proven where it is exact — inside the
redirect-target correction, whose admission is precisely "no other
element recorded yet"; both of its branches now set a
first_element_redirectflag.finish_function_command, thesingle exit every definition path shares, then walks the body in
parse order for bare-name definitions only and restamps the first
simple command's
lineandfirst_word_end_lineto the definitionline when the flag is set. Wrapper commands are descended in token
order; arithmetic and conditional commands are skipped over (they
never capture or reset the stamp); nested definitions and case
commands stop the walk (a case clause's stamp comes from the
pattern token — a distinct compound-command mechanism, recorded
separately). The two executor sites where a definition body is
re-parsed at definition time apply the same restamp to the retried
body.
logical_lineis untouched.Fail-first
Measured on the pristine base (
f7fed212); per-stemtest resultlines:
the plant cells (multiline body, brace body on its own line,
split header, subshell body form, background-first, coproc).
8 passed / 2 failed.
Head verification
pre-registered:
coproc_first_reports_definition_lineisblocked by a parser defect outside this change (the coproc
grammar rejects a redirection-first coproc body outright, on
base and head alike, so the walk's coproc arm cannot be
reached; it needs its own issue).
base. One of the two reds is the d8 cell, whose own repair wave
follows this PR. The other red's expectation contradicts the
GNU oracle (the pin expects rc=0 where GNU measures rc=127,
and rubash matches GNU byte-for-byte there); recorded in the
wave report for that pin's owners.
1207 passed / 0 failed on head — the failure name sets are
identical (empty).
issue2332 respawn text body 12/0, issue3028 continuation
error line 23/0, issue1184_f4 procsub diagnostics 7/0,
issue1520 parse-time POSIX time 18/0, issue1548 time quoted
option operand 12/0.
RUSTFLAGS="-D warnings"cargo check on the head tree: clean.cargo fmtapplied; the change is formatted.Residuals recorded in the wave report
bodies do not parse).
command, an assignment-completed first command, a word-first
split, a pipeline second stage, a command after a
redirect-only first command) report line 1 on both trees where
GNU reports line 2 — a flattening of the first body command's
stamp inside definition capture, unchanged by this change and
outside its mechanism. Measured values are in the wave report
addendum; the shapes are deliberately not pinned here.
What this PR deletes (本 PR 删除了什么)
Nothing is deleted outright. The span wire format's three-field
rendering is replaced by the four-field form (the parser keeps
reading three-field entries), and the FN carrier's open-coded span
rendering is replaced by the shared formatter. No files removed;
the net change is additive (new node fields, the restamp walker,
the candidate hooks, and the correction call at nine procsub
sites).
Refs #3053
Refs #3054
Refs #3209