Skip to content

fix(executor): route dynamic assoc whole assignments to owner tables (Refs #3211) - #3220

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/3211-whole-assign
Nov 14, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/3211-whole-assign

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3211 — UNVERIFIED-BY-CAPTAIN

根因(机制定性)

动态变量整表复合赋值缺属主落点钩子。GNU 把 BASH_ALIASES / BASH_CMDS
注册为带元素 assign hook 的动态变量(variables.c:1882-1897
initialize_dynamic_variables):

变量 hook 语义
BASH_ALIASES assign_aliasvar(variables.c:1785) valid_alias_name 校验后 add_alias;非法名报错跳过该元素、其余照落、语句 rc 不变
BASH_CMDS assign_hashcmd(variables.c:1715) phash_insert(key, value, 0, 0):被点名条目 hits 重置、未点名条目原样保留

整表赋值无第二条路:subst.c:3441 do_compound_assignment →
arrayfunc.c:700 assign_compound_array_list 逐元素经
bind_assoc_var_internal / bind_array_var_internal 调钩子;标量
绑定走 bind_variable_internal 的 assign_func 臂、以 key "0" 调
钩子(variables.c:3140),+= 标量先 make_variable_value
ASS_APPEND 读现值拼接(variables.c:3328)。非追加复合形只换 cell
投影、从不清属主表——列表外属主条目保留。declare / typeset /
export 的操作数绑定同走 bind_variable 家族、钩子同路。

rubash 侧:#3107 的 sync_dynamic_assoc_vars 只在「属主 → 镜像」
方向发布;整表赋值落通用路径只写镜像 + typed 存储,下一命令边界
sync_dynamic_assoc_cells 对账时以未被触碰的属主表重建两者,赋值
被丢弃。对照 DIRSTACK 早有属主落点门 apply_dirstack_assignment,
assoc 对偶一直缺位——本 PR 补上。

普查(全部动态变量整表赋值落点,GNU 探针 27 格实测)

变量 GNU 机制 rubash 处置
BASH_ALIASES assign_aliasvar 逐元素落 alias 表 本 PR 新增门(复合/标量/追加/kvpair/列表内 [k]+=)
BASH_CMDS assign_hashcmd 逐元素落 hash 表 本 PR 新增门(同上;hits 语义 = 只重置被点名条目)
DIRSTACK assign_dirstack → set_dirstack_element([0]/越界忽略) 既有门(回归锁钉覆盖)
GROUPS / BASH_ARGC / BASH_ARGV / BASH_SOURCE / BASH_LINENO / FUNCNAME null_array_assign no-op + att_noassign 既有 noassign 臂吞(非追加形);追加形普查与残余见车道 REPORT
BASH_REMATCH 无钩子普通数组(match 时重建) 通用路径即正道
PIPESTATUS 无钩子普通数组;赋值语句自身管线状态在边界覆写读值 通用路径 + 既有 note 机制

declare / typeset / export 三门与 local 影子、unset 后整表赋值的
基底行为由车道普查对基底二进制逐格核对后回填(见
~/workspace/fix-3211/REPORT.md §2,工作区文件不入仓)。

修法

apply_shell_assignment_inner 在 DIRSTACK 臂旁加动态 assoc 门
apply_dynamic_assoc_assignment(dynamic_arrays.rs,与 DIRSTACK
门同居):复合形经与通用路径同一
rewrite_compound_element_subscripts + append_assoc_value 扫描
后逐条路由属主(aliases 表 / set_hashed_path);= 形以空表为
扫描种子(列表内追加在本列表内组合)、+= 形以属主现表为种子算
终值且只路由列表点名的键;标量形 = key "0" 单条,+= 先读属主
[0] 拼接。门控与 DIRSTACK 同口径:readonly 由上游臂先行拒绝,
unset 标记 / local / tempenv 影子让位普通 cell。收尾统一
sync_dynamic_assoc_vars() 发布。

回归钉 tests/issue3211_dynamic_whole_assignment.rs:普查每个
动态变量的整表赋值形 + 元素赋值回归锁 + unset 后普通变量锁,
先行提交(fail-first 核验数字待构建槽腿落地后回填本节)。

本 PR 删除了什么

无删除:纯新增(赋值门 + 回归钉)。通用路径对这两个变量名的整表
赋值自本 PR 起不可达(由门接管),但代码不删——影子/unset 情形仍
走通用路径绑定普通 cell。

@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review: FAIL for the current head (2026-11-14) — with captain ruling (b) split, below. The PR's own mechanism is correct; the head still cannot merge as-is.

What passes

The dynamic-assoc gate is the right mechanism (same shape as the DIRSTACK gate), the GNU anchors are exact (variables.c:1715 / 1785 / 1895-1897 / 3140, subst.c:3441, arrayfunc.c:700 — all read first-hand), and of the pin's 11 cells the base runs 3 green / 8 red with the head flipping exactly the 7 gate cells to green: head 10/11. Neighbour stems, lib bilateral (1206/0/4 both sides, failure name sets empty on both), -D warnings and rustfmt are all banked green from the lane runs.

The one red cell is a real product divergence — in a different face

unset_dynamic_then_whole_assignment_is_plain: unset BASH_ALIASES; BASH_ALIASES=([u]='echo u'); declare -p —

  • GNU 5.3.20 (captain-run this round): declare -a BASH_ALIASES=([0]="echo u"). For a name with no live declaration GNU always builds an indexed array and evaluates subscripts arithmetically; fresh-name controls agree.
  • Base c01a541: declare -A BASH_ALIASES=() (value lost).
  • Head 0f6d152: declare -A BASH_ALIASES=([u]="echo u" ) (value lands, wrong type).

The pin's expectation is the GNU truth — the pin is not wrong. The divergence lives in the generic compound-assignment type inference for undeclared names, which this PR's gate deliberately stands down from. It is not a baseline red carried over unchanged: the failure shape differs between base and head.

Captain ruling: (b) split

  1. The generic divergence is filed separately as Compound assignment to an undeclared name infers assoc from string subscripts; GNU builds an indexed array #3573, with the three-way evidence above; this pin cell moves to that issue as its seed. Do not change the cell's expectation to the assoc output — pins only assert GNU.
  2. This PR: remove that one cell from tests/issue3211_dynamic_whole_assignment.rs (it will live in Compound assignment to an undeclared name infers assoc from string subscripts; GNU builds an indexed array #3573's pin), keep the other 10 cells as-is.
  3. Merge path for the reduced PR: the interval touches both product files (dynamic_arrays.rs via seed-aware BASH_SOURCE bottom pop for interactive source #3135/fix(declare): render FUNCNAME listings from the live call stack (Refs #2770) #3466, temporary_assignments.rs via locale funnel: cover array binding channels and the declare hack (W-LOCALE) #3242/Stage-2 ④ Phase 4: variable-attribute family onto Diag (Refs #2707) #2968/fix(executor): consume the arithmetic fatal flag at the triggering command boundary #3365) and apply_shell_assignment_inner has drifted, so the merge round must build a local merged shape and re-run the full leg set (pin 10/10, fail-first, neighbours, lib name sets, -D warnings, hygiene, three-way probes); any text conflict stops the round.

Two record items for the #3211 close-out (not blocking): declare/typeset/export operand forms are not routed by this PR and have no pin (GNU routes them through the same hooks) — the merge-round three-way probe will measure them and the captain will either extend this wave or file separately; and the element-form illegal-alias-name status observation in the lane report (§2/§6, GNU rc=0 vs rubash exit 1) stays on record for the same decision.

caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…set binds stay plain (Refs #3573)

## 修了什么

`unset BASH_ALIASES` / `unset BASH_CMDS` 从不记录 UNSET_DYNAMIC_VARS:dynamic_parameter_is_set 只服务标量动态登记表,不含这两个 owner 表驱动的 assoc 变量。后果有四:

- #3220 的动态门对 unset 名字永不让位;
- declare -p 继续拿 owner 表渲染(`declare -A BASH_ALIASES=()`);
- alias / hash 操作复活已解绑变量;
- 元素绑定/解绑误操作 owner 表。

本次按 GNU variables.c:3788(unbind_variable;:1194-1195 解绑后“失去特殊含义”)在三处解绑记录点(unset builtin、view_unset_variable、jobs 内 unbind)补记,并在 publisher、元素绑定臂、元素解绑臂兑现该标记。通用复合赋值路径本身不动(新鲜名字本来就是对的,见钉锁)。

回归钉:tests/issue3573_unset_dynamic_assoc.rs(14 格;fail-first 在 d374e78 预修二进制上实测:11 格红、3 格锁绿;期望全部取自 GNU bash 5.3.20 oracle)。

GNU 锚点:variables.c:3788 unbind_variable、:1194-1195;subst.c:3441 do_compound_assignment;arrayfunc.c:507 assign_array_from_string、:700 assign_compound_array_list。

## 删了什么

无(纯修复 + 新增钉文件)。

## 碰撞

- 与 PR #3220 同文件 src/executor/dynamic_arrays.rs,不同 hunk(本 PR 只动 publish_dynamic_assoc_var;#3220 在同文件新增 apply_dynamic_assoc_assignment 等三函数,约 1870 行一带);合入顺序由队长定,后合者 update-branch + 合并形重验。
- 未碰 src/executor/temporary_assignments.rs(#3220 的门)、assignment_expansion.rs(#3501 在途)、src/lexer/continuation.rs(队长专属)。
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain focused re-review of the rework delta: PASS.

The original FAIL (comment 6873800335, ruling (b) SPLIT) faulted only the one red cell in a different face (#3573); the dynamic-assoc gate itself was judged correct. The rework removes exactly that cell and nothing else:

Merge round notes: head is already update-branched to 8eb07872, but the tip may move again before the merge — the merge round re-checks the tip and recomputes the intersection at execution time, then re-verifies the merged shape (pin 10/10 + lib name sets). Merge body Refs #3211 (the captain closes #3211 manually after the merge shows MERGED); strip the PR body's UNVERIFIED-BY-CAPTAIN marker and substitute these verified legs. Dossier: ~/workspace/review-3220/REPORT.md.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 17:10
@caomengxuan666
caomengxuan666 merged commit 021705c into master Nov 14, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…(Refs #3500)

## Summary

A bad substitution inside a compound-assignment element was diagnosed with the `${...}` fragment instead of the element word. GNU quotes the whole element and reports the word being expanded, e.g. `a=([0]=${-x})` → `\[0\]=${-x}`.

## Root cause

`subscripted_parameter_element` hands the RHS to `whole_word_parameter_single_value`, whose `has_word_operator` arm misjudges `${-x}` (empty `var_name` at position 0) and expands it standalone with no pending diagnostic word installed, so `expand_braced_parameter_word` falls back to the synthesized `${-x}` fragment. The plain-element path had the same gap (the walker default names the raw token, without `quote_assign`'s `\[sub\]` quoting).

## Fix

- New `compound_element_diag_word` (module level, mirrors GNU `quote_assign`): indexed `[sub]=value` → `\[sub\]=value`; assoc elements → the bare value; a quoted value keeps the fragment's own word.
- The element word is installed as the pending diagnostic word at the two element-expansion sites (`subscripted_parameter_element`, `compound_plain_element_value[_fields]`), install-if-absent.
- An `assoc` parameter is threaded through `expand_compound_positional_at_assignment[_bare]` (4 call sites), computed by new `compound_assignment_is_assoc` (live `ASSOC_VARS` marking OR the declare-assoc hint).
- New declare-assoc thread-local hint (`DECLARE_ASSOC_HINT` + RAII guard), installed by the `declare_assoc_operand_names()` scan in `command_prepare.rs`, covering the `declare -A` command-word expansion path, which runs before the declare builtin.
- Bare (eval-argument) flatten installs no word: documented residual, not fixed here.

GNU anchors: `arrayfunc.c:557/:581/:594-599/:606/:630/:938-977/:1108-1129`; `subst.c:10278`.

## Regression pin

`tests/issue3500_compound_elem_diag_word.rs` — 19 cells (10 fix shapes + 6 guard shapes + 2 quiet guards + 1 first-bad-wins). Expectations verified against GNU bash 5.3.20.

## Verification (captain-verified legs)

- Merged head `d11ffbcf` (update-branch of `00c0a07` onto tip `021705cf`, three update-branch rounds: `8eb07872` (#3510), `12aa434e` (#3455, disjoint files), `021705cf` (#3220, disjoint files); intersection `{src/executor/assignment_expansion.rs}` via #3599, hunks ≥164 lines apart, no overlap): pin **19/19**; same-file neighbor issue3501 pin **68/68**; adjacent assoc-face issue3573 pin **14/14**.
- Fail-first (top-up form on base `11719895`): pin 11/19 — 8 red, each reporting `Some("${-x}")` where the element word is expected.
- Neighbor `array_compound_quote_regressions` 17/17 on head.
- Full lib bilateral (bin built first): base 1247 passed / 0 failed / 4 ignored; merged head 1249 passed / 0 failed / 4 ignored — failure name-set diff empty (the +2 are the tip's Mach-O unit tests from #3510).
- `RUSTFLAGS="-D warnings" cargo check` RC=0, 0 warnings; `cargo fmt --check` RC=0; utf8-boundary hygiene clean.
- Head CI run `43619058744` (on `10da84b4`, the second update-branched head): 3 failing jobs, sole FAILED name `issue2875` (known baseline). A fresh CI run starts on the final head `d11ffbcf` from the third update-branch; it differs from `10da84b4` only by the disjoint #3220 merge.
- `continuation.rs` untouched.

Refs #3500

## 本 PR 删除了什么

Nothing — purely additive fix plus the new regression pin. No code, test, file, or behaviour removed.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3220 — 跳过返工:gh pr view 确认 state=MERGED(merge commit 021705c,merged 2026-11-14T17:10:26Z,已进 origin/master 6171293 区间)。Wave 4 分工中本 PR 的钉格拆分裁决已由合入完成,不再续作。Refs #3211

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