Skip to content

r79: allexport local/readonly + array marks, assoc subscript single-eval, source diagnostic name - #2962

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/r79-set-a-assoc-source
Nov 7, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/r79-set-a-assoc-source

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Refs #2944
Refs #2945
Refs #2946
Refs #2947

r79 hunt batch — four independent roots, one PR. Pins land first (fail-first on master 4f747412); the code changes follow in a second commit on this branch.

What changes, per issue

#2944 — set -a ignored by local/readonly initialization.
GNU: set -a sets mark_modified_vars (flags.c:47, flags.c:167), applied by the scalar bind primitives only — bind_variable_internal tail (variables.c:3211-3212), bind_variable_value (variables.c:3366-3367). local's valued operands bind through bind_variable_value via declare_internal (builtins/declare.def), and readonly's valued words bind through do_assignment_no_expand → bind_variable (builtins/setattr.def), while set_var_attribute creates a missing variable through bind_variable(name, NULL, 0) (setattr.def). Rubash: execute_declare already emulated the mark (the #538 post-pass) but execute_local had no counterpart, and apply_readonly_arg never marked. Change: a valued-operand post-pass in execute_local mirroring the declare one (valued scalar operands only — valueless locals perform no bind in GNU, make_local_variable only; array creations and subscript operands bind through the array machinery, which never marks), plus the bind-shaped marks in apply_readonly_arg (creation short-circuit and the non-array valued path).

#2945 — set -a wrongly marks arrays -x.
GNU: the mark lives only in the scalar bind primitives above. Array creation (make_new_array_variable variables.c:2798, make_new_assoc_variable variables.c:2851) and the compound path (do_compound_assignment subst.c:3441 → assign_array_from_string arrayfunc.c:507) never mark. Rubash marked in two places GNU does not: the generic tail of apply_shell_assignment_inner marked every shape including compound binds, and the execute_declare post-pass marked -a/-A creation operands. Change: gate the assignment tail's mark on the bind not being a compound assignment, and skip the declare post-pass marking when the invocation carries -a/-A. The flagless declare arr=(1 2) form keeps GNU's -ax quirk (the valued word creates the name through bind_variable before conversion) — pinned as a control.

#2946 — associative assignment evaluated the subscript twice.
GNU: assign_array_element_internal (arrayfunc.c:392-398) expands the subscript exactly once via expand_subscript_string and hands the expanded key to bind_assoc_variable; an assignment word gets no whole-word expansion pass (general.c:480). Rubash ran the whole-word expansion over the assignment word (first evaluation, result discarded) and then expanded the raw subscript again in prepare_array_element_assignment_word (second evaluation — the one whose key was stored). Change: in expand_command_word, attempt the assignment preparation before the whole-word pass for every associative element-assignment word, not only for the provably side-effect-free subset; when preparation resolves the word, the whole-word pass never runs. The now-unused side-effect predicate is removed. Indexed subscripts are untouched (preparation declines non-associative arrays) and the expansion form is untouched.

#2947 — POSIX-mode source diagnostic printed ..
GNU: builtins/source.def registers two builtins over one implementation — source (source.def:23) and . (source.def:39) — and the diagnostic is builtin_error(_("%s: file not found"), x) (source.def:179) with the prefix taken from this_command_name, the invoked name (builtins/common.c:93-94). Rubash hardcoded the . spelling in the file-not-found arm of the source builtin. Change: use the invoked command name the executor already threads through, matching the sibling arms in the same function.

本 PR 删除了什么

  • The assoc_element_word_expansion_is_side_effect_free predicate (command_prepare.rs) and its doc comment: its only call site was the gate described in [bug] Associative array assignment evaluates the subscript twice #2946 above; with preparation attempted first for the whole associative-assignment class, the predicate has no remaining consumer.
  • The hardcoded . in the source builtin's file-not-found format string.
  • Nothing else is deleted; no test, doc, or ledger entries are removed.

Net-line accounting

  • Commit 1 (pins): +545 / −0 (four new test files).
  • Commit 2 (code + two +a-corner pins): +167 / −61 across 7 files — src +149 / −61 (declare_local.rs +90, command_prepare.rs +20 / −61, setattr/apply.rs +21, temporary_assignments.rs +9 / −1 in effect, source.rs +7 / −1 in effect), tests +18 / −0.
  • Branch total vs master: +712 / −61.

Pins (fail-first on master 4f74741, oracle = GNU bash 5.3.20)

  • tests/issue2944_allexport_local_readonly_regressions.rs — master: 4 passed / 6 failed (local, local -i, local -g, readonly, readonly compound, valueless readonly facets fail; all controls pass).
  • tests/issue2945_allexport_array_no_export_regressions.rs — master: 4 passed / 6 failed (compound, assoc compound, empty compound, declare -a compound, declare -a scalar, append facets fail; controls incl. the flagless-declare quirk pass).
  • tests/issue2946_assoc_subscript_single_eval_regressions.rs — master: 3 passed / 5 failed (plain, assoc_expand_once, nested, first-key, append facets fail; indexed/expansion/value controls pass).
  • tests/issue2947_posix_source_diagnostic_regressions.rs — master: 4 passed / 2 failed (POSIX source form and source -p facets fail; . forms and default-mode controls pass).

caomengxuan666 and others added 3 commits November 7, 2026 04:05
One integration stem per issue, expectations cross-checked against GNU bash 5.3.20 oracle probes on master 4f74741. Fail-first tallies on master: issue2944 4p/6f, issue2945 4p/6f, issue2946 3p/5f, issue2947 4p/2f — every in-scope facet fails, every control (including the flagless-declare -ax quirk) passes.
…tic name

Refs #2944: execute_local gains the valued-operand allexport post-pass declare already had (bind_variable_value, variables.c:3366-3367); apply_readonly_arg marks on its bind shapes (bind_variable tail, variables.c:3211-3212; creation bind in set_var_attribute). Valueless locals, -a/-A creations, subscript and compound operands do not mark, matching the GNU bind each performs.

Refs #2945: the plain-assignment tail no longer marks compound binds (do_compound_assignment, subst.c:3441, never reaches a marking primitive), and the declare post-pass stands down when the invocation's -a/-A attribute ends set (make_new_array_variable variables.c:2798 / make_new_assoc_variable variables.c:2851). The flagless declare -ax quirk is preserved and pinned.

Refs #2946: expand_command_word now attempts prepare_array_element_assignment_word before the whole-word pass for every associative element assignment (GNU has no whole-word pass for assignment words, general.c:480; the subscript expands once, arrayfunc.c:392-398). The side-effect-free predicate whose only call site was the old gate is deleted.

Refs #2947: the source builtin's file-not-found diagnostic names the invoked builtin (source.def:179 via this_command_name, builtins/common.c:93-94) instead of a hardcoded dot.

Two pins added with the code: local +a initializer (2944) and declare +a scalar control (2945) — the -a/-A stand-down keys on the attribute's final state.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 7, 2026 04:56
@caomengxuan666
caomengxuan666 merged commit 9fbeedd into master Nov 7, 2026
12 of 13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/r79-set-a-assoc-source branch November 7, 2026 05:35
caomengxuan666 added a commit that referenced this pull request Nov 7, 2026
… function (Refs #2963 #2964) (#2977)

Two allexport marking residuals from the r79 batch:

- #2963: a scalar bind over an existing indexed array went through `set_process_env` (a no-op for ordinary names), so the EXPORTED attribute was never set. GNU's array arm of bind_variable_internal stores element 0 and its tail (variables.c:3211-3212) still applies mark_modified_vars. The arm now calls mark_exported, exactly like its assoc twin in the same function.
- #2964: inside a function (without -g), `declare` runs in GNU's local context, where a compound operand is created through the local array machinery and do_compound_assignment (subst.c:3441, ASS_MKLOCAL) — neither marks. The #538 allexport post-pass now stands down for compound operands in the local context (compound judged as in declare.def:935-947); scalar operands there still mark via bind_variable_value. The top-level -ax quirk and declare -g behaviour are unchanged and pinned as controls.

Captain verification: new pins 8/8 and 10/10 re-run (fail-first 5/3 and 6/4), the #2962 control stems 11/11, 11/11, 8/8, 6/6, full lib 1188 passed / 0 failed / 4 ignored, RUSTFLAGS="-D warnings" clean, hygiene and per-file rustfmt clean, and a 9-cell probe against GNU bash 5.3.20 identical on every in-scope cell. The one remaining probe divergence (declare arr[0]=x over-marked -x in both contexts) is pre-existing on master and is filed as #2980.

本 PR 删除了什么:temporary_assignments.rs 中标量覆写数组臂里一行错误的进程环境投影(`set_process_env` 调用),由 mark_exported 取代;无其他删除。净行数 +278/−1(4 文件,含新回归钉 223 行)。

Fixes #2963
Fixes #2964
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