Skip to content

fix4 slice-sml: #1290 second-diagnostic line residual + #1184 f4 procsub diag line seeding - #1522

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix4/slice-sml
Oct 25, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix4/slice-sml

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

概要

第四波第三片:sml 簇两件——#1290 第二诊断行号残差(三面全清,本片 Fixes 关单)+ #1184 f4 spawn procsub 体诊断行号归属(f6 船长补丁与赋值收尾残差未清,仅 Refs)。

基线 master 7bf3c582,cherry-pick 簇 commits 76f6dd2b / 9dc2abff(零冲突)。

一、#1290 残差:[[ … =~ ( … 未闭合时第二诊断的行号与形状

标题主体已随第四片 #1509 关单;残差 = 第二条诊断 unexpected argument to conditional binary operator。基线实测发现残差实际有三个面:

  1. file 模式整个形状都错:基线打印通用 unexpected EOF while looking for `]]' + tail,而非 GNU 的两行对。根因:conditional_eof_error_command 的 RHS 合并把 [[ 行之后的命令吞进 RHS 参数,后续片段带引号 ⇒ 合并参数 raw≠value ⇒ 分类器的未闭合括号检查被 raw == value 门挡住。GNU 的扫描跑在原始文本上(parse.y parse_matched_pair:反斜杠保护下一字符、引号是递归嵌套对且内容永不计数、引号前缀里的括号不开对)。修法:raw≠value 时改扫合并参数的 raw 形——新增 unclosed_regex_paren_line_in_raw(引号感知),与既有 cooked 形检查并列于同一 BareEof 出口。
  2. EOF 行丢 offset 且漏未终止末行规则:stream_eof_line 只数解析输入自身的换行。GNU 的 reader 在 EOF 处补齐最后一行,EOF 诊断永远落在最后一行之后一行。改为 offset + 换行数 + 1 + (末行未终止 ? 1 : 0)。
  3. stdin 模式组被提前提交:stdin 驱动以 [[ 一行为完整组提交;GNU 在读该命令时把流的其余部分都消耗进扫描。修法:stdin_source_needs_more_posix 的 token 遍历新增扫描深度跟踪(advance_regexp_scan_depth)——片段开启扫描后,后续一切 token 都是正则数据,直到配平 );未闭合 ⇒ 继续收行。

改动文件:src/parser/conditional_command.rs、src/script_driver.rs。

GNU 对照矩阵(GNU Bash 5.3.20 oracle):双探针([[ 在第 3 行,期望第二诊断行 7 / 5)× file/stdin 四格、三种 -c 形、无尾随换行单行文件、[[ 在第 2 行文件、通用 EOF 形、引号闭合不关扫描——修复后逐字一致;控制组(数据 ]]、闭合求值、引号内括号、有效多行组)与 GNU 全同、无过收集。

回归:tests/issue1290_cond_regex_eof_diag_regressions.rs 11 例,期望全部按 GNU 实测书写。

二、#1184 f4:spawn 的 procsub 体诊断恒报 line 1

根因:procsub 体由 spawn 的同 exe 子进程以 -c <source> 执行,失败时诊断恒报 line 1——子进程只拿到脚本名、没有构造所在行。修法:构造行经 env 播种(__RUBASH_CURRENT_LINE + __RUBASH_LINE_OFFSET,即 & respawn 的既有协议、main.rs 的 -c 驱动消费 offset),reader 初始行由此建立。

三个 spawn 执行点已修:

执行点 修法
简单命令输出 >(...) 物化时把所属命令的 cmd.line 存入 OutputProcessSubstitution.line,spawn 时播种 CURRENT_LINE 与 LINE_OFFSET = 构造行 − 1 − prelude 换行数
条件操作数输出 [[ -w >(...) ]] 入队时捕获 [[ 命令的 CURRENT_LINE 存入队元组
exec N< <(...) 输入 bind 调用点传 cmd.line;子进程补 __RUBASH_SHELL_PID 标记 + 脚本名 + CURRENT_LINE + LINE_OFFSET(此路径无 prelude)

进程内两形态(简单命令输入 <(...)、化合物化输出)基线已正确,本片以回归钉住为控制。

GNU 对照矩阵(诊断正文 3: Bad file descriptor):f4(tee 行 4)、f4late(行 6)、f4exec(行 4,且名前缀由 bash: 恢复为脚本名)、f4cond(行 4)修复后与 GNU 一致;f4b / f4comp 控制同。

回归:tests/issue1184_f4_procsub_diag_line_regressions.rs 7 例。

#1184 余项(本片不关单):f6 船长 continuation 补丁(草案在案);赋值 RHS 输出 procsub 收尾延迟 + 重复执行(根因在收尾时机、非行号播种,已另行立案,见评论);f4 的 rc 141 与外部 tee /dev/fd 物化差异为平台层旧账。

验证(集成树,门控全量)

  • cargo build --locked:通过(5m22s,无警告错误)
  • cargo test --lib:728 passed / 1 failed / 1 ignored,唯一 failed = ownership_unary_operators_check_existing_file(允许的环境项,与基线同集)
  • 新回归:issue1290 11/11 + issue1184 7/7 = 18/18
  • 246 差分:244/246,稳定失败集 = {gl08, ms10} ⊆ 基线许可集(ps06 为先完成者竞态:隔离 10 连跑 9 过 1 败、直跑分布与 GNU 同族,非回归)
  • 改动 8 文件 rustfmt(edition 2021)逐文件干净、CR 计数 0;未碰 src/lexer/continuation.rs 与载体字节。

Fixes #1290
Refs #1184

…bash#1290 residual)

The subject diagnostics for an unclosed regex group already matched
GNU; the residual was the second line's number (and, in file mode, the
whole shape). Three root causes, one per face:

- File mode: conditional_eof_error_command's merge swallows the lines
  after the `[[` line into the RHS argument (exactly the raw text
  parse_matched_pair would consume), so later fragments carry quoting,
  raw != value, and the classifier's unclosed-paren check — gated on
  raw == value — never fired; the generic `]]' EOF shape printed
  instead. The check now scans the merged RAW form when raw != value:
  parse_matched_pair scans the raw stream (parse.y:3901-3912), with
  backslash protection (LEX_PASSNEXT, parse.y:3965-3984) and quoted
  spans consumed as nested pairs that never count (parse.y:4040-4051);
  a quoted prefix paren therefore still never opens a pair
  (shellquote precedes the `(' case, parse.y:5417).
- stream_eof_line counted the parse input's own newlines but dropped
  source_line_offset, and missed GNU's unterminated-final-line rule:
  the reader completes the last line at EOF, so the EOF report
  (parse.y:5223-5227) lands one past it either way. Now
  offset + newlines + 1 (+1 when the final line is unterminated).
- stdin: the group reader submitted the `[[` line as complete because
  the lexer's =~ RHS fragments are skipped as word data. While a
  fragment's parse_matched_pair scan is open, every following token is
  regex data (including a `]]' token and later lines' keywords), so
  stdin_source_needs_more_posix now tracks the scan depth across the
  token stream and keeps gathering until the balancing `)'.

GNU 5.3.20 oracle (script file + stdin): v1290c reports lines 3 + 7
in both modes (was: generic shape in file mode, 3 + 2 on stdin),
p1290b lines 3 + 5; `-c '[[ abc =~ ([a-z]]]'` reports 1 + 2.
Regression tests: tests/issue1290_cond_regex_eof_diag_regressions.rs
(11 cases: both probes x file/stdin, -c forms, unterminated tail,
quoted-paren and quoted-close controls, delayed close).
…ion line (rubash#1184 f4)

A process-substitution body that fails inside a spawned same-exe
child reported line 1: the child received the script name but never
the line that constructed the substitution. GNU process_substitute
(subst.c:6362) forks at substitution time, so the body inherits the
parent's line_number then. The spawn carriers now seed that line
through the `&` respawn's env protocol (__RUBASH_CURRENT_LINE +
__RUBASH_LINE_OFFSET, main.rs consumes the offset for `-c`):

- Output substitutions (simple commands): the owning command's line
  is captured at materialization into OutputProcessSubstitution.line
  (the body runs at finish, when the current line has moved on) and
  threaded to spawn_output_process_substitution_child, which seeds
  CURRENT_LINE and LINE_OFFSET = line - 1 - prelude newlines (the
  body sits below background_function_prelude in the `-c` source).
- Conditional operands: the queue entry captures the `[[` command's
  CURRENT_LINE at realization (conditional.rs) — the seed the
  in-process body parse already trusts (rubash#1024).
- `exec N< <(body)` input bind (trap_exec.rs): the exec command's
  line is passed in; the child also gains __RUBASH_SHELL_PID, the
  internal-respawn stamp the child init requires before it keeps
  __RUBASH_SCRIPT_NAME at all, so the diagnostic prefix names the
  script as well as the line.

Already correct and now pinned, not changed: simple-command input
bodies and compound-command output bodies, which execute in-process
seeded from the executing command's CURRENT_LINE.

GNU 5.3.20 oracle (script files): f4 line 4 (was 1), f4late line 6,
f4exec line 4 with script name (was `bash: line 1`), f4cond line 4;
controls f4b lines 2 + 4 and f4comp line 4 unchanged.
Regression tests: tests/issue1184_f4_procsub_diag_line_regressions.rs
(7 cases). Out of scope, recorded in the cluster report: the
assignment-RHS output form's deferred/duplicated execution and
f4's rc (141 vs 0) from the external tee /dev/fd materialization.
@caomengxuan666
caomengxuan666 merged commit 9a64aca into master Oct 25, 2026
5 of 8 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 25, 2026
…e debugger design (#497) (#1535)

Both designs were approved as written by the owner on 2026-10-25 and are
finalized together as one 1.5.0 implementation program (split and
debugger interleaved, module by module).

- 1.5.0-session-api.md extends docs/design/1.5.0-workspace-and-engine-api.md
  (the #595 RFC): section 11 Q1-Q8 are decided per the recommendations
  recorded there, with a decision record in section 12. Q4: the syntax
  surface is tier-B api::syntax view types; the internal Ast is not
  frozen into tier A. Q5: the threading contract is explicitly
  single-threaded, one Session per thread.
- debugger-full-design.md extends docs/design/debugger-m0.md (the #497
  M0 draft of record) and does not supersede it: section 14 Q1-Q5 are
  decided per the recommendations recorded there (Q1 stop at first
  command; Q2 session core built in-tree now, shaped for rubash-core;
  Q3 conditions stay full shell commands; Q4 trace via the xtrace fd
  machinery; Q5 engine-level injectable command stream), with the
  finalization recorded in section 15. Prerequisites P-1 (#1184 f4,
  PR #1522) and P-2 (#1511, PR #1527) are marked landed.

Docs only; no code changes.

Co-authored-by: 曹梦轩 <[email protected]>
@caomengxuan666
caomengxuan666 deleted the fix4/slice-sml branch October 30, 2026 01:41
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.

[bug] Cosmetic: invalid-regex [[ =~ ]] parse diagnostics differ (GNU names the operator, niu names ']]')

1 participant