Skip to content

Commit

Permalink
Reduce cloning happening in compile_deep.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivorforce committed Jul 16, 2024
1 parent be127eb commit 64c7209
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/interpreter/compile/compile_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,31 @@ impl CompileServer {
self.simplify.run(source);

let needed_functions = self.simplify.refactor.gather_needed_functions(source);
let fn_logic = self.simplify.refactor.fn_logic.clone();

let mut errors = vec![];

for function in needed_functions {
match &fn_logic[&function] {
// FIXME We shouldn't clone it here... But compile_descriptor needs a mutable ref to self
// because it needs to insert inlines AND data layouts. Which means the mutable ref can
// get invalidated.
match self.simplify.refactor.fn_logic[&function].clone() {
FunctionLogic::Descriptor(d) => {
if self.function_inlines.contains_key(&function) || self.function_evaluators.contains_key(&function.function_id) {
continue
}

compile_descriptor(&function, d, self);
compile_descriptor(&function, &d, self);
}
FunctionLogic::Implementation(implementation) => {
match compile_function(self, implementation) {
match compile_function(self, &implementation) {
Ok(compiled) => drop(self.function_evaluators.insert(function.function_id, compiled)),
Err(err) => errors.extend(err),
};
}
}
}

let FunctionLogic::Implementation(implementation) = &fn_logic[function] else {
let FunctionLogic::Implementation(implementation) = &self.simplify.refactor.fn_logic[function] else {
errors.push(RuntimeError::error("main! function was somehow internal after refactor."));
return Err(errors);
};
Expand Down

0 comments on commit 64c7209

Please sign in to comment.