Repository navigation
WIP: fix(expansion): stop assignment pre-scan expanding operator words (#1953) - #1958
Merged
Merged
Conversation
…words (#1953) The `:=`/`=` pre-scan (apply_parameter_assignment_expansion_with_context) split every ${...} body on its first top-level `=`/`:=` and expanded the split's "value" BEFORE any apply arm validated the left-hand side. For a body whose real operator comes first — ${a:-x=${a:-...}} (the c14 construction: a `:-` default word carrying a literal `x=` segment plus a nested expansion) — the split names `a:-x` as the "target" and the rest of the default word as the "value", so the pre-scan fully expanded the nested fragment and then discarded the result when every apply arm rejected the name. Per nesting level that is one extra full expansion of the inner fragment: depth 10 cost 1778ms and depth 15 never finished on the frozen tip, while GNU bash 5.3.20 is millisecond-class at depth 400. The phantom evaluation was also observable without nesting: a command substitution inside an unselected default word ran twice, and three times when selected (pre-scan passes + the real pass), where GNU runs it zero / one times. GNU anchor: parameter_brace_expand (subst.c:9777) extracts the parameter name first and dispatches on the FIRST operator character (subst.c:9886-9917), and parameter_brace_expand_word (subst.c:7663) expands an operator's word only when that operator selects it. An `=`/`:=` inside another operator's word is word text, never an assignment operator. Fix the invariant instead of the symptom: both pre-scan arms now admit a split only when its left-hand side is syntactically an assignment target (plain shell name, subscripted name — the admission apply_array_element_parameter_assignment itself uses — or either behind the `!` indirect prefix). Otherwise the fragment is not an assignment fragment and the pre-scan leaves it entirely to the real pass. Genuine binds (scalar, element, associative, cross-fragment) are unchanged. Regression pins (tests/issue1953_nested_default_blowup_regressions.rs), all expectations measured against GNU bash 5.3.20: depth ladder 10/15/25 byte-identical, depth-100 polynomial-growth + absolute-cap sanity, word side effect runs exactly once when selected and never when unselected, `=`/`:=` text inside a default word is not a bind, and genuine assignment fragments still bind.
Member
Author
|
门账汇总(同条件双边对照,工件 ~/workspace/fix-1953/logs/,全卷 REPORT 见工作区 fix-1953/REPORT.md):
残留一条(PR 正文已注): |
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.
WIP: #1953 nested
${a:-…}exponential blowup — freeze-exception audit fixFixes #1953
Root cause
The
:=/=assignment pre-scan (apply_parameter_assignment_expansion_with_context, src/executor/parameter_words.rs) split every${...}body on its first top-level=/:=and expanded the split's "value" before any apply arm validated the left-hand side. For the c14 construction${a:-x=${a:-…}}— a:-default word carrying a literalx=segment plus a nested expansion — the split namesa:-xas the "target" and the rest of the default word as the "value", so the pre-scan fully expanded the nested fragment and then discarded the result when every apply arm rejected the name. One extra full inner expansion per nesting level: depth 10 = 1778ms, depth 15/20/25 never finished (>20s, zero output) on the frozen tip, vs GNU bash 5.3.20 millisecond-class at depth 400.The phantom evaluation is observable without nesting too: a command substitution inside an unselected default word ran twice (GNU: zero), and three times when selected (GNU: once) — the pre-scan passes plus the real pass.
GNU anchor:
parameter_brace_expand(subst.c:9777) extracts the parameter name first and dispatches on the FIRST operator character (subst.c:9886-9917);parameter_brace_expand_word(subst.c:7663) expands an operator's word only when that operator selects it. An=/:=inside another operator's word is word text, never an assignment operator.Fix (mechanism, not shape)
Both pre-scan arms now admit a split only when its left-hand side is syntactically an assignment target — plain shell name, subscripted name (the admission
apply_array_element_parameter_assignmentitself uses), or either behind the!indirect prefix (parameter_assignment_target_form). Otherwise the fragment is not an assignment fragment and the pre-scan leaves it entirely to the real pass. +39 lines, one file. Genuine binds (scalar / element / associative / cross-fragment ordering) verified unchanged against GNU.Verification (all expectations GNU bash 5.3.20)
len=22/32/42/52).tests/issue1953_nested_default_blowup_regressions.rs(6 tests: ladder 10/15/25, depth-100 polynomial-growth + absolute-cap, side-effect once/never,=/:=text in a default word is not a bind, genuine binds still apply).-D warnings— results land in the cluster REPORT and a follow-up comment here.Known residual (NOT this PR)
${v=x:=y}: GNU bindsvtox:=y; rubash produces the right expansion value but never binds (the pre-scan's:=arm claims the fragment with an invalid composed name and returns before the=arm). Pre-existing on the frozen tip, unchanged by this PR — flagged for a separate issue.