fix(aiken-lang): include same-module function dependencies in UPLC export (#1333)#1
Open
knoal wants to merge 3 commits into
Open
fix(aiken-lang): include same-module function dependencies in UPLC export (#1333)#1knoal wants to merge 3 commits into
knoal wants to merge 3 commits into
Conversation
added 3 commits
July 5, 2026 23:14
…port When a public function calls a same-module private helper function, aiken export was producing UPLC where the helper appeared as a free variable reference rather than including its definition. Root cause: hoist_function creates Air::DefineFunc nodes with the function body embedded, and the code generator produces the correct UPLC structure (lambda/apply wrapping), but the helper function was never registered in key_to_func. This meant the function call site couldn't be resolved at runtime. Fix: after hoisting a function that exists in self.functions (i.e., a user-defined function, not a compiler-builtin), register it in key_to_func via insert_new_function so DefineFunc processing can find it. Regression test added in aiken-project. Fixes aiken-lang#1333
- Collapse 6-line comment block to 2 lines - Destructure body directly in the HoistableFunction::Function match arm - Drop intermediate func_body_vec and func_def bindings - Separate borrow scopes to satisfy the borrow checker cleanly
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
When exporting a function that calls a same-module private helper function,
aiken exportproduces UPLC where the helper appears as a free variable reference rather than including its definition.Repro from aiken-lang#1333:
Running
aiken exportand evaluating the exportedmainwithamaru-uplcgives:Root Cause
In
hoist_function, when a same-module function dependency is hoisted onto the validator tree:Air::DefineFuncnode is created with the function body embeddedlambda(func_name).apply(func_body)wrapping)key_to_funcviainsert_new_functionWithout registration in
key_to_func, theDefineFunc-generated UPLC creates a local variable binding that nothing resolves — leaving a free variable at the call site.Fix
After hoisting a user-defined function (identified by being present in
self.functions), register it inkey_to_funcviainsert_new_function. This ensures theDefineFuncprocessing can look up the function and generate the correctVarreference.The fix is guarded with
self.functions.contains_key(key)to skip compiler-builtin functions (which use a different registration path).Testing
aiken-project --libtests passexport_same_module_dependencyincrates/aiken-project/src/export.rsFixes aiken-lang#1333