Skip to content

fix(executor): sparse PIPESTATUS representation (rubash#1364 R3) - #1539

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix5/slice-r3
Oct 25, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix5/slice-r3

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Refs #1364(本片落地 R3 稀疏表示;#1364 剩余面为形状 save/restore 家族,已另行立案 #1525,由 statelife 簇处理,故此处只 Refs 不 Fixes,待 #1525 落地后再议 #1364 关单。)

内容

PIPESTATUS 的内部表示由稠密 Vec<i32> 迁移为稀疏条目 Vec<(i64, i32)>(下标升序、唯一),写入器按 GNU variables.c:6291 set_pipestatus_array 算法直译:空数组按下标插入、count == 1 && nproc == 1 快速路原地替换保下标、count <= nproc 按下标序原地替换 + array_insert 写到位置下标、count > nproc flush 稠密重建。

  • src/shell/state.rs:pipestatus 字段改稀疏条目,文档注明不变量与读语义。
  • src/executor/public_accessors.rs:set_pipestatus 直译 C 算法(形状门不变、签名不变,调用点零改动);note_pipestatus_assignment 改逐下标同步(去除原稠密化填零孔洞);新增 pipestatus_entries() / pipestatus_element()(按下标解析、负下标对最大下标、孔洞静默)/ pipestatus_subscript_resolves()(诊断姿态判据)。
  • 读路径全面按下标走:declare -p 渲染真实下标(([2]="0"))、${!PIPESTATUS[@]} 与切片经存储形看到真实下标、${PIPESTATUS@A} 同步。
  • src/executor/prompt_command.rs:PROMPT_COMMAND 回滚在 LiveArray 格整组拷贝恢复(含下标,同 restore_pipestatus_array);其余形状仍走 set_pipestatus 保留形状门。

同 commit 的两处同族修复(实施中实测发现)

  1. 算术下标读镜像缺口:$((PIPESTATUS[i])) 原经 env_vars 镜像读数,而完成写入器从不写镜像——master 上连稠密管道的 $((PIPESTATUS[1])) 都恒读 0(GNU=1)。沿 ArithDynamicContext 既有先例,快照带条目、左值读先查快照,稠密算术读一并转正。
  2. 元素 unset 不同步状态:unset PIPESTATUS[2] 后状态条目残留,unset 自身的完成写入会把新 status 写回已删下标(实测 ([2]="0"),GNU 为 ([0]="0"))。在 unset_array_element 索引分支与 @/* flush 分支对 PIPESTATUS 同步状态。

回归钉

  • bf-a 的 R3 占位钉摘除 #[ignore] 已激活;新增 3 条稀疏钉(写入器 grow/shrink、按下标读、稀疏元素 unset)。tests/issue1363_pipestatus_family_regressions.rs 共 21 条全过。

验证账本

簇内(基线 afe14d4,门控配方):

  • cargo build --locked 通过;lib 测试 730 passed / 1 failed / 1 ignored,唯一失败 ownership_unary_operators_check_existing_file 与 master 基线逐名一致(root 环境项)。
  • issue1363/1364 回归 21/21(0 ignored);z2 40 例矩阵同名口径 40/40(原始比对 38/40,两例仅差 argv[0] 诊断前缀,同名复跑逐字相同);1364.sh/1364b.sh 与 GNU 逐字相同;稀疏探针 26/26。
  • 246 差分 244/246,失败集恰为稳定集 {gl08, ms10}(中途一跑 ps06 隔离复跑 5/5 通过,既有 wait -n 竞态 flake,非本簇回退)。
  • fmt 改动文件逐个干净;CR 计数 0。红线:continuation.rs、var_table.rs/variable_state.rs([perf] "${a[@]}" iteration is O(n²): 40k elements take 516s (GNU 0.24s) #1510 本体)零改动。

集成复验(cherry-pick 到当前 master 3962566,commit e534768,diff 与簇 commit 逐字一致;门控配方同簇内):

  • cargo build --locked 通过;lib 测试 730 passed / 1 failed / 1 ignored,唯一失败仍为 ownership_unary_operators_check_existing_file(基线环境项),无回退。
  • issue1363 回归 21/21(R3 钉激活、0 ignored);issue1364 回归 12/12。
  • z2 矩阵:原始比对 38/40(两例仅 argv[0] 诊断前缀差),同名口径复跑该两例逐字相同 → 40/40。1364.sh/1364b.sh 与 GNU 逐字相同。
  • 246 差分:失败集 {gl08, ms10} + ps06;ps06 为既有 wait -n 时序 flake(part_036 同族,master 基线与簇内运行均有记录),隔离复跑 8 次中 5 过,定谳为 flake 非本片回退;稳定集 ⊆ {gl08, ms10} 成立。
  • fmt 改动 11 文件逐个干净;CR 计数全 0;集成 diff 再次确认 continuation.rs、var_table.rs、variable_state.rs 零改动。

已知残差

附带观察(先行分歧、非本片引入,未修):标量格 PIPESTATUS=99 下 ${PIPESTATUS[-1]}——GNU 报 bad array subscript 并读空(VT_VARIABLE 规则),rubash 经动态快速路径的稠密回退返回标量值 99 且无诊断。普通标量变量同形在 rubash 与 GNU 一致(已验 x=99),故缺口仅在 PIPESTATUS 标量格的动态腿姿态,属形状机家族而非稀疏表示,建议随 #1525 或形状机后续片一并处理。

The PIPESTATUS cell state was a dense Vec<i32>, so a sparse element
assignment (`PIPESTATUS[2]=5`) collapsed to index 0 and every read
renumbered the cell. GNU keeps a real ARRAY object whose writer
preserves indices; port that model (variables.c:6291
set_pipestatus_array over the ARRAY object, array.c:516
array_insert):

- ShellState.pipestatus is now Vec<(i64, i32)> — (index, status)
  entries in ascending index order, unique indices.
- set_pipestatus is a direct port of the C writer: empty array ->
  dense insert at 0..n; count <= nproc -> replace existing elements
  in index order, then array_insert the remaining statuses AT their
  indices (an insert landing on an occupied index replaces it, so a
  sparse cell keeps its indices and its count can stay below the
  status count); count > nproc -> array_flush + dense rebuild.
  The PipestatusShape gate (scalar/valueless frozen, absent
  recreated) is unchanged.
- Bind-path syncs (note_pipestatus_assignment,
  array_assignment_exec) copy the stored entries index-for-index
  instead of densifying with zero-filled holes.
- Reads resolve BY INDEX (arrayfunc.c array_reference): $PIPESTATUS
  and arithmetic read element 0 (unset on a sparse cell, never the
  first stored entry); element fetches resolve negative subscripts
  against the MAXIMUM index, with the bad-array-subscript diagnostic
  only when the resolution falls below zero (INDEX_ERROR posture);
  declare -p, ${PIPESTATUS[@]}, ${!PIPESTATUS[@]}, counts, slices
  and the storage render all carry the real indices.
- Arithmetic element reads consult a live-cell snapshot in
  ArithDynamicContext: the env mirror never carries pipeline
  results, so $((PIPESTATUS[i])) previously read a stale
  assignment-era value (or 0 even for dense pipelines).
- Element unset and unset 'PIPESTATUS[@]' remove entries from the
  state list together with the mirror, so the unset command's own
  completion cannot resurrect a removed index through the fast case.
- PROMPT_COMMAND rollback uses restore_pipestatus_array's wholesale
  array copy on a live-array cell (indices included) and keeps the
  writer-gated path for the frozen/absent shapes.

Regression: the bf-a R3 placeholder pin
(pipestatus_sparse_element_assignment_keeps_index) is un-ignored and
passing, joined by sparse writer grow/shrink, sparse read, and
sparse unset pins in tests/issue1363_pipestatus_family_regressions.rs
(21/21). z2 matrix 40/40 on the same-invocation-name basis (case 24
was the last real failure); 246-case differential stable at
{gl08, ms10}; lib baseline unchanged (730 pass, sole failure the
known ownership_unary_operators_check_existing_file).

Refs #1364. The remaining #1364 surface is the shape save/restore
family tracked as #1525 (statelife cluster).
@caomengxuan666
caomengxuan666 merged commit a18e7d9 into master Oct 25, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix5/slice-r3 branch October 30, 2026 01:41
caomengxuan666 added a commit that referenced this pull request Nov 9, 2026
…) (#3098)

Fixes #3050

extglob 组字面匹配器 `extglob_match_literal_with_case` 补齐与普通匹配器 `case_pattern_atom_matches` 同构的 CTLESC 臂:引号字面(`*` / `?` / 元字符 / PUA 值)在 extglob 组内按字面比较,不再整体失效。GNU 锚点 execute_cmd.c:3695-3729(QGLOB_CTLESC)、lib/glob/sm_loop.c:121-135。

队长复核 PASS(CAPTAIN-VERIFY.md):头钉 4/4、头 lib 1206/0/4、marker lint、fmt、diff 审计(2 文件,含同构性源码双向亲核)、GNU 探针 p1+p8 三方裁定、CI 10 pass + 1 skipping 全绿。五项腿(fail-first 独立复跑、lib 基底名集、-D warnings 显式带旗复跑、12 邻茎补齐、issue332 基底机械确认)因构建槽饥饿未跑、补跑进程被运行时杀死,按 #1538/#1539/#1540 累积证据先例合入,各节回滚条件在复核文件在案。唯一 GNU 分歧 MATCH8(引号 `[`)经三方探针裁定为基底既存分歧、非本 PR 回归,已另立残余单追踪;本 PR 顺带修好同族 `]` / `(` / `!` 三形。

本 PR 删除了什么:无删除。修法为 pattern.rs 新增一条匹配臂(+19/−0),测试新增 +111 行,净 +130/−0。
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