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

make code dryer, #5566

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/wasm-lib/kcl/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{
},
fs::FileManager,
modules::{ModuleId, ModulePath},
parsing::ast::types::{Expr, ImportPath, Node, NodeRef, Program},
parsing::ast::types::{Expr, ImportPath, NodeRef},
settings::types::UnitLength,
source_range::SourceRange,
std::StdLib,
Expand Down Expand Up @@ -532,8 +532,7 @@ impl ExecutorContext {
}
}

exec_state.add_root_module_contents(&program);
let result = self.inner_run(&program.ast, &mut exec_state, true).await?;
let result = self.inner_run(&program, &mut exec_state, true).await?;

// Restore any temporary variables, then save any newly created variables back to
// memory in case another run wants to use them. Note this is just saved to the preserved
Expand Down Expand Up @@ -646,8 +645,7 @@ impl ExecutorContext {
(program, exec_state, false)
};

exec_state.add_root_module_contents(&program);
let result = self.inner_run(&program.ast, &mut exec_state, preserve_mem).await;
let result = self.inner_run(&program, &mut exec_state, preserve_mem).await;

if result.is_err() {
cache::bust_cache().await;
Expand Down Expand Up @@ -699,19 +697,19 @@ impl ExecutorContext {
self.send_clear_scene(exec_state, Default::default())
.await
.map_err(KclErrorWithOutputs::no_outputs)?;
exec_state.add_root_module_contents(program);
self.inner_run(&program.ast, exec_state, false).await
self.inner_run(program, exec_state, false).await
}

/// Perform the execution of a program. Accept all possible parameters and
/// output everything.
async fn inner_run(
&self,
program: &Node<Program>,
program: &crate::Program,
exec_state: &mut ExecState,
preserve_mem: bool,
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclErrorWithOutputs> {
let _stats = crate::log::LogPerfStats::new("Interpretation");
exec_state.add_root_module_contents(program);

// Re-apply the settings, in case the cache was busted.
self.engine
Expand All @@ -720,7 +718,7 @@ impl ExecutorContext {
.map_err(KclErrorWithOutputs::no_outputs)?;

let env_ref = self
.execute_and_build_graph(program, exec_state, preserve_mem)
.execute_and_build_graph(&program.ast, exec_state, preserve_mem)
.await
.map_err(|e| {
let module_id_to_module_path: IndexMap<ModuleId, ModulePath> = exec_state
Expand Down
Loading