Repository navigation
fix(executor): sparse PIPESTATUS representation (rubash#1364 R3) - #1539
Merged
Merged
Conversation
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).
This was referenced Oct 25, 2026
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。
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 #1364(本片落地 R3 稀疏表示;#1364 剩余面为形状 save/restore 家族,已另行立案 #1525,由 statelife 簇处理,故此处只 Refs 不 Fixes,待 #1525 落地后再议 #1364 关单。)
内容
PIPESTATUS 的内部表示由稠密
Vec<i32>迁移为稀疏条目Vec<(i64, i32)>(下标升序、唯一),写入器按 GNUvariables.c:6291 set_pipestatus_array算法直译:空数组按下标插入、count == 1 && nproc == 1快速路原地替换保下标、count <= nproc按下标序原地替换 +array_insert写到位置下标、count > nprocflush 稠密重建。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 的两处同族修复(实施中实测发现)
$((PIPESTATUS[i]))原经env_vars镜像读数,而完成写入器从不写镜像——master 上连稠密管道的$((PIPESTATUS[1]))都恒读 0(GNU=1)。沿ArithDynamicContext既有先例,快照带条目、左值读先查快照,稠密算术读一并转正。unset PIPESTATUS[2]后状态条目残留,unset 自身的完成写入会把新 status 写回已删下标(实测([2]="0"),GNU 为([0]="0"))。在unset_array_element索引分支与@/*flush 分支对 PIPESTATUS 同步状态。回归钉
#[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 环境项)。1364.sh/1364b.sh与 GNU 逐字相同;稀疏探针 26/26。wait -n竞态 flake,非本簇回退)。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(基线环境项),无回退。1364.sh/1364b.sh与 GNU 逐字相同。wait -n时序 flake(part_036 同族,master 基线与簇内运行均有记录),隔离复跑 8 次中 5 过,定谳为 flake 非本片回退;稳定集 ⊆ {gl08, ms10} 成立。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 或形状机后续片一并处理。