Skip to content

(opt): reprocess replaced block ends for inlining - #10349

Merged
orizi merged 1 commit into
mainfrom
orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding
Aug 25, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding

Conversation

@orizi

@orizi orizi commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

The interleaved inlining/const-folding pass scans a block's statements for
inlinable calls before const folding visits the block end. When that visit
replaces the end it may append new statements (e.g. rewriting a match on
x - 1 into a call to an inc/dec function), which nothing scanned again, so
such calls were only inlined if the containing function was itself later
inlined into a caller - otherwise they survived as un-inlined calls (see the
removed u32_inc call in the function_generator golden).

Reprocess the statements appended by a block-end replacement, similar to the
reprocessing of replaced statements. This slightly shrinks generated code
(e.g. the libfuncs_coverage contract).

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

@orizi
orizi force-pushed the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch 2 times, most recently from caec800 to 6faccdd Compare August 16, 2026 10:20
@orizi
orizi force-pushed the orizi/08-14-_opt_memoize_function_code_size_estimation branch from d526b81 to 01aab53 Compare August 16, 2026 10:20
@orizi orizi changed the title (opt): inline calls appended to a block by const folding (opt): fold overflowing add/sub by one directly into bounded-int ops Aug 16, 2026
@orizi
orizi force-pushed the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch from 6faccdd to 7a3da04 Compare August 16, 2026 10:56
@orizi orizi changed the title (opt): fold overflowing add/sub by one directly into bounded-int ops (opt): reprocess replaced block ends for inlining Aug 16, 2026
@orizi
orizi changed the base branch from orizi/08-14-_opt_memoize_function_code_size_estimation to graphite-base/10349 August 16, 2026 10:58
@orizi
orizi force-pushed the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch from 7a3da04 to 5a923b2 Compare August 25, 2026 07:54
@orizi
orizi force-pushed the graphite-base/10349 branch from 01aab53 to 4c8faf9 Compare August 25, 2026 07:54
@orizi
orizi changed the base branch from graphite-base/10349 to main August 25, 2026 07:54
@orizi
orizi force-pushed the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch from 5a923b2 to 05e51e7 Compare August 25, 2026 07:57
The interleaved inlining/const-folding pass scans a block's statements for
inlinable calls before const folding visits the block end. When that visit
replaces the end it may append new statements (e.g. rewriting a match on
`x - 1` into a call to an inc/dec function), which nothing scanned again, so
such calls were only inlined if the containing function was itself later
inlined into a caller - otherwise they survived as un-inlined calls (see the
removed `u32_inc` call in the function_generator golden).

Reprocess the statements appended by a block-end replacement, similar to the
reprocessing of replaced statements. This slightly shrinks generated code
(e.g. the libfuncs_coverage contract).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@orizi
orizi force-pushed the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch from 05e51e7 to 1f2e292 Compare August 25, 2026 08:00
@orizi
orizi marked this pull request as ready for review August 25, 2026 08:03
@cursor

cursor Bot commented Aug 25, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core lowering/inlining and const-folding interaction; wrong indexing or double visit_block_end could mis-inline or corrupt CFG, though behavior is covered by updated compiler golden tests.

Overview
Fixes a gap in the interleaved inlining + const-folding pass: inlinable calls were only searched in the block’s original statements, so when const folding rewrote a block end and prepended new calls (e.g. turning x - 1 into an inc/dec call), those calls were skipped unless the whole function was later inlined elsewhere.

The inline loop now invokes visit_block_end mid-scan when it reaches the end of the statement list, uses the returned prepend count to advance the index, and keeps scanning—including those newly appended statements—for should_inline. Const folding’s visit_block_end returns how many statements were spliced in, relaxes reachability asserts when a match end is revisited after inlining moves it to a continuation block, and runs try_specialize_call on inc/dec calls inserted during enum block-end lowering.

Golden Sierra output and Starknet compiled-class hashes/bytecode update accordingly (e.g. u32_inc replaced by bounded-int paths in generator tests; slightly smaller libfuncs coverage contract).

Reviewed by Cursor Bugbot for commit 1f2e292. Bugbot is set up for automated code reviews on this repo. Configure here.

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware reviewed 7 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi added this pull request to the merge queue Aug 25, 2026
Merged via the queue into main with commit 59cc18e Aug 25, 2026
55 checks passed
@orizi
orizi deleted the orizi/08-14-_opt_inline_calls_appended_to_a_block_by_const_folding branch August 31, 2026 12:47
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.

3 participants