Skip to content

fix(f6): dynamic-variable shadowing, declare registry, test -v frames, assoc keys, env import (#2720 #2700 #2710 #2703 #2723) - #2766

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/f6-variables
Nov 3, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/f6-variables

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fix lane F6 — variable table / dynamic variables / environment import. Five deep-audit findings, one mechanism-level fix each, regression stems named by issue. UNVERIFIED-BY-CAPTAIN (lane-local verification summarized below; captain re-verifies before merge).

Refs #2720 Refs #2700 Refs #2710 Refs #2703 Refs #2723

#2720 — local/tempenv bindings of dynamic variables never shadowed the provider (B3-F02)

GNU model: hooks live on the global cell (variables.c:1844 initialize_dynamic_variables); find_variable walks the variable-context stack first, so a local binding is an ordinary cell owning reads/writes in scope. One predicate (dynamic_name_shadowed / dynamic_bind_targets_plain_cell) now gates every face: expansion (dynamic_parameter_value, dynamic_parameter_is_set, declaration view), the arithmetic context snapshot (ArithDynamicContext::shadowed_names + arithmetic/value.rs), plain assignment hooks (SECONDS offset / RANDOM seed / SRANDOM swallow store into the plain cell when shadowed or tempenv-bound), kept-tempenv absorption (plain binds replay through the hook, mirroring merge_temporary_env), and declare (new apply_declare_dynamic_hooks — adds the missing SECONDS offset hook; local-shaped declares skip, -g hooks). Precedents in-tree: DIRSTACK shadowing, PIPESTATUS shape snapshot (#1555/#1364).
Stem: issue2720_dynamic_local_shadow_regressions — 3 passed.

#2700 — declare listings omitted most of the dynamic registry (A3-DYN)

Listings now receive DynamicDeclarationViews (text + the registry's own integer/array class) for the whole registry; the merge adjudicates filters by that class instead of mark sets dynamics never carry. declare -i gains BASHPID/HISTCMD/RANDOM/SRANDOM, declare -a gains GROUPS, and the phantom stale BASH_LINENO cell is superseded in every form — including the assignment-form listings (set, bare declare), which receive the live compositions via a parallel set-form supply. PIPESTATUS keeps its deliberate #1363 -p-only listing presence. Documented choices: SECONDS modeled as statically att_integer (GNU earns it lazily on first read via set_int_value, variables.c:1294-1295); THIS_SH listing and OLDPWD initial cell are pre-existing faces outside this finding, left as-is.
Stem: issue2700_declare_dynamic_listing_regressions — 2 passed.

#2710 — test -v / [[ -v ]] blind to FUNCNAME/BASH_SOURCE in functions (A3-V1)

The builtin's env-only lookup contract is preserved (test.c:650-677; rubash#2073); the executor overlays the composed frame-array storage onto the env map handed to the lookup whenever a -v operand names a frame carrier (FUNCNAME/BASH_SOURCE/BASH_LINENO/BASH_ARGC/BASH_ARGV), on both the [ ] dispatch and the [[ ]] rewrite path.
Stem: issue2710_test_v_frame_arrays_regressions — 2 passed.

#2703 — assoc assignment with bracket keys stored corrupted values (A3-F2)

record_array_element_assignment_for_word's raw-parse fallback skipped the cooked-field fix-up when the cooked parse failed outright — exactly the bracket-in-quotes shapes (m['a]b']='v' stored 'v' with quotes) — while both executor consumers expect cooked form (general.c:480 splits the syntactic word). The fallback arm now applies the identical fix-up.
Stem: issue2703_assoc_bracket_key_assignment_regressions — 2 passed.

#2723 — environment import de-exported lowercase-first names (B5-05, HIGH)

is_initial_export_candidate / is_process_startup_export_candidate now import exported-ness as-is for every valid identifier (variables.c:368, :513-516, :3307), on the embedded and standalone paths alike; the len <= 1 exclusion is gone too (GNU children see x=1). The old heuristic's rationale (sibling mirror writes in a shared process env) is void post-#916: set_process_env mirrors only a fixed uppercase/internal whitelist.
Stem: issue2723_env_import_export_regressions — 2 passed, plus in-module unit tests over both predicates (initial_export_candidates_follow_gnu_import).

Lane-local verification (full logs in the lane report)

Residuals (honest)

  • SRANDOM has no declare/plain seed state to hook (draws are entropy-first by design) — unchanged divergence, noted in the report.
  • Posix-mode + in-function kept-tempenv conversion for dynamic names is not wired (binds are context cells there).
  • FUNCNAME has no declaration view yet (GNU renders a valueless declare -a FUNCNAME line in listings) — same root as the pre-existing FUNCNAME materialization gap.

…ssoc keys, env import

Five mechanism-level fixes from the deep-audit sweep, each with a
regression stem named by its issue:

- rubash#2720 (B3-F02): one shadow discipline over the whole dynamic
  class. GNU keeps the hooks on the global cell (variables.c:1844
  initialize_dynamic_variables) and find_variable's context stack
  precedes it, so a local/tempenv binding owns reads and writes in
  scope. The provider now yields whenever a visible local scope or
  tempenv binding owns the name — across expansion, the arithmetic
  context snapshot, [[ ]], declare rendering, and the assignment
  hooks (plain binds store into the plain cell; kept tempenv binds
  for builtin commands replay through the hook at absorption,
  mirroring merge_temporary_env). Declare gains the SECONDS hook it
  lacked. In-tree precedents: DIRSTACK shadowing, PIPESTATUS shape.

- rubash#2700 (A3-DYN): declare listings enumerate the dynamic
  registry. Filtered forms adjudicate views by the registry's own
  attribute class (att_integer: variables.c:1858-1875; arrays:
  GROUPS and the stack carriers) instead of mark sets the dynamics
  never carry; the assignment-form listings (set, bare declare) get
  the same live compositions, ending the stale BASH_LINENO cell and
  the missing GROUPS. SECONDS is modeled as statically integer
  (GNU earns its att_integer lazily on first read, variables.c:1294).

- rubash#2710 (A3-V1): test -v / [[ -v ]] see the frame arrays. The
  executor overlays the composed stack storage onto the env map the
  env-only lookup receives when an operand names a frame carrier
  (test.c:650-677 reads find_variable's live table); the builtin's
  no-process-env contract (rubash#2073) is untouched.

- rubash#2703 (A3-F2): the array-element assignment reconciler used
  the raw parse without its cooked-field fix-up when the cooked
  parse failed outright — exactly the bracket-in-quotes subscript
  shapes — so quoted values stored with their quotes. The fallback
  arm now applies the identical fix-up (general.c:480 assignment()
  splits the syntactic word).

- rubash#2723 (B5-05, HIGH): environment import keeps the
  environment's exported-ness as-is (variables.c:368, :513-516):
  the uppercase-first heuristic and the single-character exclusion
  are gone from both import paths. The mirror-pollution rationale
  is void post-rubash#916 — set_process_env mirrors only a fixed
  uppercase/internal whitelist, so no lowercase environment name
  can be a mirror write.

UNVERIFIED-BY-CAPTAIN: local verification is in the lane report
(probe battery vs the GNU 5.3.20 oracle, per-stem scrubbed cargo
runs, full lib suite, 22 neighbor stems, --all-targets check).
@caomengxuan666
caomengxuan666 merged commit 9e609e2 into master Nov 3, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 13, 2026
…2770) (#3466)

## 根因

FUNCNAME 在 `declare`/`set` 各类 listing 里没有 live view:PR #2766 把动态变量的 listing 改为 registry 驱动后,FUNCNAME 的 listing 仍渲染 init mirror——一个 birth snapshot(`""` 函数入口,从不刷新),而不是实时调用栈;且 #183 的 seed hack 会在 `unset` 后凭空造出一个 cell。

## GNU 锚点(vendored bash 5.3)

- `variables.c:1835-1839` `init_funcname_var`:`INIT_DYNAMIC_ARRAY_VAR ("FUNCNAME", get_funcname, null_array_assign)` + `att_invisible|att_noassign`。
- `variables.c:1812-1824` `make_funcname_visible`:函数入口清 `att_invisible`,返回时重设。
- `variables.c:1066-1073` `print_var_list`:跳过 `att_invisible` cell——depth 0 的 bare `declare`/`set` 无行,可见后渲染 live stack。
- `builtins/setattr.def:510-511` `show_var_attributes`:invisible array 印 bare 名(depth 0 为 `declare -a FUNCNAME`),可见后带元素。
- `variables.c:3788` `unbind_variable`:`unset` 后 cell 在本 shell 生命周期内消失,`declare -p FUNCNAME` 报 not found。

## 改动

- `src/executor/dynamic_arrays.rs`:FUNCNAME 加入 array declaration class、dynamic cell view、set-view supply(仅非空栈)、以及从 composed stack 渲染的专用 declaration view。
- `src/executor/declare_local.rs`:named-print seed 永不 seed lifetime-unset 的 cell;FUNCNAME 加入 VISIBLE listing-refresh 类(与 GROUPS/BASH_SOURCE/BASH_LINENO 同列)。
- `tests/issue2770_funcname_listing_regressions.rs`(新 stem,3 tests):顶层 named/listing/filter 形、函数内 live stack(含嵌套)、unset 后 view 消失;期望与 GNU bash 5.3 oracle 逐字节一致。
- `.github/workflows/ci.yml`:新 stem 的 named nextest 步(该 stem 在其他 CI lane 之外,rubash#3430)。

## 本 PR 删除了什么

无产品代码删除。仅重组:FUNCNAME 的 listing 渲染从 stale env mirror 改为 live provider view;`declare_local.rs` 的 seed 条件收窄(unset 后不再造 cell)。

## 验证(UNVERIFIED-BY-CAPTAIN)

- Box:新 stem head 3/3;base top-up fail-first 1 过 / 2 败(函数内 listing 与 unset 两格,正是本修所补)。
- 待补:全量 lib 双边、`RUSTFLAGS="-D warnings"` check、GNU oracle 三方、相邻 issue2700 族 stem。

Refs #2770
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