Skip to content

parser/executor: rebase heredoc gather end line with token positions - #3680

Merged
caomengxuan666 merged 1 commit into
masterfrom
devin/heredoc-end-line-offset
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
devin/heredoc-end-line-offset

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Token::heredoc_end_line records the physical line where the lexer stopped gathering a here-document body. Every site that shifts a token's position/end_position/logical_line into the ambient line space (source offsets, folded {/function bodies, eval/trap boundaries, unclosed-compound regions) now shifts the gather end line in lockstep.

Before this, a here-document that hit EOF inside a rebased region warned under the fragment-local line: f() {\ncat <<EOF\nx printed line 2: warning: here-document ... where GNU prints line 3. Six rebase sites updated (script_driver, builtins/source/execution, trap_exec ×2, function_command, function_calls, parse_loop::unclosed_brace_eof_node).

GNU owner: make_cmd.c gather line accounting — the warning reports line_number once the gather stops at EOF (the physical end line, #1028 family); parse.y:6899 reports the same ambient space for the unclosed-compound error.

Verification

  • GNU Bash 5.3.20 (macOS arm64), byte-identical: { cat <<EOF\nx → line 2 warning naming at line 1; f() {\ncat <<EOF\nx → line 3 naming at line 2; x=1\n{\ncat <<EOF\nx → line 4 naming at line 3.
  • niubash gate slice run-heredoc: PASS (the last remaining diff was macOS /bin/bash 3.2 rewriting exported-function env values inside the test harness — niubash-side infra, not a rubash divergence).
  • New pins: tests/issue3605_heredoc_end_line_rebase.rs (3 cases).
  • Known adjacent residual (out of scope): {-family unclosed-compound EOF errors report last_line where GNU reports last_line + 1 ({ cat <<EOF\nx → niu line 2, GNU line 3); (-family already correct.

Refs #3605

Token::heredoc_end_line records the physical line where the lexer
stopped gathering a here-document body. When a folded or reparsed
region shifted `position`/`end_position`/`logical_line` into the
ambient line space (source offsets, folded `{`/function bodies, eval
and trap boundaries, unclosed-compound regions), the gather end line
stayed at its fragment-relative value. The EOF gather warning then
printed under the wrong `line N:` prefix: `f() {\ncat <<EOF\nx`
warned at line 2 where GNU warns at line 3, and unclosed-compound EOF
errors could fall back to the fragment-local line.

Shift `heredoc_end_line` in lockstep at every rebase site:
- script_driver.rs run_source_impl_inner_body (line_offset)
- builtins/source/execution.rs run_source_groups (line_offset)
- trap_exec.rs caller_line eval splice + line_offset parse (2 sites)
- function_command.rs folded body re-lex (base - 1)
- function_calls.rs quoted function word (base_line - 1)
- parse_loop.rs unclosed_brace_eof_node inner region (brace_line - 1)

GNU owner: make_cmd.c gather line accounting — the warning reports
`line_number` once the gather stops at EOF (the physical end line,
rubash#1028 family); parse.y:6899 reports the same ambient space for
the unclosed-compound error.

Verified on macOS arm64 against GNU Bash 5.3.20:
`{ cat <<EOF\nx` -> `line 2` warning naming `at line 1`;
`f() {\ncat <<EOF\nx` -> `line 3` naming `at line 2`;
offset brace group (`x=1\n{\ncat <<EOF\nx`) -> `line 4` naming
`at line 3`. niubash gate slice run-heredoc: PASS (the remaining diff
turned out to be macOS bash 3.2 rewriting exported-function env
values in the harness, not a rubash divergence).

New pins: tests/issue3605_heredoc_end_line_rebase.rs (3 cases).

Refs #3605

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】开工评论:机制已验证(分组路径 warn prefix base=line3 vs GNU line6,head 已修正一致),但所附钉的 3 个形状不走分组驱动路径,在未修复 base 上同样全绿 = 非判别钉。本轮续作只补一个判别测试(. 标记触发 grouped driver + 非零行偏移的 EOF heredoc 重定基形),不动产品代码。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3680 第1轮 — 建议:PASS(附钉质量注记)
head: 683a9f4 base(merge-base): 96802ca 文件: 7 个 +99/-0
关联 issue: #3605(open,核于 2026-11-16 — 追踪目录 issue,合并不关单)

机制核查:

  • 6 个重定基点(run_source_impl_inner_body、run_source_groups、function_calls comsub 拼接、trap_exec eval/DEBUG、function_command 折体、unclosed_brace_eof_node)把 heredoc_end_line 与 position 同步位移 — 对应 GNU heredoc EOF 警告按 gather 结束时的物理 line_number 报告(make_cmd.c 警告链、parse.y:6899 unclosed-compound)。机制贴合。
  • 无关改动:无;无桥接层。

腿:

  • 钉自跑:issue3605_heredoc_end_line_rebase 3/3 绿
  • fail-first:base 上 3/3 绿(非判别钉) — 3 个钉形不走分组驱动路径,在 Windows base 上基线输出已正确。但产品修复真实有效:补测 # marker . 分组标记\nx=1\nx=2\nf() {\ncat <<EOF\nx\n 在 base 打 line 3: warning: ... at line 5(GNU 5.3.20 = line 6),head 打 line 6 与 GNU 逐字节一致;# marker .\ntrue\n{\ncat <<EOF\nx\n 同理 base3→GNU5→head5。钉缺「触发 grouped driver 的标记」,判别力缺口属实但修复面有效(PR 正文作者处 macOS 上 f() {\ncat <<EOF\nx 曾打 line2,即钉在 macOS 上可能本就有判别力)。曾尝试续作补判别钉,被本机 pre-commit 钩(cargo fmt --check 在 1400+ 测试目标下撞 Windows 命令行长度上限 os error 206,恒失败)挡住,未 push;改进钉留档 .audit-s6/pins/issue3605_heredoc_end_line_rebase.rs。
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base 同 / 差集 {}(Windows 本机 flake,双侧相同)
  • -D warnings:lib+bins 0;钉 stem 编译 0
  • 卫生:PR 全部文件 rustfmt --check 0 diff(cargo fmt 在本机因 os error 206 不可用,逐文件替代);CI ubuntu job UTF-8/marker 两步 success
  • CI:红 = 3 job 仅 issue2875 基线(同 master run 43779513598);census 等后续 step skipped
  • GNU 对照(WSL GNU bash 5.3.20 脚本文件):分组形 warn 行 base3/head6/GNU6、base3/head5/GNU5、base3/head6/GNU6 — head 全一致;非分组形 hd1-3 warn 行 base 已正确、err 行差 1 属 fix(parser): count consumed physical lines into unclosed-compound EOF report (Refs #3605) #3681 面(已合入 aea5b15,合并后形态完整闭合)

F 点:无(钉判别力缺口见上,作注记不作否决)

续作记录:本轮未落地(env 钩阻断,见上)

未跑/VOID 的腿:cargo fmt 全库(os error 206 环境限),以逐文件 rustfmt --check 替代

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 07:18
@caomengxuan666
caomengxuan666 merged commit 2815ed3 into master Nov 16, 2026
8 of 11 checks passed
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