Skip to content

WIP: grow stack at parser/executor recursion hubs (#1801) + #1803 recheck - #1836

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/clearance-recheck-duo
Oct 27, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/clearance-recheck-duo

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: mechanism fix for #1801 + recheck disposition for #1803 (cluster REPORT delivered to the captain separately; do not merge from this description alone).

#1801 — FIXED

Fixes #1801

Recheck on current master (8fffc99): the filed case-body pin test_case_body_keeps_arithmetic_for_semicolons_inside_nested_if still SIGSEGVs deterministically (3/3 isolated runs, rc=139) on a default libtest thread. GNU bash 5.3.20 runs the same script clean with the pin's expected output.

Mechanism (not a depth guard): the parser and executor are recursive tree walkers whose debug call chains burn ~150KB of stack per nesting level — the figure src/main.rs itself cites when it gives the binary driver a 512MiB stack thread (which is why the binary never crashed and only library hosts die). Measured on a 2MiB thread, pre-fix: if nesting dies at depth 6, function chains at depth 4, parse at depth 20 (SIGABRT), the filed pin's ~5-level nest at 2–3MB. GNU's contract is recursion bounded only by the real stack — its sole depth limit is FUNCNEST for functions (execute_cmd.c:324-325, enforced execute_cmd.c:5200 only when > 0; variables.c:5945 sv_funcnest). A library cannot assume its host owns a driver-sized stack, so the fix is at the resource layer:

  • New src/stack_growth.rs: ensure_stack = stacker::maybe_grow (1MiB red zone / 8MiB segments) — the mechanism rustc uses for recursive descent on host threads. New dependency: stacker 0.1 (+ psm).
  • Both recursion hubs route through it: Executor::execute_ast_inner (every nested command list funnels through it — compound/function/loop bodies, pipeline stages, comsub via execute_ast) and parser::parse_loop::run_command_loop (re-entered per nested section).
  • No depth is counted, no limit imposed, no thread migration (Executor stays a single-thread session object); behavior identical at every depth.

Regression pin (same commit): test_issue_1801_deep_nesting_runs_on_the_default_test_thread_stack (12-deep and 40-deep nested ifs, 30-deep function chain; GNU 5.3.20 expected outputs). Pre-fix it aborts with a stack overflow on the default test thread; post-fix it passes, as does the filed pin. Post-fix depth probes on a 2MiB thread: if=200, case/for/while=30, func=60, comsub=25, parse if=200 — all rc=0.

Gates: part_002 module 15/15; lib 773 passed / 1 failed (ownership_unary_operators_check_existing_file, the standing baseline failure) / 1 ignored (--skip login_posix_env); diffcorpus 306/306 against the rebuilt binary (first run 305 + ps06, adjudicated a timing flake by 3/3 isolated re-runs, second full run 306/306).

#1803 — recheck only, no code change

Refs #1803

Rechecked on 8fffc99: user_pua_length_counts_one_char still fails in a no-locale-vars environment (expected 1, got 3) and passes 16/16 under LC_ALL=C.UTF-8. Characterization: the pin's expectation presumes a UTF-8 locale — GNU gives 1 only under UTF-8, 6 under C (where glibc does not even decode \uE301, leaving the literal 6-byte text). Under every explicitly-set locale, current master matches GNU exactly. The pristine red is a no-locale environment artifact, not a carrier regression, so no carrier bytes were touched (highest-risk area). One residual incoherence is recorded in the cluster REPORT for the captain rather than fixed here: with no locale vars at all, rubash decodes \u to UTF-8 bytes but its ${#} gate defaults to single-byte (3), while GNU stays consistently in C (6) — a locale-default coherence question, not part of this pin's claim.

…flowing host threads (#1801)

The executor_tests case-body pin (nested if + =~ + arith-for inside a
case arm) SIGSEGVed deterministically on a default libtest thread, and
the crash class is general: the parser and executor are recursive tree
walkers whose debug call chains burn ~150KB of stack per nesting level
(the figure src/main.rs cites for the binary driver's 512MiB stack
thread), so any host driving the library on an ordinary thread dies at
~5 compound levels, ~4 function calls, or ~20 parse levels on a 2MiB
stack. The binary never crashed only because its driver pre-reserves
512MiB.

GNU anchor: recursion is the mechanism, bounded only by the real stack.
execute_cmd.c dispatches compound commands by recursive C calls, and
its only depth limit is FUNCNEST for function calls (execute_cmd.c:
324-325 funcnest/funcnest_max, enforced at execute_cmd.c:5200 only when
FUNCNEST > 0; variables.c:5945 sv_funcnest). GNU owns its process
stack; a library cannot assume its host's. The fix therefore sits at
the resource layer, not the semantics layer: both recursion hubs —
Executor::execute_ast_inner, through which every nested command list
funnels (compound bodies, function bodies, loop bodies, pipeline
stages, command substitution via execute_ast), and the parser's
run_command_loop, which every nested section re-enters — now pass
through stack_growth::ensure_stack (stacker::maybe_grow, 1MiB red
zone / 8MiB segments), growing the current thread's stack on demand.

No depth is counted, no limit is imposed, and execution never migrates
threads (Executor stays the single-thread session object it is);
behavior is identical at every depth, in debug and release alike. The
only new dependency is stacker 0.1 (with psm), the same mechanism
rustc uses for recursive descent on host threads.

Regression pin, same commit:
test_issue_1801_deep_nesting_runs_on_the_default_test_thread_stack —
12-deep and 40-deep nested ifs and a 30-deep function call chain,
expected outputs taken from GNU bash 5.3.20. Pre-fix the pin aborts
with a stack overflow on the default test thread, and the filed
case-body pin segfaulted 3/3; post-fix both pass, and depth probes
that died pre-fix at if=6/func=4/parse=20 on a 2MiB thread now run
clean at if=200, case/for/while=30, func=60, comsub=25.

Gates: executor_command_chaining part_002 15/15; lib 773 passed /
1 failed (builtins::test::tests::ownership_unary_operators_check_
existing_file — the standing baseline failure) / 1 ignored with
--skip login_posix_env; diffcorpus 306/306 against the rebuilt
binary.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 08:22
@caomengxuan666
caomengxuan666 merged commit 495cf86 into master Oct 27, 2026
9 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 27, 2026
Refs #1836. Since #1836 made rubash depend on stacker unconditionally,
every consumer cross-check also builds psm — and niubash's
aarch64-unknown-linux-ohos cross-target check now fails assembling
psm's src/arch/aarch_aapcs64.s (no such instruction / operand type
mismatch / bad register expression): psm 0.1.32 has no OpenHarmony
support anywhere (not in build.rs find_assembly's explicit rows, not
in its README platform table, not in its assembly sources).

Move the dependency behind a target cfg built from psm 0.1.32's own
support matrix: the architectures with an assembly implementation in
find_assembly (wasm32 excluded — precompiled object, README marks it
unsupported), crossed with the OSes its README table / assembly cover,
crossed with the environments those platforms use. The env factor is
what excludes OpenHarmony: its triples are target_os = "linux" with
target_env = "ohos".

src/stack_growth.rs (the only stacker consumer, via ensure_stack at
the two #1801 recursion hubs) gets the matching cfg split: inside the
matrix it calls stacker::maybe_grow with the unchanged red-zone /
segment constants; outside it invokes the closure directly, which is
exactly the pre-#1801 behavior. No call site changes; no cfg anywhere
else. Unblocks niubash PR #615, whose ohos check is the last red.

Co-authored-by: 曹梦轩 <[email protected]>
@caomengxuan666
caomengxuan666 deleted the fix/clearance-recheck-duo branch October 30, 2026 01:41
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.

[bug] executor_tests case-body test SIGSEGVs deterministically on pristine master (nested if + =~ + arith-for in case body; suspected stack overflow)

1 participant