Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 24, 2025

When blocks are refactored and wrapped in closures, labels from LabelNode elements were not being extracted and added to the block's labels list. This caused 'Can't find label' errors when refactored code tried to use those labels.

This minimal fix adds label extraction to createMarkedBlock() in LargeBlockRefactorer.java to properly handle labels in refactored blocks.

Test results with JPERL_LARGECODE=refactor:

  • op/pack.t: 14579/14726 passing (99.0% pass rate)
  • Matches baseline performance

When blocks are refactored and wrapped in closures, labels from LabelNode
elements were not being extracted and added to the block's labels list.
This caused 'Can't find label' errors when refactored code tried to use
those labels.

This minimal fix adds label extraction to createMarkedBlock() in
LargeBlockRefactorer.java to properly handle labels in refactored blocks.

Test results with JPERL_LARGECODE=refactor:
- op/pack.t: 14579/14726 passing (99.0% pass rate)
- Matches baseline performance
Changes:
1. Parse-time refactoring now runs automatically for large blocks
   - Removed dependency on JPERL_LARGECODE environment variable
   - Refactoring triggers automatically when block size exceeds threshold

2. Removed code-generation time refactoring from EmitBlock.java
   - Parse-time refactoring now handles all cases
   - No fallback needed at code-generation time

3. Added label extraction to createMarkedBlock()
   - Fixes 'Can't find label' errors in refactored blocks
   - Labels from LabelNode elements properly preserved

Test results:
- op/pack.t: 14579/14726 passing (99.0% pass rate)
- re/pat_advanced.t: 48/83 passing (57.8% pass rate)
- Matches baseline performance exactly
Changes:
1. Parse-time refactoring with conservative threshold (200 elements)
   - Handles extremely large blocks proactively
   - Avoids over-refactoring smaller blocks that don't need it

2. Code-generation time refactoring as fallback (50 elements)
   - Catches blocks between 50-200 elements
   - Uses bytecode size estimation at code-gen time

3. Label extraction in createMarkedBlock()
   - Fixes 'Can't find label' errors in refactored blocks

Test results (all match baseline):
- op/pack.t: 14579/14726 (99.0%)
- re/pat_advanced.t: 48/83 (57.8%)
- re/regexp_unicode_prop.t: 819/1110 (73.8%)
- op/hexfp.t: 120/125 (96.0%)
- Overall: 15566/16044 (97.0%)
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