Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 23, 2025

Summary

This PR removes code-generation time AST refactoring from the EmitBlock class, ensuring that all refactoring happens exclusively at parse time.

Changes

  • Remove LargeBlockRefactorer.processBlock() call from EmitBlock.emitBlock()
  • Remove unused processBlock, shouldRefactorBlock, and tryWholeBlockRefactoring methods from LargeBlockRefactorer
  • Remove unused EmitterVisitor import

Rationale

Refactoring should only happen during the parsing phase when the AST is being constructed. Modifying the AST during code generation violates the separation of concerns between parsing and code emission phases.

Impact

  • Refactoring now only occurs at parse time via BlockNode constructor calling LargeBlockRefactorer.maybeRefactorBlock()
  • The AST is finalized before bytecode emission begins
  • Code generation phase no longer modifies the AST structure

- Remove LargeBlockRefactorer.processBlock() call from EmitBlock.emitBlock()
- Remove unused processBlock, shouldRefactorBlock, and tryWholeBlockRefactoring methods
- Remove unused EmitterVisitor import
- Refactoring now only happens at parse time via BlockNode constructor
- This prevents AST modification during code generation phase
- Rewrite buildNestedStructure to place closures at tail position instead of head
- This ensures variable declarations execute before closures that use them
- Add variable declaration detection to shouldBreakChunk
- Treat my/our/local declarations as chunk breakers to preserve lexical scope
- Prevents variables from being hidden inside closures
- Remove error throwing when large blocks contain control flow statements
- Simply skip refactoring for blocks with last/next/redo/goto
- This accepts the limitation that some large blocks cannot be refactored
- Fixes regressions in op/pack.t and re/pat_advanced.t
- Change isRefactoringEnabled to return true by default
- Set JPERL_LARGECODE=disable to turn off refactoring
- This is necessary since we removed code-gen time refactoring
- Without this, large test files fail to compile
- Fixes regression where op/pack.t and re/pat_advanced.t produced 0 tests
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.

2 participants