Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 23, 2025

This PR fixes the closure placement in large block refactoring to use tail position instead of head position, which preserves lexical scoping for variable declarations.

Changes

  1. Tail Position Closures: Rewrote to place closures at the end of blocks instead of the beginning. This ensures variable declarations execute before closures that might use them.

  2. Skip Unsafe Control Flow: Removed error throwing for blocks with unsafe control flow (last/next/redo/goto). Now simply skips refactoring for such blocks.

  3. Increased Bytecode Limit: Raised from 30000 to 40000 bytes to allow larger blocks before requiring refactoring.

Testing

Tested with :

  • : 14676 tests pass
  • : 83 tests pass

Impact

This change improves lexical scoping preservation when refactoring is enabled, allowing variable declarations to remain visible to subsequent code including closures.

- Rewrite buildNestedStructure to place closures at tail position instead of head
- This ensures variable declarations execute before closures that use them
- Preserves lexical scoping by keeping direct elements at the start of blocks
- Remove error throwing for blocks with unsafe control flow
- Simply skip refactoring for blocks containing last/next/redo/goto statements
- Increase LARGE_BYTECODE_SIZE limit from 30000 to 40000 bytes
- Allows larger blocks before requiring refactoring
@fglock fglock merged commit 80842d8 into master Dec 23, 2025
2 checks passed
@fglock fglock deleted the fix/closure-tail-position branch December 23, 2025 11:34
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