Skip to content

[FLINK-40605][table-code-splitter] Allow splitting if blocks containing loops with jump statements - #29141

Open
ChaomingZhangCN wants to merge 1 commit into
apache:masterfrom
ChaomingZhangCN:codex/fix-code-splitter-nested-jumps
Open

[FLINK-40605][table-code-splitter] Allow splitting if blocks containing loops with jump statements#29141
ChaomingZhangCN wants to merge 1 commit into
apache:masterfrom
ChaomingZhangCN:codex/fix-code-splitter-nested-jumps

Conversation

@ChaomingZhangCN

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fix code splitting for large if blocks containing nested loops with break or continue.

Currently, BlockStatementSplitter skips a statement whenever its subtree contains any return, break, or continue. This is overly conservative for an enclosing block containing a self-contained loop: even a small loop with a jump can prevent the surrounding large block from being split, leaving generated methods that fail compilation with Code grows beyond 64 KB.

This change allows such enclosing blocks to be split while retaining conservative guards for return statements and loop-body extraction.

Brief change log

  • Track return statements separately from the combined return/jump count.
  • Allow enclosing blocks containing self-contained loops with jumps to be extracted.
  • Preserve the restrictions on extracting blocks containing returns and loop bodies containing jumps.
  • Add rewrite fixtures and compilation/execution regression tests covering oversized branches, break, continue, labeled jumps, and early returns.

Verifying this change

Added regression tests that generate an oversized if branch containing a short loop with either break or continue, run the complete JavaCodeSplitter pipeline, compile the output with Janino, and verify execution results.

Both oversized-branch test cases fail on the unmodified base commit with Code grows beyond 64 KB and pass with this change. The tests also verify that skipped branches remain unexecuted and that statements following a jump execute correctly.

Additional execution tests verify labeled break/continue and early-return behavior.

The complete code-splitter module test suite was run with its reactor dependencies using JDK 17 and the repository's Maven wrapper:

./mvnw -pl flink-table/flink-table-code-splitter -am \
  -Drat.skip=true \
  '-Dtest=org.apache.flink.table.codesplit.*Test' \
  -Dsurefire.failIfNoSpecifiedTests=false \
  test

Result: 54 tests, 0 failures, 0 errors, and 1 pre-existing skipped test.

Spotless and Checkstyle checks also passed. The reactor command skips the repository-wide RAT scan; a module-scoped RAT check was run separately and passed. The full repository test suite was not run.

Does this pull request potentially affect one of the following parts:

  • Dependencies: no.
  • Public API: no.
  • Serializers: no.
  • Runtime per-record code paths: yes, generated code may be split into additional helper methods; no hand-written runtime operator changes.
  • Deployment or recovery infrastructure: no.
  • S3 file system connector: no.

Documentation

  • Does this pull request introduce a new feature? No, this is a code-splitting bug fix.
  • How is the feature documented? Not applicable.

Was generative AI tooling used to co-author this PR?
  • Yes.

Generated-by: Codex CLI 0.153.4

… jump statements

Keep return statements and loop jumps within their original control-flow scope while allowing enclosing blocks with self-contained loops to be extracted.

Add compiler and execution regressions for oversized branches, break/continue, labeled jumps, and early returns.

Generated-by: Codex CLI 0.153.4
@flinkbot

flinkbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@ChaomingZhangCN ChaomingZhangCN changed the title [table-code-splitter] Allow splitting if blocks containing loops with jump statements [FLINK-40605][table-code-splitter] Allow splitting if blocks containing loops with jump statements Sep 9, 2026
@ChaomingZhangCN

Copy link
Copy Markdown
Contributor Author

@JingsongLi Hi, could you please review this PR for FLINK-40605, which fixes a remaining 64 KB code-splitting issue in large if blocks containing loops with break or continue?

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