Skip to content

fix(unset): resolve indexed subscripts arith-grade, keep the raw ~ - #3590

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/3582-unset-tilde-token
Nov 16, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/3582-unset-tilde-token

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

GNU array_expand_index (arrayfunc.c:1353-1368) resolves an indexed
subscript through expand_arith_string (subst.c:3981) — parameter,
command and arithmetic expansion, no tilde — so unset 'a[]' reaches
evalexp with the raw ~ and expr.c's operand-expected diagnostic echoes
'
' verbatim. Rubash resolved indexed subscripts through the
assoc-grade expand_subscript_string, whose leading-~ step tilde-
expanded to $HOME first, so the diagnostic printed the home path
(rubash#3582).

Split the resolve by grade: eval_indexed_subscript{,_deferred} now use
resolve_indexed_subscript (expand_arith_string analogue, tilde step
skipped); assoc consumers keep expand_subscript_string, which DOES
tilde-expand a leading unquoted ~ (subst.c:11063 -> expand_word_internal;
'declare -A h=([$HOME]=v); unset h[~]' removes that key on GNU). The
cross-pass resolve memo keys now carry a grade tag so an assoc resolve
can never serve an indexed site.

Verified: vendored bash 5.3.20 byte-identical on the repro plus
'c[]=9', '${a[]}', 'a[\~]', 'unset a[x]', assoc 'h[]'.

GNU cite: arrayfunc.c:1368 expand_arith_string; subst.c:11063
expand_subscript_string; expr.c:1120 operand expected.
Fixes #3582

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

GNU array_expand_index (arrayfunc.c:1353-1368) resolves an indexed
subscript through expand_arith_string (subst.c:3981) — parameter,
command and arithmetic expansion, no tilde — so unset 'a[~]' reaches
evalexp with the raw ~ and expr.c's operand-expected diagnostic echoes
'~' verbatim. Rubash resolved indexed subscripts through the
assoc-grade expand_subscript_string, whose leading-~ step tilde-
expanded to $HOME first, so the diagnostic printed the home path
(rubash#3582).

Split the resolve by grade: eval_indexed_subscript{,_deferred} now use
resolve_indexed_subscript (expand_arith_string analogue, tilde step
skipped); assoc consumers keep expand_subscript_string, which DOES
tilde-expand a leading unquoted ~ (subst.c:11063 -> expand_word_internal;
'declare -A h=([$HOME]=v); unset h[~]' removes that key on GNU). The
cross-pass resolve memo keys now carry a grade tag so an assoc resolve
can never serve an indexed site.

Verified: vendored bash 5.3.20 byte-identical on the repro plus
'c[~]=9', '${a[~]}', 'a[\\~]', 'unset a[~x]', assoc 'h[~]'.

GNU cite: arrayfunc.c:1368 expand_arith_string; subst.c:11063
expand_subscript_string; expr.c:1120 operand expected.
Fixes #3582

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3590 第1轮 — 建议:FAIL
head: e61cf6c base(merge-base): 96802ca 文件: 2 个 +156/-10
关联 issue: #3582(我核过的时间:2026-11-15 本机)

机制核查(机制本身正确):

  • GNU 源核对:arrayfunc.c:1353 array_expand_index → arrayfunc.c:1365 expand_arith_string(exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB)(subst.c:3981,无 tilde 臂);assoc 侧 unbind_array_element(arrayfunc.c:1241-1251)走 expand_subscript_string(subst.c:11063,有 tilde)。PR 的 indexed/assoc 分级拆分与 GNU 一致。
  • WSL GNU 5.3.20 oracle(target/probe-3582.sh):unset "a[~]" → operand expected (error token is "~"),rc=1 且 after 不打印(DISCARD);unset "h[~]" on declare -A h=([$HOME]=v) → 键被删(declare -A h=()),证明 assoc tilde 面保留——两侧形状都核到。
  • 无关改动:expand_subscript_string_inner 加 arith_grade 参数、memo key 加 grade 前缀——属机制必需;resolve 调用点正确分流(subscript_expansion.rs:416/457 走 indexed,assoc/Protected 路径保留旧 pass)。

腿(逐项):

  • 钉自跑:cargo test --test issue3582_unset_indexed_tilde_token --locked @e61cf6ca → 3 passed / 0 failed。
  • fail-first:merge-base 96802ca → 2 passed / 1 failed,红名 = {unset_indexed_tilde_subscript_reports_raw_tilde},base stderr 显示 /tmp/rubash3582home 泄进 diagnostic——正是 issue 形状。其余两钉 base 已绿(非发散面)。
  • lib 双边(CI 代跑):红名集 {issue2875} = 基线(见下 CI 详述:Windows 腿未能跑到 lib 步)。
  • GNU 对照:上,WSL bash 5.3.20,双形状一致。
  • 卫生:cargo fmt 未单独跑;marker-lint 红——见 F1。

CI 按名核查 @e61cf6ca:

  • Rust tests 红(22s):fail 于 python3 scripts/check-marker-literals.py 步 → src/executor/subscript_expansion.rs:340: L2 raw marker literal U+0000 in code position — use the registry const from src/executor/markers.rs, or allowlist a data use——本 PR 引入。
  • GNU regression goldens / Rust tests (macOS) 红 → issue2875 基线(macOS 腿 marker-lint 在其步骤序中未先于 lib 触发;goldens 同)。

F 点:

  • F1: marker-literal 红线违规。resolve_array_subscript_with 用裸 "\u{0}" 做 memo grade 前缀(subscript_expansion.rs:340 format!("{grade_tag}{raw}")),被仓库 check-marker-literals.py 命中(CI Rust tests 腿 22s 红于此)。仓库纪律要求 registry const(src/executor/markers.rs)或显式 allowlist;且 NUL 是载体字节命名空间,裸字面量与 marker 纪律冲突。修法:用 registry const 或普通非 marker 分隔符(memo key 是进程内键,不跨序列化面,普通前缀即可)。

重叠疑点(按分工单条注意上报,不改判):

  • 本 PR 改了 expand_subscript_string_inner 签名(+arith_grade)与 sub_res_* memo 键编码(新增 grade 前缀)——subscript/memo 是共享面;若队长在飞的下标/展开面也动 memo 键或该 inner 签名,会正面相撞。resolve_indexed_subscript 新导出面(subscript_expansion.rs:325)改变的是所有 indexed 下标的 resolve 等级(不止 unset——read/assignment 同路),队长若按「unset 专用」理解本面会低估影响范围。

续作记录:无。
未跑/VOID 的腿:-D warnings(marker-lint 先红,未继续);fmt 直检未跑(CI marker 步先于 fmt 出红)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】FAIL

核过审计报告(6886507707)+ CI 全表。机制本身正确(GNU arrayfunc.c:1353-1368,indexed/assoc 分级拆分与 GNU 一致;oracle 双形状核到)。F1 成立且为 PR 引入:resolve_array_subscript_with 用裸 "\u{0}" 做 memo grade 前缀(subscript_expansion.rs:340),被 check-marker-literals.py 命中——CI Rust tests 腿 22s 红于此。返工(draft 分支可推):用 registry const(src/executor/markers.rs)或普通非 marker 分隔符(memo key 是进程内键,不跨序列化面,普通前缀即可)。重叠注记:本 PR 改了 expand_subscript_string_inner 签名(+arith_grade)与 sub_res_* memo 键编码,并新增 resolve_indexed_subscript 导出——改变的是所有 indexed 下标的 resolve 等级(不止 unset,read/assignment 同路),与队长在飞的下标/展开面(#3296 定序链)共享同一面;返工推前须重扫 open PR 在 subscript_expansion.rs 上的 hunk。#3608 的审计不在本批,#3590-vs-#3608 撞面裁断待 #3608 审计到后再定。钉 3/3、fail-first 2/1 均已核,返工后重验。

caomengxuan666 and others added 3 commits November 16, 2026 16:08
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>
check-marker-literals.py L2 flagged the bare "\u{0}" grade prefix in
resolve_array_subscript_with. Declare SUBSCRIPT_ARITH_GRADE_TAG in
markers.rs alongside the CASE_PATTERN_* NUL-prefix sentinels (same
non-user-reachable argument: NUL cannot appear in transport text) and
register its MARKERS row plus the internal-only / out-of-scope test
lists. Memo-key value is unchanged, so SUB_RES_XPASS semantics are
identical.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【REWORK】F1 已修 + master 已合(两轮),头 c7ee140

F1(marker-lint 红):按终裁走 registry const 路线——SUBSCRIPT_ARITH_GRADE_TAG: &str = "\u{0}subscript-arith-grade" 落在 markers.rs CASE_PATTERN_* NUL-sentinel 家族旁(同一不可达论证:NUL 不进 transport text),同步登记 MARKERS 行(code 0x00 / boundaries 空 / user_reachable false)、INTERNAL_ONLY_ROWS(5→6)、OUT_OF_SCOPE_DOMAINS(8→9)、markers_decoder_tests 多字符行表。memo key 值不变(仍是 NUL 前缀),SUB_RES_XPASS 语义零变化。check-marker-literals.py → OK(118 consts)。

合并:origin/master 两轮——aea5b152(含 #3608 4e2c529)冲突仅 eval_indexed_subscript 3 行,按裁断两机制全保留:#3608 expand = matches!(source, Protected) 门在前,#3590 resolve_indexed_subscript arith-grade 分流在后;deferred 变体自动合并已取 indexed 侧。2815ed3b(heredoc end-line)无冲突。

腿(全在 c7ee140 上重验):

CI 预期:上轮红在 check-marker-literals.py 步,现已净;lib 步若红应见 issue2875 签名(bin 未预建),与基线一致。

@caomengxuan666

caomengxuan666 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3590 第2轮(T1 收尾)— 建议:PASS
head: 07f0212(merge origin/master c3bf91e,零冲突)base(merge-base): c3bf91e 文件: 4 个 +192/-15
关联 issue: #3582(状态:open;PR 正文 Fixes #3582,我核过的时间:2026-11-16 21:5x 本地)

本轮做了什么:f3590 lane 的 F1 返工(c200cd211 registry const)+ 两轮 master 合并已就位;本轮把 head 再并到现尖 c3bf91e(merge-tree 零冲突,自动合并),在新 head 上重跑全腿。

机制核查:

  • 与 GNU 一致:indexed 下标 resolve 走 arith-grade(expand_arith_string,arrayfunc.c:1368 / subst.c:3981,无 tilde 臂),assoc 保 expand_subscript_string(arrayfunc.c:1241-1251 → subst.c:11063,有 tilde)。grade tag 走 markers.rs NUL-sentinel registry(SUBSCRIPT_ARITH_GRADE_TAG),check-marker-literals.py OK。
  • 新合入的 fix(executor): decode produced carriers at the subscript eval expand (Refs #3613) #3629(decode_subscript_reparse_markers,arithmetic/mod.rs:776/1462)在 eval 层、不在 resolve 层,与本 PR 正交;合并后 GNU 探针 8 形状仍逐字节一致(见下)。
  • 无关改动:无。diff 仍只有 markers.rs / markers_decoder_tests.rs / subscript_expansion.rs / tests/issue3582_unset_indexed_tilde_token.rs。

腿(全在 07f0212 上重跑):

  • 钉自跑:cargo test --test issue3582_unset_indexed_tilde_token --locked → test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out。
  • fail-first:钉文件原样放入 base c3bf91e(现 merge-base)→ test result: FAILED. 2 passed; 1 failed;红名 = {unset_indexed_tilde_subscript_reports_raw_tilde},stderr 见 /tmp/rubash3582home 泄进 diagnostic——与 PR 声称一致。
  • lib 双边(两边先 cargo build --locked --bin rubash):head 1356 passed; 1 failed; 4 ignored / base 1356 passed; 1 failed; 4 ignored;两边失败名都 = {api::consumer_tests::issue2084_session_end_restores_host_process_state}(Windows 本地基线红,前 lane 已在 2815ed3 核同名同因),差集 ∅。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --lib --locked 与 --test issue3582_unset_indexed_tilde_token 均净(0 警告)。
  • 卫生:rustfmt --edition 2021 --check 4 个改动文件全 OK;python scripts/check-marker-literals.py → OK (118 registry consts, 268 allowlisted sites);WSL bash scripts/check-utf8-boundary-hygiene.sh → scanned src / clean。
  • GNU 对照:WSL /usr/local/bin/bash GNU bash 5.3.20(1)-release vs target/debug/rubash.exe 同跑 target/probe-3590-rework.sh(8 例:unset/assign/read × tilde、assoc tilde 双向、backquote via param、a["~"]、a[$t])→ 逐字节一致(diff 空)。
  • CI:旧 head c7ee140 的三红(Rust tests / macOS / goldens)逐一核过日志,红名均只有 issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:3503 前置条件签名,该 head 早于 master ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 的 resolver 修复)。新 head 已含 ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750,预期该签名消失;合并前以新 CI run 复核。

F 点:无。

续作记录(本轮):

未跑/VOID 的腿:无。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 14:21
@caomengxuan666
caomengxuan666 merged commit 646db58 into master Nov 16, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3582-unset-tilde-token branch November 16, 2026 14:21
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
T1 收尾波批次汇总(2026-11-16 22:5x CST 本地;分工清单 #3590 #3612 #3607 #3569 #3564)

PR 处置 建议判词 依据
#3590 已合入 — merge 646db584,issue #3582 closed(前轮 PASS 报告见本 PR 评论区)
#3612 已合入 — merge 8a83879c;修复头 c3475c49a 为本 lane 推送(merge master + 弃陈旧 census 迁移 hunk),issue #3557 closed
#3607 不返工 建议 FAIL(重复实现,建议 owner 关闭) 机制被已合入 #3720(e3a7b7b3a)完全覆盖:其 9 个 cfg(unix) 钉在 master c3bf91e8 的 WSL 构建上 9/9 绿,GNU bash 5.3.20 脚本对照逐字节一致。详见 #3607 第2轮评论
#3569 阻塞待队长裁定 建议 PENDING(缺腿/阻塞:CONFLICTING) git merge-tree --write-tree origin/master c3bf91e8 对 head b7086c3d:仅 scripts/git-hooks/pre-commit 冲突。PR 的 fail-closed 全工作区 Python 批处理门与 master 的 staged-file fallback/fail-open 语义不同,属设计裁决,未自行解
#3564 阻塞待队长裁定 建议 PENDING(缺腿/阻塞:CONFLICTING) merge-tree 对 head adcbd99b:scripts/git-hooks/pre-commit(同 #3569 裁决)+ src/builtins/exec.rs(须保留 master shebang/descriptor 新机制并叠加 full_pathname)双冲突。另其 diff 含与 #3316 无关的 rustfmt 工具链文件(check-rustfmt.py、check_rustfmt_test.py、AGENTS.md、d11 钉),与 #3569 同源,建议拆分

阻塞项(需队长):scripts/git-hooks/pre-commit 的设计方向——#3569 主张 fail-closed 全工作区 rustfmt 批处理门,master 现行是 staged-file fallback。裁决后 #3569 可机械推进;#3564 还需在 exec.rs 上做语义合并(保留 master shebang_interpreter_command/shell_wrapped_command 与 descriptor/termination 改动,叠加 PR 的 Unix 侧 full_pathname 语义),并先拆分无关 rustfmt 面。

环境备注:本轮 git fetch 因代理故障失败,远端 head 以 gh API 实时值为准(#3607 1d6060e8、#3569 b7086c3d、#3564 adcbd99b 均未变);merge-tree 均对本地 origin/master c3bf91e8 复核。

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.

[bug] unset 'a[~]' 诊断 token 应为 ~,rubash 报 /home/hatch(#3522 残差)

1 participant