Skip to content

Compiler: scan repeated loop-body captures once #618

Description

@chrisbbreuer

Parents: #465, #493, #496
Related: #616

Problem

Repeated loop-body admission still multiplies lexical declaration count by body AST size. loopBodyCapturesLexical, repeatedBodyCapturesSupported, predeclareRepeatedBodyNode, emitDeclareRepeatedBodyNode, and repeatedBodyListNeedsEnvironment each answer per-binding capture questions through another exhaustive nameRefInClosure(body, name, false) walk. A wide block-scoped body with a large closure-free tail therefore performs declaration-count × body-size compiler-classification work before bytecode emission.

This is distinct from #616, which owns lexical names in the for/for-in/of head. This child owns block-scoped declarations inside bodies repeated by while, do-while, for, and for-in/of, including the shared CaseBlock handling for switches nested in such bodies.

Scope

  • Freeze production parse + plain-function admission/compile growth witnesses before changing the classifier.
  • Collect repeated-body lexical binding names once across the exact existing block/if/try/switch/labeled boundaries while leaving nested loops/functions to their own roots.
  • Traverse the repeated-body AST once to classify exact names referenced from nested closures or deferred class bodies.
  • Reuse one compile-owned capture result for support checks, lexical predeclaration, Environment Record declaration, and environment-need decisions.
  • Preserve conservative shadowing, catch/destructuring behavior, nested-loop ownership, bytecode fallback, structural checksum, and allocation accounting.
  • Keep zero- and one-binding common cases allocation-minimal.

No-workaround rules

  • No syntax refusal, heuristic cutoff, skipped body region, runtime TDZ broadening, tree-walker fallback presented as optimization, source rewriting, or weakened per-iteration Environment semantics.
  • No process-global or cross-compilation mutable cache.
  • A new AST node kind must not silently bypass capture classification.

Acceptance

  • 1K/2K/4K wide-body growth and unrelated/first/last/destructuring/catch/switch/nested-loop controls preserve exact admission and structural checksums.
  • Parent → candidate exact evidence demonstrates bounded classifier scaling with allocation metrics and names the complete scored boundary.
  • Captured declarations retain fresh per-iteration bindings; uncaptured declarations remain slot-backed in forced tree-walker and required-bytecode execution.
  • Focused compiler/frontend, full units, relevant Test262 loop/block/lexical subtrees, and applicable TSan gates pass with exact before → after accounting.
  • Evidence and parent issues are cross-linked without converting diagnostic wall noise into a public claim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjitBytecode, baseline JIT, optimizer, and code generationperformanceMeasured runtime, memory, scaling, or build performanceruntimeJavaScript runtime and builtin implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions