Expand description
The Function Inlining pass traverses the AST and inlines function at their call site.
See https://en.wikipedia.org/wiki/Inline_expansion for more information.
The pass also reorders Function
s in a reconstructed ProgramScope
so that they are in a post-order of the call graph.
In other words, a callee function will appear before a caller function in the order.
Consider the following flattened Leo code.
function main(flag: u8, value: u8) -> u8 {
$var$0 = flag == 0u8;
$var$1 = foo(value);
value$2 = $var$1;
value$3 = $var$0 ? value$2 : value;
return value$3;
}
inline foo(x: u8) -> u8 {
$var$4 = x * x;
return $var$4;
}
The inlining pass produces the following code.
inline foo(x: u8) -> u8 {
$var$4 = x * x;
return $var$4;
}
function main(flag: u8, value: u8) -> u8 {
$var$0 = flag == 0u8;
$var$4$5 = value * value;
$var$1 = $var$4$5;
value$2 = $var$1;
value$3 = $var$0 ? value$2 : value;
return value$3;
}
Re-exportsยง
pub use assignment_renamer::*;
pub use function_inliner::*;
Modulesยง
- inline_
expression ๐ - inline_
program ๐ - inline_
statement ๐