Repository navigation
Phase 4 residuals: getopts/declare/setattr/local/unalias point semantics (Refs #2970, #2971, #2972, #2973, #2974, #2975) - #2997
Merged
Conversation
GNU builtins/alias.def unalias_builtin reports usage with EX_USAGE when no alias name is given; only a missing alias NAME is EXECUTION_FAILURE. Both no-operand returns in unalias_with_io (the entry check and the post-option-scan check, e.g. `unalias --`) now return EX_USAGE, matching the invalid-option arm. Regression pins: tests/issue2975_unalias_bare_status_regressions.rs (bare and `--` forms red on master with rc 1, green after).
…2970 builtins/getopts.def:301 binds OPTARG unconditionally on the valid option path (bind_variable ("OPTARG", sh_optarg, 0)); for a no-argument option sh_optarg is NULL, so the variable ends up BOUND WITH NO VALUE — a later `declare -p OPTARG` prints `declare -- OPTARG`, and any earlier value is replaced. getopts' unbind belongs only to the G_EOF / non-silent G_INVALID_OPT / G_ARG_MISSING paths. The success path called getopts_unbind_optarg; it now calls the new getopts_bind_optarg_null, which leaves the declared-unset representation (no stored value, DECLARED_UNSET mark), reports a readonly OPTARG and keeps its value like the valued bind, and binds through a nameref OPTARG to its target (bind_variable semantics). Regression pins: tests/issue2970_getopts_optarg_bind_regressions.rs (3 defect cells red on master, error/silent control cells green).
…onvert, Refs #2971 GNU builtins/setattr.def:236-275 delegates an assignment operand to declare_builtin with ONE synthesized letter — 'a' when arrays_only, else 'A' (setattr.def:253-256) — and runs the delegation only under `if (assign)`. Two corrections follow. (1) In array_attribute_assignment_value's SCALAR branch an explicit assoc request now yields to an explicit array request, and the function returns the storage kind it produced (Some(true)=assoc, Some(false)=indexed, None=scalar) so the three caller arms (export set, export -n, readonly) mark exactly that kind. The compound branch is untouched: with -A present the compound word was already expanded as key/value pairs, so compound -aA stays associative, matching GNU. (2) Name-only operands no longer take the (value-or-"", array||assoc) fallback that manufactured an array conversion — `x=1; export -A x` keeps x a scalar; only att_exported/att_readonly is applied, as in GNU. Regression pins: tests/issue2971_setattr_array_assoc_priority_regressions.rs (7 defect cells red on master incl. the readonly -ar oracle shape, compound/only-letter control cells green).
#2972 GNU builtins/setattr.def set_or_show_attributes (the listing branch declare_builtin reaches for no-operand forms) does NOT conjoin the requested attributes: the array attribute is a type GATE when requested (the assoc attribute is the gate only when -a is absent — an `else if` in the C), the gate bit is removed from the attribute set unless it was the only flag, and a variable is shown iff it passes the gate AND carries at least one remaining attribute (`(var->attributes & attribute) != 0`). declare's listing filters now implement exactly that via one shared listing_filter_passes adjudication used by the table walk, the mark-chain candidates, the dynamic-view merge, and the tempenv underlay. trace and capcase — parsed into DeclareOptions but never forwarded — are real filter parameters now. Candidate generation chains every attribute mark set plus the declared-unset set (a value-less `declare -i x` is a live cell in GNU's enumeration), and the chain no longer requires a table entry in unfiltered listings, so declared-but-unset names appear in full listings too. state_views' name-set call passes the two new filter arguments (both off). Regression pins: tests/issue2972_declare_listing_filter_regressions.rs (defect cells: -c/-t ignored, AND semantics, -aA listing, missing declared-unset candidates).
…efs #2973 GNU's getter-backed dynamics are real shell_variable cells (variables.c INIT_DYNAMIC_VAR): find_variable_internal (variables.c:1175-1189) fires the getter on by-name lookups and the getter stores its result INTO the cell; enumeration (print_var_list / show_var_attributes) renders the CELL and never fires getters. rubash computed listing views live, so listings drew fresh RANDOM values, stamped -i on an unread SECONDS, rendered GROUPS' live groups and BASH_ARGV0's value. The fix gives the cells a home: ShellState.dynamic_cells records every materialization the read path performs (SECONDS also earns att_integer there, variables.c:1294-1295; a GROUPS read regenerates the cell), plus the literals SECONDS/RANDOM assignments store. Listings now build dynamic_cell_views from that state — bare name when never read, cached (possibly stale) value after a read, GROUPS=() until a read regenerates it — while NAMED lookups keep the live views. The stack arrays and PIPESTATUS keep delegating to the live view (their cells are continuously maintained); PIPESTATUS is pushed in every listing form and renders nothing while its cell does not exist. The set form gains the materialized PIPESTATUS cell and the unmaterialized GROUPS=() shape. BASH_ARGV0 is marked att_invisible like GNU's registration: the set form skips it, declaration listings render its bare name (show_var_attributes), named lookups still print its value — COMP_WORDBREAKS shares the listing rule. An enumeration name that resolves to no cell/value/attribute is skipped silently; the not-found diagnostic stays with named lookups. Regression pins: tests/issue2973_declare_dynamic_cell_rendering_regressions.rs (5 defect cells red on master; named-view controls green).
…ons, Refs #2974 GNU's local is declare_internal in a local context (builtins/ declare.def): the function-listing branch is reached only on the operand path, and the no-operand branch ignores the -f/-F flags and calls show_local_var_attributes (builtins/setattr.def) — with nodefs set when -F was given. execute_local diverted ANY invocation whose option scan contained f/F to the function path, so a nameless `local -f` printed the caller's own function definition. The divert now requires name operands (new declare_invocation_has_operands walk, mirroring scan_declare_options' stop rules); nameless forms fall through to the generic local-variable listing, and a nameless -F strips the values from the rendered listing lines at the flush (the builtin has no nodefs input for variables), matching show_local_var_attributes with nodefs. Regression pins: tests/issue2974_local_f_nameless_regressions.rs (3 defect cells red on master; bare-local control green).
…2973 Self-verification against rubash#2700's pins exposed the other face of the cell model: GNU's attribute builtins resolve every name-only operand through find_variable (the operand walks of builtins/ setattr.def and builtins/declare.def), and find_variable_internal fires a dynamic variable's getter into its cell — so `export RANDOM` alone makes a later listing render a drawn value, and `declare SECONDS` earns SECONDS its lazy att_integer, with no read anywhere. The executor now fires fire_dynamic_operand_lookups at the export, readonly and declare/typeset dispatch points (gated on non-print invocations; assignment operands bind instead of looking up, print forms render through the live views). Two expectations in tests/issue2700_declare_dynamic_listing_ regressions.rs encoded the pre-cell model and are corrected to the oracle-verified shapes (GNU bash 5.3.20, harness env): the D1 `declare -i` set no longer lists an unread SECONDS (its own header documented the static-class deviation; #2973 supersedes it), and the full-listing set gains OLDPWD (the documented exclusion is gone since #2972's candidate chains list the startup exported-unset cell like GNU). New pins for the operand face land in the #2973 stem.
caomengxuan666
marked this pull request as ready for review
November 7, 2026 20:59
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
…2968) Stage-2 ④ Phase 4: the variable-attribute family (declare/typeset, local, readonly, export, unset, alias/unalias) migrates onto the Phase 0–3 infrastructure — one declaration-table row, the single BuiltinOpt parser, and the Diag handle. The assignment machinery now takes `&mut Diag` bound at the dispatch point, so a readonly diagnostic is written through the command's own fd 2 (redirect-aware) instead of an ambient stderr — this settles A3-R1 (#2707). Captain verification highlights: E1 option/attribute matrix 232 cells, SAME 189 → 230 with 41 flips all DIFF→SAME and zero regressions (the two remaining cells are filed as #2971); E3 differential matrix 3112 cases, SAME 2756 → 2801, exactly 45 flips all in-family --help cells, zero regressions; regression pins 18/18 (including seven cells added for the unset repair below); full lib 1188 passed / 0 failed / 4 ignored; RUSTFLAGS="-D warnings" clean; UTF-8 hygiene clean. One regression the migration itself introduced was caught in captain verification and fixed on this branch (ba25d2e): execute_unset kept pre-migration branches that opened a plain `2>file` target directly for the Diag, and the new trailing buffered-output route re-applied the redirects — the second, truncating open erased the readonly diagnostic, so `readonly uv=old; unset uv 2>f` lost it entirely (GNU and pre-migration master both deliver it to f). Unset now buffers both streams and lets the single ordered route apply the redirects once, like the rest of the family; a captain probe battery of 14 cells (unset file/append/dup/no-redirect/unopenable, readonly assignment and arithmetic faces, and one diagnostic cell per migrated family member) is byte-identical to GNU bash 5.3.20. Two later additions ride on this branch. The E4 follow-up removes three per-call overheads on the declare-family success path (stack-parsed BuiltinOpt spec, flag fast scan, lazy print_names snapshot); it lands on structural evidence under the captain's E4 ruling, with the residual (≲1.5%) booked as performance debt under #3232. Master meanwhile landed the locale-funnel work in pre-migration form (PR #3242); merging master into this branch re-lands that funnel semantics in migrated form — LocaleFunnelRecord rides the migrated assign_declare_names signature and the !print gate keeps the outer-gate shape (GNU declare.def:389-406 and declare.def:1105) — and the funnel regression pins pass unchanged (issue3066 8/8, issue3097 8/8, issue2707 18/18, the six #2997 residual stems all green, lib 1233 passed / 0 failed / 4 ignored on the merged head). Pre-existing divergences found on the way are filed for later and left untouched here. The tracking issues are #2970 (getopts OPTARG), #2971 (export/readonly -aA priority), #2972 (declare listing attribute filters), #2973 (declare listing rendering), #2974 (local -f/-F nameless) and #2975 (bare unalias exit code). 本 PR 删除了什么:变量属性族各 builtin 手写的选项解析与诊断前缀代码(由 BuiltinOpt + Diag 取代)、赋值机械的 `buffer_assignment_diagnostics` 缓冲机制(改为 Diag 直通)、unset 的迁移前直开重定向分支(双重应用重定向的回归源)。净行数以 PR 文件账为准(42 文件 +2214/−1289,含队长 fmt 提交、unset 专修提交、E4 三刀与 funnel 消解 merge)。 Refs #2707
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 4 残余六单的点状语义修复(一单一提交,每单带以 issue 号命名的回归钉,fail-first 已在 master
b3e4ff89上证红):export -aA/readonly -aA标量操作数按 setattr.def:253-256 委托单字母(-a 胜出)绑索引存储;compound 操作数保持关联解释(与 GNU 一致,不动);无赋值操作数不再触发转换/标记(setattr.def 的if (assign)门)。();BASH_ARGV0 按 att_invisible 在列表印裸名、命名查找印值。local -f/-F不再走函数列表路径(declare.def 仅在操作数路径查 list_function_p),落回帧内本地变量列表;-F按 nodefs 剥值。unalias(含unalias --)退出码改 EX_USAGE(2)(builtins/alias.def 的 usage 路径)。第七提交(自验跟进提交)
3b938cf1Refs #2973 — 属性内建的裸名操作数按 find_variable 语义物化动态 cell:GNU 的 export/readonly/declare 对每个无赋值操作数走 find_variable,getter 触发把值存进 cell(export RANDOM单独执行即可让后续列表渲染抽取值、declare SECONDS让 SECONDS 赚得惰性 -i);executor 在三处分发点补上该次查找。此提交同时更正 tests/issue2700 的两处钉期望(旧钉编码的是物化前模型:未读 SECONDS 不再进 -i 集——原钉头注本就记录了该偏差;OLDPWD 因 #2972 候选链补全后与 GNU 一致地进入全量列表,删除旧文档化排除)——产品代码未向旧钉弯曲,oracle 证据在车道 REPORT。红线遵守:未碰
src/lexer/continuation.rs、未碰docs/api-ledger.md、无新公开面、未改 Phase 4 迁移的分发接线。本 PR 删除了什么:删除了 getopts 成功路径上错误的 OPTARG 解绑调用、setattr 三处「assoc 优先 + 无值回退 bound_array」的旧标记逻辑、declare 列表的三处 AND 过滤实现、动态变量列表的实时渲染路径(命名查找的实时视图保留)。净行数以提交统计为准(七个提交合计见各提交)。
自验(车道自报,UNVERIFIED-BY-CAPTAIN):六钉 stem 全绿;全量 lib 与 base
b3e4ff89逐数对照、邻域 stem 失败名集对照、RUSTFLAGS="-D warnings" check、hygiene、逐文件 rustfmt 结果见车道 REPORT。