no extra executes

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-04-05 14:41:22 -07:00
parent cb2368dc17
commit 729ca08eef
4 changed files with 26 additions and 16 deletions

View File

@ -484,12 +484,12 @@ impl ExecutorContext {
let result = match &mut repr {
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
ModuleRepr::Kcl(_, Some((env_ref, items))) => Ok((*env_ref, items.clone())),
ModuleRepr::Kcl(_, Some((_, env_ref, items))) => Ok((*env_ref, items.clone())),
ModuleRepr::Kcl(program, cache) => self
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
.await
.map(|(_, er, items)| {
*cache = Some((er, items.clone()));
.map(|(val, er, items)| {
*cache = Some((val, er, items.clone()));
(er, items)
}),
ModuleRepr::Foreign(geom) => Err(KclError::Semantic(KclErrorDetails {
@ -524,13 +524,14 @@ impl ExecutorContext {
let result = match &mut repr {
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
ModuleRepr::Kcl(_, Some((val, _, _))) => Ok(val.clone()),
ModuleRepr::Kcl(program, cached_items) => {
let result = self
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
.await;
match result {
Ok((val, env, items)) => {
*cached_items = Some((env, items));
*cached_items = Some((val.clone(), env, items));
Ok(val)
}
Err(e) => Err(e),
@ -2302,14 +2303,16 @@ impl FunctionSource {
#[cfg(test)]
mod test {
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
use super::*;
use crate::{
execution::{memory::Stack, parse_execute, ContextType},
parsing::ast::types::{DefaultParamVal, Identifier, Parameter},
ExecutorSettings,
};
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
#[tokio::test(flavor = "multi_thread")]
async fn test_assign_args_to_params() {

View File

@ -4,13 +4,13 @@ use anyhow::Result;
use schemars::JsonSchema;
use serde::Serialize;
use super::{types::UnitLen, EnvironmentRef, ExecState, MetaSettings};
use crate::{
errors::KclErrorDetails,
execution::{
annotations::{SETTINGS, SETTINGS_UNIT_LENGTH},
types::{NumericType, PrimitiveType, RuntimeType},
Face, Helix, ImportedGeometry, Metadata, Plane, Sketch, Solid, TagIdentifier,
types::{NumericType, PrimitiveType, RuntimeType, UnitLen},
EnvironmentRef, ExecState, Face, Helix, ImportedGeometry, MetaSettings, Metadata, Plane, Sketch, Solid,
TagIdentifier,
},
parsing::ast::types::{
DefaultParamVal, FunctionExpression, KclNone, Literal, LiteralValue, Node, TagDeclarator, TagNode,

View File

@ -780,7 +780,10 @@ impl ExecutorContext {
)
.await;
results_tx.send((module_id, module_path, result)).await.unwrap();
results_tx
.send((module_id, module_path, result))
.await
.unwrap_or_default();
});
}
#[cfg(not(target_arch = "wasm32"))]
@ -800,7 +803,10 @@ impl ExecutorContext {
)
.await;
results_tx.send((module_id, module_path, result)).await.unwrap();
results_tx
.send((module_id, module_path, result))
.await
.unwrap_or_default();
});
}
}
@ -809,13 +815,13 @@ impl ExecutorContext {
while let Some((module_id, _, result)) = results_rx.recv().await {
match result {
Ok((_, session_data, variables)) => {
Ok((val, session_data, variables)) => {
let mut repr = exec_state.global.module_infos[&module_id].take_repr();
let ModuleRepr::Kcl(_, cache) = &mut repr else {
continue;
};
*cache = Some((session_data, variables.clone()));
*cache = Some((val, session_data, variables.clone()));
exec_state.global.module_infos[&module_id].restore_repr(repr);
}

View File

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
use crate::{
errors::{KclError, KclErrorDetails},
exec::KclValue,
execution::{EnvironmentRef, PreImportedGeometry},
fs::{FileManager, FileSystem},
parsing::ast::types::{ImportPath, Node, Program},
@ -94,7 +95,7 @@ pub(crate) fn read_std(mod_name: &str) -> Option<&'static str> {
}
/// Info about a module.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct ModuleInfo {
/// The ID of the module.
pub(crate) id: ModuleId,
@ -117,11 +118,11 @@ impl ModuleInfo {
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum ModuleRepr {
Root,
// AST, memory, exported names
Kcl(Node<Program>, Option<(EnvironmentRef, Vec<String>)>),
Kcl(Node<Program>, Option<(Option<KclValue>, EnvironmentRef, Vec<String>)>),
Foreign(PreImportedGeometry),
Dummy,
}