Open Sword-Smith opened 11 months ago
I think this should be an optimization step performed directly on TASM code -- that way we do not make the already very complicated code generation step even bigger. I suggest to implement function inlining like this.
impl OuterFunctionTasmCode {
/// Return the names of the subroutines that should be inlined, those whose function body is shorter or equal to the input length
fn get_subroutines_for_inling(&self, subroutine_length_threshold: usize) -> Vec<String> {
todo!()
}
/// Perform the function inlining that mutates the `CompiledTasm` data structure
fn inline(&mut self, subroutine_names: Vec<String>) {
todo!()
}
The subroutines that contain recurse
cannot be inlined. We should probably only inline the subroutines that
recurse
instructionsreturn
instructionreturn
instructionSo for this, we would also want a method
impl SubRoutine {
pub(crate) fn can_be_inlined(&self) -> bool {
todo!()
}
}
@junkicide
Currently we are calling a function each time read from public input, or print to it. We should just inline the function body instead of calling a function.
I suggest that e.g.The inlining should happen after code generation, since the code generation step is already too big. We want to avoid making the most complicated step (intermediate AST -> TASM) more complicated than it already is. It's already too complicated.CompiledFunction
gets a fieldinline
which defaults tofalse
.