Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inlining functions #32

Open
Sword-Smith opened this issue Aug 19, 2023 · 2 comments
Open

Add support for inlining functions #32

Sword-Smith opened this issue Aug 19, 2023 · 2 comments

Comments

@Sword-Smith
Copy link
Contributor

Sword-Smith commented Aug 19, 2023

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. CompiledFunction gets a field inline which defaults to false.
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.

@Sword-Smith
Copy link
Contributor Author

Sword-Smith commented Aug 22, 2023

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

  1. start with a label
  2. contain no recurse instructions
  3. contain only one return instruction
  4. The last instruction in the return instruction

So for this, we would also want a method

impl SubRoutine {
    pub(crate) fn can_be_inlined(&self) -> bool {
        todo!()
    }
}

@Sword-Smith
Copy link
Contributor Author

@junkicide

Sword-Smith added a commit that referenced this issue Aug 23, 2023
With this commit, the code is concatenated later in the compilation pipeline.
This will allow us inline functions after the TASM code generation but before
the final code concatenation. Cf. #32.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant