Repository navigation
fix(builtins): print function definitions in bare declare/set listings (Refs #3487) - #3530
Merged
Merged
Conversation
GNU print_all_shell_variables (builtins/set.def:506-527) prints the function definitions after the variables for bare `declare` and bare `set`; rubash bare `declare` omits them entirely. Pin covers the seed shape, name order after all variables, the bare `set` twin, the POSIX gate, subshell/redirect/keyword definition shapes, and guards for `declare -p`, `unset -f`, and `declare -f`. Fail-first on master 8b48c16: 5 passed / 3 failed (bare_declare_prints_function_definition_block, bare_declare_functions_sorted_and_after_all_variables, bare_declare_function_shapes).
…s (Refs #3487) GNU print_all_shell_variables (builtins/set.def:506-527) is a single enumerator: print_var_list, then print_func_list (variables.c: 1079-1090) when posixly_correct == 0. Bare `declare` reaches it via declare.def's no-operand arm (set_builtin(NULL)), exactly like bare `set`. rubash's port, print_shell_variables, printed only the variable half. Bare `set` masked that with an executor-side append in execute_set (rubash#1056); bare `declare` had no counterpart and omitted the function definitions entirely. Complete the enumerator instead: print_shell_variables takes a &[FunctionSetView] (rendered by the executor with the same ast_print port declare -f/type use, metadata included) and prints it after the variables in name order, gated on the live posix option (set.def:518-520). The views thread through the set_with_io chain and execute_with_io_named_in_context from all four executor call sites, composed beside dynamic_set_views. execute_set's post-append block is deleted — its POSIX gate read __RUBASH_POSIX_MODE, which set_shell_option keeps in sync with the option table the enumerator reads, so the two listings now share one gate and one code path. Pin: tests/issue3487_bare_declare_function_listing_regressions.rs 8/8 (fail-first 5/8 on master).
caomengxuan666
force-pushed
the
fix/3487-bare-declare-functions
branch
from
November 14, 2026 04:07
fc9c54f to
689bf01
Compare
Member
Author
|
队长复核 PASS(头 腿(复核员全跑,队长核查原始日志):
合入:Refs #3487(合后队长手关 #3487,随后派 #3494)。合入顺序待定:与 #3548 的 hunk 相邻,须等用户定合入顺序后,合入轮再 update-branch 至 live 尖 + 合并形重验。 |
Member
Author
|
【WIN-AGENT-BATCH-SUMMARY】 h3 车道批次汇总(#3487 审 #3530 / #3494 / #3502 全部处理完;判词均为建议,合入/关单由队长裁定)
共腿:lib 双边两分支均 1376/1/4 差集 ∅(共有失败 issue2084 环境性); |
… call Master's local -p operand walk (Refs #3529) added a fourth execute_with_io_named_in_context call site after this branch's signature change; the textual merge was clean but the new site missed the function_set_views argument. The views are unused on that route (core_args always carries operands, so the bare-listing enumerator is unreachable) but are supplied for signature parity with the sibling call sites. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
print_func_list (variables.c:1079-1090) calls named_function_string
with name=NULL, so the `name && *name` gate (print_cmd.c:1419-1425)
skips the `function ` prefix entirely — print_func_list supplies the
`name ` itself. The listing therefore renders an assignment-word
function name (`function a=b { ...; }`) as `a=b () ` even though
`declare -f a=b` prints `function a=b () ` (declare.def:518 passes
the name). Verified against the GNU bash 5.3.20 oracle:
$ function a=b { echo hi; }; declare
a=b ()
{
echo hi
}
Split the ast_print port: multiline_function_listing_text takes the
name=NULL arm (no `function ` fallback) while the named form keeps it
for declare -f / type / export -pf. Regression pin added.
GNU C source: print_cmd.c:1419-1425 named_function_string name gate;
variables.c:1158 print_var_function name=NULL call site.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
marked this pull request as ready for review
November 18, 2026 08:30
This was referenced Nov 18, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 20, 2026
…3982) PR #3530 (for #3487) threaded pre-rendered FunctionSetViews through the set/declare funnels, and the executor materialized them at every dispatch: Executor::function_set_views() rendered every function's listing text via ast_print on each set/declare/typeset/local call, although only the bare-listing arm ever prints them. In a function-heavy shell (bats loads ~150 library functions and calls `local` pervasively) that is an O(total definition text) tax per call: on X299 (release) 2,000 local-carrying calls under 150 twelve-line functions took ~33 s, and bats' junit gather reported 221 ms/test against ~35 ms before the regression (bisect over 9ef7380..81a5bbf: first bad 3505855, the #3530 commit itself; #3177 is clean). GNU renders function definitions only inside print_all_shell_variables' print_func_list arm (builtins/set.def:506-527; variables.c:1079-1090), reached solely from the no-operand listing. Mirror that cost shape: the funnels now take a lazy FunctionSetViewProvider and realize the views only in the listing arm (set with no args; declare's plain arm). The render itself (Executor::render_function_set_views over the functions and function_def_infos maps) is unchanged. What this change deletes: the eager per-dispatch full-table render at five executor call sites (execute_set and the four declare/local routes in declare_local.rs). Verification (X299, release build of this branch): - probe (150 functions x 12 lines, local-loop x2000): 33 s -> 1 s - bats junit suite, direct form: 221/216 ms per test -> 37/37 ms (pre-#3177: 34/36 ms; #3177 itself: 35/37 ms) - bats junit outer form: 43 s -> 17 s wall, 9/9 ok (#3177: 17 s) - listing outputs (bare declare/set/typeset, -F/-f/-p/-a forms, POSIX mode, bare local, declare --) byte-identical to master except the self-referential BASH=<exe path> lines - new pin tests/issue3230_declare_family_lazy_views_regressions.rs (scaling-ratio sentinel + listing-arm checks): 2/2 green; issue3487 pin 9/9 green; builtins::set/declare lib tests 16/16 UNVERIFIED-BY-CAPTAIN
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.
Refs #3487
根因
GNU 的无参列表是单一枚举器
print_all_shell_variables(builtins/set.def:506-527):先print_var_list印变量,再于非 POSIX 模式下print_func_list(variables.c:1079-1090)印函数定义。裸declare经 declare.def 无参臂(list == 0且flags_on == 0)分发到set_builtin(NULL),与裸set共用这张列表。rubash 侧
print_shell_variables(该枚举器的移植)只印了变量半:函数表在ShellState.functions,builtin 层看不到。裸set此前靠 execute_set 在 builtin 返回后自行 append 函数段(#1056)补上了这一半,裸declare没有对应 append——于是同一枚举器的两条入口一全一缺。修法
按 GNU 的机制面补全枚举器本身,不在 declare 入口再打补丁:
print_shell_variables新增函数半:变量段之后、非 POSIX 模式下(与既有 ansic 引号分支读同一个活posix选项),按名序逐个印FunctionSetView的多行定义文本。POSIX 门对应 set.def:518-520(PASC Interp declare -f re-serializes from AST instead of replaying definition text: leaks source-context redirect into } (rewrites 2> as 2>>), rewrites nested quotes in $() as \", drops -n in compound [[ ]] #202)。function_set_views()(与dynamic_set_views()同位组合):用declare -f/type同一个 ast_print 移植(multiline_function_def_text_with,含 body kind 与定义期重定向元数据)渲染每个函数,四个调用点(execute_set、execute_declare、execute_local 两路)与 dynamic 视图同位供给。__RUBASH_POSIX_MODE由 set_shell_option 与选项表保持同步)。GNU 锚点:builtins/declare.def 无参臂(
set_builtin ((WORD_LIST *)NULL));builtins/set.def:506-527print_all_shell_variables;variables.c:1079-1090print_func_list;variables.c:1152-1162print_var_function(FUNC_MULTILINE|FUNC_EXTERNAL)。探针以 GNU bash 5.3.20 oracle 干净环境脚本文件复核:函数按名序、位于全部变量之后(含zzzz_last变量先于afunc)、子 shell 体/定义期重定向/keyword 形格式、set -o posix后函数段消失、declare -p不含函数定义。回归钉
tests/issue3487_bare_declare_function_listing_regressions.rs(8 测,随第一笔提交先行):master 8b48c16 上 fail-first 5 过 / 3 红(bare_declare_prints_function_definition_block、bare_declare_functions_sorted_and_after_all_variables、bare_declare_function_shapes);修后 8/8。本 PR 删除了什么
functions/function_set_views参数,无状态包装层传空集,行为不变),无其他删除。UNVERIFIED-BY-CAPTAIN