Repository navigation
Share runtime instances across call sites - #1618
Merged
Merged
Conversation
Callee semantic keys carried caller-only identity, so every recv arm and every calling module got its own copy of each helper it reached, with identical bodies. Sonatina's function merge folded some copies back, but not reliably: the v3 factory shipped a second 1.8 KB `modify_position`. - `EffectProviderSubst` holds the resolved provider bindings. Call-site provenance stays in the typed body; everything it determines already flows into the key through the substitution and the binding. - Root providers name the contract or function whose registrations they come from, not the arm that materialized them. - Concrete free and inherent functions, including effectful ones, shed caller assumptions the way concrete trait impls do. - Context-independent callees normalize at their caller's ingot root rather than a module. Library paths and impl selection resolve per ingot, and a body can need impls only the caller's ingot sees, such as `Encode<Sol>` for a panic payload. - Stable keys name the ingot of the normalization scope, since every ingot's root module has the same name. In the v3 port, the UniswapV3Factory module drops from 177 duplicate instances to 8 (init vs runtime copies or different parameter classes), and the factory runtime shrinks from 24916 to 22272 bytes, back under EIP-170.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
|
Amazing 😍 |
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Callee semantic instance keys carried details that only identify the caller. As a result, every recv arm and every calling module got its own copy of each helper it reached, even though the bodies were identical. Sonatina's exact function merge folded some copies back together, but not reliably. The Uniswap v3 port's
UniswapV3Factoryshipped a second 1.8 KBmodify_positionand went over EIP-170 (24916 bytes).In the factory module, the colliding keys differed in three places:
ProviderSource::RootProvider { site }named the recv arm, although every arm of a contract shares the contract's root-provider registrations.EffectProviderSubststoredEffectProviderSpecializations, whose provenance names the caller's body and binding. It's only needed while the call site is being resolved; everything it determines already flows into the key through the substitution and the resolvedProviderBinding.MemBuffer::alloc,MemSlice::len, ...) and effectful free functions never took the context-independent path, so they inherited the calling module's scope and assumptions.Change
EffectProviderSubstholdsProviderBindings.ProviderSource::RootProvidercarries aRootProviderScope(FuncorContract) instead of the arm's site.Result::unwraploweringpanic_with_valuetostd::evm::revertwithEncode<Sol>for a user error type. Library paths and impl selection resolve per ingot, so the ingot root is the canonical choice.Results
Uniswap v3 port at
--optimize s, runtime bytes:createPoolgoes from 268k gas more than Solidity to 265k less.A few helpers that used to be inlined per arm are now shared and outlined, which costs some gas in small paths (e.g.
NoDelegateCalloverhead). fe-lang/sonatina#339 addresses the larger memory-placement cost behind those paths.Tests
recv_arms_share_helper_instances: a helper called from two arms, plus the std helpers they reach, is emitted once.StorageMap<.., 0>vs<.., 1>) stay distinct. These replace a test that required two identicalStorageMap<.., 0>providers to produce distinct instances.cargo nextest r --release, clippy, and fmt all pass.