Skip to content

WIP: fix(exec): per-function source-span transport for respawn LINENO (#2202) - #2327

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2202-lineno-span
Oct 31, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2202-lineno-span

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Refs #2202. Intra-body LINENO fidelity for respawned function bodies.

Problem. The respawn prelude re-renders each function body via bash_command_sequence_text, collapsing its line structure; the fork stamp carried only one seed line per body. A body command in an async/coproc/procsub child therefore reported the call-site line (async) or a re-parse line (coproc/procsub) instead of its own definition line. GNU's forked child executes the parent's parsed tree, whose nodes keep their parse lines (make_cmd.c:196 temp->line = lineno), and execution re-stamps line_number from the executing node (execute_cmd.c:936; function entry :5351), with $LINENO bound to it (variables.c:1861 get_lineno).

Fix (transport-format change).

  • Stamp: fork_context_transport_entries also emits __RUBASH_FORK_FN_SPANS — for exactly the functions background_function_prelude transports, each body's per-node (line, end_line, logical_line) spans in a canonical AST traversal (parser::collect_command_line_spans), riding the indexed-array codec; the key joins FORK_TRANSPORT_KEYS (stripped unconditionally at child birth).
  • Consumption: init.rs decodes it (internal respawns only) into ShellState::respawn_function_line_spans.
  • Re-seed at both install paths: define_function re-seeds prelude-defined bodies (consuming the entry, so a later redefinition keeps its own lines); the Executor::new BASH_FUNC import re-seeds imported bodies at birth (the coproc and procsub-producer spawns transport the table that way). apply_command_line_spans count-checks the round-trip before writing — a shape-unfaithful re-render leaves the body untouched.
  • Nested respawns re-stamp from the re-seeded table. [respawn] 运输集完整性盘点:BASH_ARGV 底帧为空等 fork 状态缺口 #2058's start-point seeds and the WIP: fix(executor): reject non-POSIX class names in =~ (#1717) #1761 call-site seed are untouched for what the transport does not cover.

Verification (cluster, slot + scrubbed-fd runner). New pins tests/issue2202_lineno_span_transport_regressions.rs: 10/10. #2058 controls: 12/12. Neighborhood (2179/1220/1221/1659/2053/2057): 21/21. Script probes p1–p7 byte-match GNU bash 5.3.20 (baseline was all-call-site/prelude lines, e.g. 2/3/6 vs 8/8/8). #2058 census re-run: 15/21 byte-identical (was 12/21); the 6 remaining diffs are the TEXT-body shapes (asyncsub/coproc inline bodies) — a separate mechanism (root-command span + initial-parse patch), documented as the residual in the cluster REPORT.

Full report: ~/workspace/fix-2202-lineno-span/REPORT.md

The respawn prelude re-renders each function body with
bash_command_sequence_text, collapsing its line structure, and the
fork stamp carried only one seed line per body — so a body command
in an async/coproc/procsub child reported the call-site line (or a
prelude-relative line) instead of its own definition line. GNU's
forked child executes the parent's parsed tree, whose nodes keep
their parse lines (make_cmd.c:196), and execution re-stamps
line_number from the executing node (execute_cmd.c:936, :5351).

Transport: fork_context_transport_entries now also stamps
__RUBASH_FORK_FN_SPANS — for exactly the functions the prelude
transports, each body's per-node (line, end_line, logical_line)
span list in a canonical AST traversal (parser::collect_command_
line_spans), riding the indexed-array codec. Consumption: init.rs
decodes the stamp into ShellState::respawn_function_line_spans
(stripped like every FORK_* key), and define_function re-seeds the
re-parsed body's node lines from the span at definition time
(parser::apply_command_line_spans, count-checked against a
shape-unfaithful round-trip), consuming the entry so a later
redefinition keeps its own lines. A nested respawn re-stamps from
the child's re-seeded table, so spans survive chains.
Nine script-file pins against GNU bash 5.3.20 expectations: async,
coproc and procsub function children report each body command's
definition line (including blank/comment lines in the count),
compound bodies (if/for) and nested function definitions ride the
outer span, same-line commands share their line, and a nested
respawn re-stamps from the re-seeded table. Controls: the direct
in-process call and the #2058 async-subshell start-point seed are
unchanged.
The coproc spawn and the process-substitution producer transport
the function table as BASH_FUNC entries, not as prelude text, so
their children install functions through the Executor::new import
and never reach define_function. Apply the recorded span to the
imported bodies at birth (consuming the entry: the imported body
is the definition this shell holds, and a definition executed
later must keep its own lines). Adds the output-procsub pin, whose
consumer child rides the prelude/define_function path.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 08:25
@caomengxuan666
caomengxuan666 merged commit 0fe408c into master Oct 31, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2202-lineno-span branch November 2, 2026 01:08
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