Skip to content

fix(executor): evaluate already-expanded indexed subscripts without re-expansion (Refs #3522) - #3608

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3522-indexed-backquote-unset
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3522-indexed-backquote-unset

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

x='echo 1'; unset 'a[${x}]' silently removed a[1] (rc 0) where GNU fails
"operand expected" (rc 1, element survives).

Root cause

GNU arrayfunc.c:1353-1391 array_expand_index -> subst.c:3981
expand_arith_string runs its single expand_word_internal pass on the
subscript text as received; text a parameter expansion produces is data,
never re-scanned for command substitution (evalexp then fails it as
"operand expected", expr.c:1120). Rubash ran that pass twice for
Raw/ExpandedOnce subscripts: resolve_array_subscript expanded ${x} to
backquote text, then eval_indexed_subscript_expression ran
expand_arithmetic_subscript_mut on the result and executed it.

Fix

eval_indexed_subscript_expression takes an expand: bool gate:

  • false — the text already went through the single
    expand_subscript_string pass (Raw / ExpandedOnce subscripts and the
    ${}-pattern path): evaluate the resolved text as-is.
  • true — the text is still raw (Protected / verbatim subscripts from
    assignments, W_ARRAYREF operands and test -v, and the compound-declare
    paths): this IS the single pass.

array_expand_once (AV_NOEXPAND) skips the pass either way and only
restores carrier markers.

Deletion

No product paths deleted; only the re-expansion gate changed (3 call sites
take the new expand argument, plus 1 new expand binding in
eval_indexed_subscript).

Verification

Note: the #3573 and #3493 pin stems do not exist in this tree, so those two
neighbor legs could not be run here; they are owed by their own lanes.

Known residuals (out of scope, not fixed here)

Refs #3522

…e-expansion (Refs #3522)

GNU arrayfunc.c:1353-1391 array_expand_index -> subst.c:3981
expand_arith_string runs its single expand_word_internal pass on the
subscript text as received; text a parameter expansion produces is data,
never re-scanned for command substitution. Rubash ran that pass twice
for Raw/ExpandedOnce subscripts — resolve_array_subscript expanded
`${x}` to backquote text, then eval_indexed_subscript_expression ran
expand_arithmetic_subscript_mut on the result and executed it — so
`x='`echo 1`'; unset 'a[${x}]'` silently removed a[1] (rc 0) where GNU
fails "operand expected" (rc 1, element survives). Protected (verbatim)
subscripts from assignments, W_ARRAYREF operands and `test -v` still
take the single pass here (for them it IS the expand_arith_string
pass), as do the compound-declare paths; the `${}`-pattern path and
all Raw/ExpandedOnce callers now evaluate the resolved text as-is.

Pin: tests/issue3522_unset_indexed_backquote_subscript.rs (22 cells;
9 fail-first red on base, 13 controls green on base and head).
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT s1】

PR #3608 第1轮 — 建议:PASS
head: 5128fec base(merge-base): 1171989 文件: 4 个 +358/-28
关联 issue: #3522(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • eval_indexed_subscript_expression 新增 expand: bool 门控:Raw/ExpandedOnce(resolve 已跑过单次 expand_subscript_string)走 expand=false 不再二次展开;Protected(verbatim,如 a[$x]=v)与两处 compound-declare 路径 expand=true(此处才是 GNU 的 expand_arith_string 单遍)。对照 GNU 源码成立:arrayfunc.c:1356-1390 array_expand_index — (flags & AV_NOEXPAND)==0 时仅跑一遍 expand_arith_string 后 evalexp;subst.c:3981-4041 expand_arith_string 对入参只跑一遍 expand_word_internal(参数展开产物为数据,不重扫命令替换)。4 个调用点语义一致:eval_indexed_subscript 按 matches!(source, Protected) 取门、parameter_patterns.rs:650 Raw→false、两个 compound 路径→true(三重展开面,与 compound-declare 三重展开:错误 token 泄漏 PUA 载体且空数组被创建(GNU 未赋值) #3613 证据一致)。deferred &self 变体本就不经此函数,无双展开问题。
  • diff 里可疑/无关改动:无。

腿(逐项给数字与名字):

  • 钉自跑 head:issue3522_unset_indexed_backquote_subscript 22 passed / 0 failed
  • fail-first:base(1171989) 上 13 passed / 9 failed,红名 = {unset_backquote_text_via_braced_parameter_fails, unset_backquote_text_via_unbraced_parameter_fails, unset_backquote_text_via_nameref_braced_parameter_fails, unset_backquote_text_in_compound_arithmetic_via_parameter_fails, unset_backquote_text_after_plus_via_parameter_fails, unset_backquote_invalid_output_via_braced_parameter_fails, unset_command_substitution_via_braced_parameter_fails, unset_dollar_name_via_braced_parameter_fails, unset_arith_substitution_via_braced_parameter_fails},与 PR 声称的 9 名逐名一致
  • lib 双边:head 失败名集 {issue2084_session_end_restores_host_process_state} / base 失败名集 {issue2084_session_end_restores_host_process_state} / 差集 ∅(两侧同败,env-bound:consumer_tests.rs:712/782 host-env 检查,非本 PR 账)
  • -D warnings:lib+bins rc0 零警告;--tests 目标在 tests/issue2473_procsub_operand_marker_regressions.rs:29 报既存 unused import(base 同存,基线警告,非本 PR 引入)
  • 卫生:rustfmt --check PR 4 文件 clean(cargo fmt 本机 os error 206,改用 rustfmt 逐文件);marker-lint OK (117 consts / 268 sites);utf8-hygiene clean
  • CI:3 红任务逐个归因 — "GNU regression goldens and canaries"、"Rust tests"、"Rust tests (macOS)" 各只红 1 名 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:2911 签名)= 已知基线,非本 PR 账;其余任务全绿
  • GNU 对照:WSL GNU bash 5.3.20(1)-release(脚本存 target/audit-s1/probe3522*.sh):x='\echo 1`'; unset 'a[${x}]' → GNU rc1 token \echo 1` 数组不变 / 本 PR 同形全同;x='$y'→token $y;x='$((1+1))'→token $((1+1));unset 'a[1+${x}]'→token `echo 1`;nameref 面同;a[${x}]=NEW 两侧均 rc1 token `echo 1`;直接 `a[`echo 1`]` 两侧均删元素 rc0。master 复现缺陷:静默删元素 rc0。
  • 邻居钉:issue3521 9/4、issue2657 6/4、issue2946 8/0、issue3024 23/0、issue3343 12/0 — 3521/2657 各 4 红均为 argv0 前缀断言(钉里 arg0("bash") 仅 cfg(unix),Windows 下 argv0=exe 路径),base 上同名同红,diff ∅,env-bound 非本 PR 账
  • 关单词扫描:标题/正文仅 "Refs [bug] unset 索引数组反引号键静默 rc 0,GNU 为 rc 1(#3493 残差) #3522",无 close/fix/resolve+编号同句

F 点:无

续作记录:本轮未动代码

未跑/VOID 的腿:PR 自述 #3573/#3493 邻居钉在本树不存在(正文已声明),由各自车道补;macOS/Linux 专属行为待队长 Linux oracle 复核(本机 Windows+WSL 5.3.20 已逐形对照一致)

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 07:04
@caomengxuan666
caomengxuan666 merged commit 4e2c529 into master Nov 16, 2026
8 of 11 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT s1 批次汇总】

本批 2 PR 审结:

PR 判词 处置
#3608 建议 PASS 已 ready→squash 合入(4e2c5291),#3522 已关
#3629 建议 PENDING 机制/钉腿全证,但 post-4e2c529 与 master 文本冲突(src/executor/arithmetic/mod.rs),未合未关,待作者 rebase

调度问题答复:#3608 机制与 #3590 arith_grade 分流是否互斥、可否先后落地?

不互斥,可先后落地。两 PR 改的是 array_expand_index 模型的两个正交轴:

文本重叠仅在 eval_indexed_subscript 一处约 2-3 行(#3608 的 let expand = matches!(source, Protected) 行与 #3590 把 resolve_array_subscript 换成 resolve_indexed_subscript 的调用行相邻),语义组合平凡:先取 expand 门、再用 arith-grade resolver、eval 带门走。#3590 后落地者做一次小 rebase 即可(#3608 已先落地,#3590 需在 post-4e2c529 上重放)。#3629 rebase 后亦与两者正交(其 decode 在 expand_arithmetic_subscript_mut 入口与 AV_NOEXPAND 臂,#3590 不触该函数)。

env-bound 备忘:本机 lib 全程有 issue2084_session_end_restores_host_process_state 单红(两侧同现,非任一侧账);issue3521/issue2657 邻居钉在 Windows 各 4 红(argv0 前缀断言,cfg(unix)-only 的 arg0("bash")),双侧同红。

caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
Keep both mechanisms in eval_indexed_subscript: #3608's expand gate
(Protected subscripts still take the single eval-time expansion pass)
and #3590's arith-grade resolve dispatch (resolve_indexed_subscript /
expand_arith_string, no tilde — arrayfunc.c:1368).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…#3613)

Conflict: src/executor/arithmetic/mod.rs only. #3608 (4e2c529)
replaced the two-state array_expand_once gate in
eval_indexed_subscript_expression with the three-state `expand` split,
so the #3613 carrier decode moves into the `else if array_expand_once`
arm (AV_NOEXPAND: text stays verbatim for evalexp) and stays at the
expand_arithmetic_subscript_mut entry (the expand_arith_string pass
must re-lex decoded bytes). #2701's `${...}` fatal latch from master
now reads the decoded text — that is what GNU's expand_arith_string
(arrayfunc.c:1368 -> subst.c:3981) re-reads.

Both pin stems green after the merge: issue3613 4/4,
issue3522_unset_indexed_backquote_subscript 22/22, issue2701 12/12.
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…xpand (Refs #3613)

Advance the branch onto the current master tip so the #3608 expand-gate
merge below applies cleanly and the CI matrix runs on today's base.
Conflict-free: master's new commits touch parser/read/tests only.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】s1 批次汇总(清单:#3608、#3629)

逐 PR 结果

PR 结果 证据
#3608 不在本轮重审(上一轮已审+已合,squash 4e2c529,head 5128fec,关联 #3522 已关)。本轮只做「与 #3590 的机制互斥性」判定,见下节。 gh pr view 3608 state=MERGED, mergeCommit 4e2c529
#3629 已合(squash 354064e,head 4c28cbe,合并时点 head 与审计时点一致)。冲突已解,全腿在解冲突后的 head 上复证;关联 #3613 已随合并自动关单(reason=completed),补了落地 SHA + 钉计数评论。 报告:#issuecomment-6914693302;落地:#issuecomment-6914716917

#3629 合流明细:只改了 src/executor/arithmetic/mod.rs 的两处冲突(#3608 把 array_expand_once 二态门换成 expand 三态门;#3613 的 decode 移进 else if array_expand_once 臂,且解码发生在 master 新增的 #2701 ${...} latch 之前)。两次 merge(242085a9、4c28cbe0)都保留已推送历史,没有 force-push。合并后 origin/master 354064e 本地重建 + 复跑:issue3613 4/4、issue3522 22/22、issue2701 12/12,GNU 对照 a/b/d/f 字节一致。

CI 归因:4 个红 job 中 3 个只红 issue2875(已知基线);Regression pin stem census 的 97 名里有 96 名与 master 同类 run 逐格相同(scripts/ci-pin-exclusions.txt 记录的已知红普查基线),唯一多出的 issue2771_..._reaches_global_cell 是 SECONDS 墙钟钉的 TIMING flake(断言 sleep 1 后读 101,负载下读 102),与 PR 4 文件无关。无本 PR 引入的红。


硬性必答:#3608 的 expand 门 与 #3590 的 arith_grade 分流 是否互斥、能否先后落地、顺序

结论:不互斥,可先后落地;顺序应为 #3608 先(已落地 4e2c529),#3590 在其上 rebase/合流。反向顺序机械上也成立,但要多写一遍 #3608 的门,无语义收益。

1) 两者是不同的轴,不共享不变量

  • fix(executor): evaluate already-expanded indexed subscripts without re-expansion (Refs #3522) #3608 = eval 期的「要不要跑那一遍」:eval_indexed_subscript_expression(resolved, expand: bool),三态——
    • expand && !array_expand_once → 调 expand_arithmetic_subscript_mut(这一遍就是 GNU arrayfunc.c:1368 的 expand_arith_string);
    • array_expand_once(AV_NOEXPAND,arrayfunc.c:1368 的 else 支)→ 文本原样交给 evalexp,只还原 carrier;
    • 其余 → resolved 直通(调用方已跑过那一遍)。
      它管的是 when:GNU 的那一遍是否在 eval 时再跑(arrayfunc.c:1356 array_expand_index、1366-1368;subst.c:3981 expand_arith_string)。
  • fix(unset): resolve indexed subscripts arith-grade, keep the raw ~ #3590 = resolve 期的「用哪种展开口味」:indexed 站点改走 resolve_indexed_subscript → expand_subscript_string_arith(跳过前导 ~ 的 tilde 步),assoc 保留 expand_subscript_string(做 tilde)。GNU 依据:expand_arith_string 在 subst.c:4006 设 td.flags = W_NOPROCSUB|W_NOTILDE;expand_subscript_string(subst.c:11063)在 subst.c:11077 设 W_NOPROCSUB|W_NOSPLIT2(无 W_NOTILDE),tilde 参数在 subst.c:11420/11451/11475 的 W_NOTILDE 判断处放行。
    它管的是 which flavour:同一遍 pass 里 tilde 做不做,外加跨 pass memo 的 grade tag。

2) 合流证据(不是推断)

3) 给调度方的执行建议

阻塞/遗留

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