Skip to content

fix5 statelife3: assignment procsub value materialization (#1561) + PIPESTATUS indirect first-touch (#1566) - #1575

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix5/slice-statelife3
Oct 25, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix5/slice-statelife3

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1561
Fixes #1566

第五波 statelife3 簇集成片:两条状态生命周期残余修复,各一个 commit,自 statelife3 簇分支按序拣入当前 master(533cb4cf,零冲突;簇基线里的 #1555/#1556 cherry-pick 已随 #1570 合并,未重复拣入)。

#1561 — 赋值形 procsub 的值停留在字面文本

v=>(echo BODY >&2); echo "v=[$v]" → GNU v=[/dev/fd/63],rubash v=[>(echo BODY >&2)]:body 恰好执行一次(#1523 收尾契约成立),只有值从未被拼接。根因在元数据扫描 process_substitutions_in_word_with_raw 构造的 ProcessSubstitution.target 是 token 再版印(>& 2),与原文 span(>&2)不一致时,raw 与 cooked 两个赋值物化通道都按目标串拼接、静默落空。

修复:src/parser/process_substitution.rs 新增 verbatim_process_substitution_span(引号/转义感知走查定位原文 span,命中须通过「其 body 再版印 == 元数据 source」身份校验);两个物化函数共用 assignment_procsub_splice_range 按游标精确 → verbatim → 从 0 的顺序找拼接范围,以字节范围 splice。raw 通道找不到仍 continue 不注册(#1523 exactly-once 原样保留);heredoc body / case…esac 等异形 span 验证不过时保持旧行为,不构成回退。

本片同时激活 tests/issue1557_inherited_fd_regressions.rs 中预留的 #[ignore] 钉 issue1557_inherited_fd_procsub_value(GNU 期望;v=>(echo BODY >&3) 正是再版印发散形),并新增 issue1561 套件 9 测。

#1566 — ${!PIPESTATUS[@]} 首次触碰误报 invalid indirect expansion

${!PIPESTATUS[@]} 作为对 PIPESTATUS 的第一次触碰 → invalid indirect expansion、rc=1;未设名 ${!no_such[@]} 同样误报(GNU 给空列表 rc=0)。展开腿本身是对的,错在词错误扫描 indirect_parameter_word_error 的存在性预言机只查 env 两张表,而 PIPESTATUS 的数组格活在 shell_state 的稀疏向量 + pipestatus_shape 里,三条腿全误判缺失抢先致命报错。

修复(全在 src/executor/parameter_errors.rs,另两处数值目标臂):新增 pipestatus_cell_exists(shape != Absent 即存在,与 GNU 懒创建时间线对齐),plain/operator/下标三腿各加这一来源;纯 keys 形([@]/[*] 恰好闭合整个 body)整体跳过 base 存在性报错(带 operator 尾不算纯 keys 形,报错保留);标量形/operator adjudication 改经状态格取值。另补数值目标再展开的两处 $0 缺口:PIPESTATUS element 0 几乎总是 0,目标 0 指 $0——expand_braced_special 数值臂原以 saturating_sub(1) 把 0 读成 $1,indirect_target_values 则完全没有数值目标臂;两处补 index==0 → script_name_value()。真非法形态(${!no_such}、${!no_such[0]}、${!no_such[@]:-d}、字面第一命令的 ${!PIPESTATUS})逐字保留报错。

新增 issue1566 套件 12 测,期望全部按 GNU bash 5.3.20 实测。

验证账本(簇侧,集成树复验随后以评论补入)

  • 簇侧(净化环境):issue1561 9/9、issue1566 12/12、issue1557 14/14(原 13 + 本片激活钉)、硬门 1523 6/6、1363 21/21、1364 12/12;lib 732 过 / 1 败(仅 root 环境既有 ownership_unary_operators_check_existing_file);246 差分 244 过、失败集 {gl08, ms10}。
  • 集成树复验:见本 PR 后续评论。

…m span (rubash#1561)

A standalone assignment whose RHS is a process substitution kept
the literal span text as the value whenever the body's token-join
re-print diverged from the verbatim text (`>&2` re-prints as
`>& 2`; pipes, `;`, quoted redirect targets likewise). GNU
extract_process_subst (subst.c:1311) pulls the span verbatim from
the word string and process_substitute (subst.c:6362) splices the
/dev/fd result; assignment words receive process substitution
exactly like argument words (expand_word_internal,
subst.c:11349-11378).

Both assignment materialize channels spliced by the re-printed
metadata target and silently missed. They now share a splice-range
search: exact match at a cursor, then verbatim location verified
against the source re-print (new parser helper
verbatim_process_substitution_span, parse_matched_pair rules via
embedded_procsub_close), then from-zero retries covering metadata
order differing from word order. The raw channel still registers
only when the splice lands (rubash#1523 exactly-once is
preserved); the cooked channel keeps its register-on-miss
behavior, and exotic bodies that fail verification keep the old
outcome.

Regression: tests/issue1561_assignment_procsub_value_regressions.rs
(9 tests, GNU bash 5.3.20 expectations); activates the previously
#[ignore]d pin issue1557_inherited_fd_procsub_value. Gates:
issue1523 6/6, issue1557 14/14, lib 732 pass / 1 baseline fail,
246 differential failures {gl08, ms10} (stable set).
…#1566)

The keys form ${!PIPESTATUS[@]} as a first touch — and the plain,
element, and operator indirection forms after any command —
reported "invalid indirect expansion" and aborted the command.
The word error scan's existence oracle consulted only env_vars
and the variable table, but the PIPESTATUS array cell lives in
shell_state (set_pipestatus_array, variables.c:6291, writes the
ARRAY object directly); the keys expansion leg itself was already
state-aware and never got to run.

GNU parameter_brace_expand (subst.c:10016-10047) dispatches the
pure ${!name[@]} / ${!name[*]} keys form to array_keys before
parameter_brace_expand_indir ever runs, so that form never
validates the base: an absent name yields the empty key list,
even under set -u.

- New pipestatus_cell_exists: PIPESTATUS counts as existing
  whenever its shape is not Absent (GNU's lazy-creation timeline:
  materialized by the first completed command). Wired into the
  plain leg's source_found, the operator-tail existence check,
  and both base_exists arms of the subscript leg.
- The pure keys form (the [@]/[*] group closes the body) skips
  the base-existence error entirely; an operator tail after the
  group keeps the error, as GNU does.
- indirect_source_scalar_value reads PIPESTATUS element 0 from
  the state cell; indirect_parameter_operator_value and the
  [@]-operator t-join scan adjudicate PIPESTATUS through the
  same sources (yielding GNU's "0 1: invalid variable name" for
  ${!PIPESTATUS[@]:-d} after a pipeline).
- Numeric indirect targets: index 0 designates $0, which lives
  outside the $1.. positional window — the plain leg's numeric
  arm read $1 via a saturating subtraction, and
  indirect_target_values had no numeric arm at all, so a
  PIPESTATUS indirection's target ("0") looked unset to the
  operator adjudication. Both now resolve $0 through
  script_name_value (subst.c:7955 re-expansion), with the plain
  leg's leading-zero guard mirrored.

Genuine error forms are unchanged: ${!no_such}, ${!no_such[0]},
${!no_such[@]:-d}, and a literal first-command ${!PIPESTATUS}
still error byte-identically to GNU.

Regression:
tests/issue1566_pipestatus_indirect_first_touch_regressions.rs
(12 tests, GNU bash 5.3.20 expectations). Gates: issue1363
21/21, issue1364 12/12, issue1555 12/12, issue1556 13/13,
lib 732 pass / 1 baseline fail, 246 differential failures
{gl08, ms10} (stable set).
@caomengxuan666

Copy link
Copy Markdown
Member Author

集成树复验(PR 开后补入)

基线 master 533cb4cf,集成分支 tip 76466ab3。只拣两 commit、零冲突:3cbe53c8(#1561)→ 1b0fb007、bf233b13(#1566)→ 76466ab3(parameter_errors.rs 为相邻面自动合并);簇基线里的 #1555/#1556 cherry-pick 未重复拣入。总 delta 9 文件 +627/−17,与簇侧两 commit 之和逐项吻合;署名三处均为曹梦轩。推送后 gh api 核实远端分支 sha = 本地 HEAD。

门控复验(净化环境,剥离全部 JARVIS_*;构建配方 RUSTFLAGS="-C debuginfo=0" CARGO_BUILD_JOBS=1 CARGO_INCREMENTAL=0):

  • build --locked ✓(1m48s)。
  • 定向回归(全 0 ignored):issue1557 14/14(原 13 + 本片激活的 [bug] 独立赋值右值为整个 >(…) 时变量保持字面、不回填 /dev/fd 路径 #1561 钉 issue1557_inherited_fd_procsub_value);issue1561 9/9;issue1566 12/12;硬门 issue1523 6/6、issue1525 8/8、issue1363 21/21、issue1364 12/12;第二基线套件 issue1555 12/12、issue1556 13/13 不回退。
  • lib 全量(--skip login_posix_env,既有栈溢出体质):732 过 / 1 败 / 1 ignored,唯一败 = ownership_unary_operators_check_existing_file(root 环境基线项),与当前 master 基线逐项一致。
  • z2 矩阵 40/40。
  • 246 差分(全新沙箱副本、假 HOME + workspace 符号链接、RUBASH 指本树二进制、results-rubash.json mtime 验新鲜):244 过,失败集恰 {gl08, ms10} = 稳定集。
  • fmt:9 个改动 .rs 文件逐个 rustfmt --check 干净;CR 计数全 0;src/lexer/continuation.rs 零 diff;载体字节未涉。

无超预期红项,无新残余。 合并归主会话把关。

@caomengxuan666
caomengxuan666 merged commit e8b6546 into master Oct 25, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix5/slice-statelife3 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

1 participant