fix(ir): derive internal function return types from declarations#56
Merged
Conversation
✅ Deploy Preview for edgelang ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
lgtm |
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.
Summary
Fixes #49 — Internal (non-pub) functions had their return type hardcoded to
u256in IR lowering, regardless of their actual declaration. Functions returningbool,addr,void, or tuples all got wrong IR type annotations.The Bug
crates/ir/src/to_egglog/function.rsinlower_internal_function_body():This meant every internal function call site assumed a
u256return, which could silently corrupt values for functions returningbool,addr, or other types.The Fix
Thread the declared return type through the call chain:
ContractFunctiontype — extended from 3-tuple to 4-tuple, addingVec<TypeSig>for returnsemit_call— now accepts and forwardsreturnstolower_internal_function_bodylower_internal_function_body— replaces hardcodedUIntT(256)withself.returns_to_type(returns)This mirrors what
lower_function()already does correctly for standalone free functions —returns_to_type()handles all cases: 0 returns →UnitT, 1 return →lower_type_sig, multiple →TupleT.Files Changed
crates/ir/src/to_egglog/mod.rsContractFunctiontype + population sitecrates/ir/src/to_egglog/function.rslower_internal_function_bodysignature + return type derivationcrates/ir/src/to_egglog/calls.rsemit_callsignature + all call sitesTests Added
3 e2e tests verifying internal function return types work correctly at runtime:
check_positive(x) -> (bool)called from pub fn; verifies both true and false casesdouble(x) -> (u256)still works correctlyAll 656+ workspace tests pass.