Repository navigation
fix5 statelife: PIPESTATUS shape save/restore (#1525) + assignment procsub finalization (#1523) - #1550
Merged
Conversation
…d local scopes (rubash#1525) The PipestatusShape note and the status vector were not part of what temporary-assignment and function-local save/restore put back, so a scalar tempenv binding or a `local` shadow left the shape machine in the pre-command state: after `PIPESTATUS=99 true` the completion write froze on the stale Scalar shape and `declare -p PIPESTATUS` resurrected a ghost cell; a frame that did `local PIPESTATUS=7` restored the global cell but not its array shape. GNU's model (variables.c:6291 set_pipestatus_array; execute_cmd.c:4904 set_pipestatus_from_exit; variables.c:3536 assign_in_env binding tempenv vars into the separate temporary_env table, disposed via push_temp_var/pop_var_context): the completion write targets the cell visible at write time — a tempenv-bound builtin/function/null command evaluates the write against the temp cell (scalar temp: discarded; array temp: absorbed), then disposal restores the pre-command cell (shape and vector) exactly; a disk command never binds the tempenv in the parent, so the write lands in the real cell. Port that model onto the two save/restore funnels: - apply_temporary_assignments snapshots (shape, vector) under a reserved key before binding PIPESTATUS; the restore reinstalls both unless the name was promoted into a frame. - Scalar PIPESTATUS tempenv bindings bind a fresh scalar shadow (GNU's tempvar is a new cell, not an element-0 write into a live array); compound tempenv binds note the Scalar shape. - The simple-command funnel performs an absorbed write against the still-bound temp cell when no external dispatch ran, and suppresses the post-restore AST write for that command; execute_external marks the dispatch so external writes land. - Function-local save/restore stashes the same snapshot with the first save of the name; restore_function_locals reinstalls shape+vector after the typed cells; local promotion of a tempenv PIPESTATUS plants the pre-tempenv snapshot. - Inside a frame, an attribute builtin's value operand binds a fresh scalar cell and a bare operand creates a valueless local; the declaration note now records those shapes instead of the permanent bind's element-0 rule. Regression tests: tests/issue1525_pipestatus_shape_save_restore_regressions.rs (issue's two cases, live-vector preservation, external landing, compound absorption, function-call temp, local array roundtrip, ordinary-array control). Co-Authored-By: Muse Spark <[email protected]>
…ucting command (rubash#1523) `v=>(...)` bodies ran at the NEXT command's finish (or never, for a trailing assignment), ran twice, and a failing body killed the script with its own status. GNU forks the body at expansion time (subst.c:6362 process_substitute, extracting at subst.c:1311 extract_process_subst; assignment words expand inside subst.c:11349-11378 expand_word_internal), so the body belongs to the command that constructs it and its status is unobservable to the script. Root causes, all in the materialize/finish path: - The raw-word materializer rewrote by the metadata `target`, which is the RE-PRINTED span (token join normalizes e.g. `>&3` to `>& 3`), so its replacen silently missed and the cooked pass in expand_assignment_value materialized the same substitution a second time under a second key; the finish drained both. The raw pass now skips a substitution whose target is not verbatim in the word; the cooked pass — which scans the text it substitutes into — materializes it once. - Standalone assignments never reached the funnel finish: words-empty commands and word-form assignments route to execute_empty_words_command / execute_assignment_or_comment_ command, which now call the finish before recording status. - The finish propagated body errors and let execute_persistent_output_process_substitution clobber the enclosing command's exit_code (a body `exit 3` killed the script). Body errors are now discarded and the enclosing status is saved/restored across the finish; the body's own diagnostics still print, attributed by the ambient span, which is now the constructing command's own line. - The pending queue is insertion-ordered so multiple bodies finish in materialization (left-to-right) order. Regression tests: tests/issue1523_assignment_procsub_finish_regressions.rs (issue case: one body run at the constructing line with script rc 0; temp-prefixed form; two assignments on one line; a trailing assignment still runs; a failing body leaks no status; word-form sibling control unchanged). Co-Authored-By: Muse Spark <[email protected]>
Member
Author
集成复验账本(集成树:master a18e7d9 + 本片两 commit,门控配方实跑)拣选:簇两 commit 对当前 master 零文本冲突;一处语义适配——#1525 的快照编解码原按稠密
相邻分歧(非本片引入,master 既存,另行上报)继承 fd≥3 的写入在本树上不通: |
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.
Fixes #1525
Fixes #1523
Refs #1364
第五波 statelife 片:PIPESTATUS 形状状态的 save/restore(#1525)与赋值 RHS procsub 收尾(#1523)。#1364 的关单判定(硬门复验)结果以评论补入本 PR:①~④全绿且标量格 ⑤ 已修则改挂 Fixes #1364;⑤ 未修则保持 Refs,残余仅剩标量格
${PIPESTATUS[-1]}一形态。#1525 根因
ShellState.pipestatus_shape(Absent/LiveArray/Scalar/Valueless/ValuelessArray)门控完成写(set_pipestatus)与声明视图,但两条 save/restore 通道——tempenv 的 apply/restore 与函数 local 的 save/restore——只恢复格本身(env + typed cell),从不保存/恢复 shape 与pipestatus向量:标量临时绑定处置后 Scalar 形状残留,完成写被冻结、声明视图渲染出幽灵格。GNU 里 shape 与值同在一个 SHELL_VAR 对象里随pop_var_context/dispose_temporary_env整体重装(variables.c:6291 set_pipestatus_array、variables.c:3536 assign_in_env、execute_cmd.c:4904)。修复:(shape, 向量)快照经保留键
__RUBASH_PIPESSTATUS_STATE骑乘 tempenv previous 表与帧 local scope 两条通道(先例__RUBASH_TEMP_PATH伪条目);标量 tempenv 绑定对 PIPESTATUS 绑新鲜标量影子格;漏斗一在未发生外部 dispatch 时对仍绑定的临时格做吸收写并抑制二次写;帧内声明注记区分新鲜影子格与永久绑定的元素-0 规则。#1523 根因
同一 procsub 被物化两次:raw 通道的
replacen用重打印后的跨度去匹配原始词、静默未命中,cooked 通道随后再次物化,收尾把体跑两遍;独立赋值根本不经漏斗收尾(体在下一命令的收尾里排空、借用其行号与状态,尾随赋值永不运行);收尾以?传播体错误——体的exit会杀死脚本并覆写外围exit_code。GNU 在展开时于构造命令内 fork 体(subst.c:6362 / 1311 / 11349-11378),体状态对脚本不可见。修复:raw 通道 target 非逐字命中时整条跳过(cooked 通道随后恰好物化一次);两个独立赋值路径在记录状态前接入收尾;收尾保存/恢复外围
exit_code、体错误就地丢弃;排空队列改插入序(多体按物化左→右序)。集成侧适配(一处)
与已合入的 r3 片(#1539,PIPESTATUS 稀疏表示
Vec<(i64, i32)>)同域:本片快照编解码原按稠密&[i32]写就,集成时改为稀疏对编码Shape|i0:v0,i1:v1,...——快照若把稀疏向量稠密化,恢复时会把未设置元素以 0 复活(${!PIPESTATUS[@]}下标面可观察)。调用点不变,仅src/shell/state.rs编解码对适配,已折入 #1525 的 commit。已知残差(簇报告在案,未扩面)
a=(9 9); a=99 declare -p a:GNU 为独立表里的新鲜标量影子格),与 PIPESTATUS 同根、属全体 tempenv 建模,处置后状态一致;本片仅按名对 PIPESTATUS 影子化。execute_assignment_or_comment_command中途展开失败的return Err)不经收尾,条目延后到后续命令的收尾排空——计数仍恰一次,时机/行号为旧行为。验证
集成树(master a18e7d9 + 本片两 commit)门控复验账本以评论补入:lib 基线、issue1363 全量(含 R3 钉与
prefixed_local_assignment_in_function_keeps_value)、issue1364 12/12、issue1523 6/6、issue1525 8/8、z2 PIPESTATUS 40 例矩阵、标量格PIPESTATUS=99; echo ${PIPESTATUS[-1]}专项、15 条场景探针、246 差分稳定集、两 commit 各自独立构建、fmt/CR。