Repository navigation
WIP: fix(exec): per-function source-span transport for respawn LINENO (#2202) - #2327
Merged
Merged
Conversation
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.
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.
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:196temp->line = lineno), and execution re-stampsline_numberfrom the executing node (execute_cmd.c:936; function entry :5351), with $LINENO bound to it (variables.c:1861 get_lineno).Fix (transport-format change).
fork_context_transport_entriesalso emits__RUBASH_FORK_FN_SPANS— for exactly the functionsbackground_function_preludetransports, 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 joinsFORK_TRANSPORT_KEYS(stripped unconditionally at child birth).init.rsdecodes it (internal respawns only) intoShellState::respawn_function_line_spans.define_functionre-seeds prelude-defined bodies (consuming the entry, so a later redefinition keeps its own lines); theExecutor::newBASH_FUNC import re-seeds imported bodies at birth (the coproc and procsub-producer spawns transport the table that way).apply_command_line_spanscount-checks the round-trip before writing — a shape-unfaithful re-render leaves the body untouched.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/6vs8/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