get rid of execution kind
Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -18,7 +18,7 @@ use tokio::sync::{mpsc, oneshot, RwLock};
|
|||||||
use tokio_tungstenite::tungstenite::Message as WsMsg;
|
use tokio_tungstenite::tungstenite::Message as WsMsg;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::{EngineStats, ExecutionKind};
|
use super::EngineStats;
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::EngineManager,
|
engine::EngineManager,
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
@ -51,7 +51,6 @@ pub struct EngineConnection {
|
|||||||
/// If the server sends session data, it'll be copied to here.
|
/// If the server sends session data, it'll be copied to here.
|
||||||
session_data: Arc<RwLock<Option<ModelingSessionData>>>,
|
session_data: Arc<RwLock<Option<ModelingSessionData>>>,
|
||||||
|
|
||||||
execution_kind: Arc<RwLock<ExecutionKind>>,
|
|
||||||
stats: EngineStats,
|
stats: EngineStats,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +343,6 @@ impl EngineConnection {
|
|||||||
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
||||||
default_planes: Default::default(),
|
default_planes: Default::default(),
|
||||||
session_data,
|
session_data,
|
||||||
execution_kind: Default::default(),
|
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -368,18 +366,6 @@ impl EngineManager for EngineConnection {
|
|||||||
self.artifact_commands.clone()
|
self.artifact_commands.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execution_kind(&self) -> ExecutionKind {
|
|
||||||
let guard = self.execution_kind.read().await;
|
|
||||||
*guard
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn replace_execution_kind(&self, execution_kind: ExecutionKind) -> ExecutionKind {
|
|
||||||
let mut guard = self.execution_kind.write().await;
|
|
||||||
let original = *guard;
|
|
||||||
*guard = execution_kind;
|
|
||||||
original
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stats(&self) -> &EngineStats {
|
fn stats(&self) -> &EngineStats {
|
||||||
&self.stats
|
&self.stats
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use kittycad_modeling_cmds::{self as kcmc};
|
|||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::{EngineStats, ExecutionKind};
|
use super::EngineStats;
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::KclError,
|
errors::KclError,
|
||||||
exec::DefaultPlanes,
|
exec::DefaultPlanes,
|
||||||
@ -29,7 +29,6 @@ pub struct EngineConnection {
|
|||||||
batch: Arc<RwLock<Vec<(WebSocketRequest, SourceRange)>>>,
|
batch: Arc<RwLock<Vec<(WebSocketRequest, SourceRange)>>>,
|
||||||
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, SourceRange)>>>,
|
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, SourceRange)>>>,
|
||||||
artifact_commands: Arc<RwLock<Vec<ArtifactCommand>>>,
|
artifact_commands: Arc<RwLock<Vec<ArtifactCommand>>>,
|
||||||
execution_kind: Arc<RwLock<ExecutionKind>>,
|
|
||||||
/// The default planes for the scene.
|
/// The default planes for the scene.
|
||||||
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
||||||
stats: EngineStats,
|
stats: EngineStats,
|
||||||
@ -41,7 +40,6 @@ impl EngineConnection {
|
|||||||
batch: Arc::new(RwLock::new(Vec::new())),
|
batch: Arc::new(RwLock::new(Vec::new())),
|
||||||
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
||||||
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
||||||
execution_kind: Default::default(),
|
|
||||||
default_planes: Default::default(),
|
default_planes: Default::default(),
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
})
|
})
|
||||||
@ -70,18 +68,6 @@ impl crate::engine::EngineManager for EngineConnection {
|
|||||||
self.artifact_commands.clone()
|
self.artifact_commands.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execution_kind(&self) -> ExecutionKind {
|
|
||||||
let guard = self.execution_kind.read().await;
|
|
||||||
*guard
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn replace_execution_kind(&self, execution_kind: ExecutionKind) -> ExecutionKind {
|
|
||||||
let mut guard = self.execution_kind.write().await;
|
|
||||||
let original = *guard;
|
|
||||||
*guard = execution_kind;
|
|
||||||
original
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
||||||
self.default_planes.clone()
|
self.default_planes.clone()
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use uuid::Uuid;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::{EngineStats, ExecutionKind},
|
engine::EngineStats,
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{ArtifactCommand, DefaultPlanes, IdGenerator},
|
execution::{ArtifactCommand, DefaultPlanes, IdGenerator},
|
||||||
SourceRange,
|
SourceRange,
|
||||||
@ -42,7 +42,6 @@ pub struct EngineConnection {
|
|||||||
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, SourceRange)>>>,
|
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, SourceRange)>>>,
|
||||||
responses: Arc<RwLock<IndexMap<Uuid, WebSocketResponse>>>,
|
responses: Arc<RwLock<IndexMap<Uuid, WebSocketResponse>>>,
|
||||||
artifact_commands: Arc<RwLock<Vec<ArtifactCommand>>>,
|
artifact_commands: Arc<RwLock<Vec<ArtifactCommand>>>,
|
||||||
execution_kind: Arc<RwLock<ExecutionKind>>,
|
|
||||||
/// The default planes for the scene.
|
/// The default planes for the scene.
|
||||||
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
||||||
stats: EngineStats,
|
stats: EngineStats,
|
||||||
@ -61,7 +60,6 @@ impl EngineConnection {
|
|||||||
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
||||||
responses: Arc::new(RwLock::new(IndexMap::new())),
|
responses: Arc::new(RwLock::new(IndexMap::new())),
|
||||||
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
artifact_commands: Arc::new(RwLock::new(Vec::new())),
|
||||||
execution_kind: Default::default(),
|
|
||||||
default_planes: Default::default(),
|
default_planes: Default::default(),
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
})
|
})
|
||||||
@ -164,18 +162,6 @@ impl crate::engine::EngineManager for EngineConnection {
|
|||||||
self.artifact_commands.clone()
|
self.artifact_commands.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execution_kind(&self) -> ExecutionKind {
|
|
||||||
let guard = self.execution_kind.read().await;
|
|
||||||
*guard
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn replace_execution_kind(&self, execution_kind: ExecutionKind) -> ExecutionKind {
|
|
||||||
let mut guard = self.execution_kind.write().await;
|
|
||||||
let original = *guard;
|
|
||||||
*guard = execution_kind;
|
|
||||||
original
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
||||||
self.default_planes.clone()
|
self.default_planes.clone()
|
||||||
}
|
}
|
||||||
@ -218,11 +204,6 @@ impl crate::engine::EngineManager for EngineConnection {
|
|||||||
.do_send_modeling_cmd(id, source_range, cmd, id_to_source_range)
|
.do_send_modeling_cmd(id, source_range, cmd, id_to_source_range)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// In isolated mode, we don't save the response.
|
|
||||||
if self.execution_kind().await.is_isolated() {
|
|
||||||
return Ok(ws_result);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut responses = self.responses.write().await;
|
let mut responses = self.responses.write().await;
|
||||||
responses.insert(id, ws_result.clone());
|
responses.insert(id, ws_result.clone());
|
||||||
drop(responses);
|
drop(responses);
|
||||||
|
@ -47,23 +47,6 @@ lazy_static::lazy_static! {
|
|||||||
pub static ref GRID_SCALE_TEXT_OBJECT_ID: uuid::Uuid = uuid::Uuid::parse_str("10782f33-f588-4668-8bcd-040502d26590").unwrap();
|
pub static ref GRID_SCALE_TEXT_OBJECT_ID: uuid::Uuid = uuid::Uuid::parse_str("10782f33-f588-4668-8bcd-040502d26590").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The mode of execution. When isolated, like during an import, attempting to
|
|
||||||
/// send a command results in an error.
|
|
||||||
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, ts_rs::TS, JsonSchema)]
|
|
||||||
#[ts(export)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub enum ExecutionKind {
|
|
||||||
#[default]
|
|
||||||
Normal,
|
|
||||||
Isolated,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExecutionKind {
|
|
||||||
pub fn is_isolated(&self) -> bool {
|
|
||||||
matches!(self, ExecutionKind::Isolated)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct EngineStats {
|
pub struct EngineStats {
|
||||||
pub commands_batched: AtomicUsize,
|
pub commands_batched: AtomicUsize,
|
||||||
@ -108,13 +91,6 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
std::mem::take(&mut *self.responses().write().await)
|
std::mem::take(&mut *self.responses().write().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current execution kind.
|
|
||||||
async fn execution_kind(&self) -> ExecutionKind;
|
|
||||||
|
|
||||||
/// Replace the current execution kind with a new value and return the
|
|
||||||
/// existing value.
|
|
||||||
async fn replace_execution_kind(&self, execution_kind: ExecutionKind) -> ExecutionKind;
|
|
||||||
|
|
||||||
/// Get the default planes.
|
/// Get the default planes.
|
||||||
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>>;
|
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>>;
|
||||||
|
|
||||||
@ -279,11 +255,6 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
cmd: &ModelingCmd,
|
cmd: &ModelingCmd,
|
||||||
) -> Result<(), crate::errors::KclError> {
|
) -> Result<(), crate::errors::KclError> {
|
||||||
// In isolated mode, we don't send the command to the engine.
|
|
||||||
if self.execution_kind().await.is_isolated() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let req = WebSocketRequest::ModelingCmdReq(ModelingCmdReq {
|
let req = WebSocketRequest::ModelingCmdReq(ModelingCmdReq {
|
||||||
cmd: cmd.clone(),
|
cmd: cmd.clone(),
|
||||||
cmd_id: id.into(),
|
cmd_id: id.into(),
|
||||||
@ -305,11 +276,6 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
cmds: &[ModelingCmdReq],
|
cmds: &[ModelingCmdReq],
|
||||||
) -> Result<(), crate::errors::KclError> {
|
) -> Result<(), crate::errors::KclError> {
|
||||||
// In isolated mode, we don't send the command to the engine.
|
|
||||||
if self.execution_kind().await.is_isolated() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add cmds to the batch.
|
// Add cmds to the batch.
|
||||||
let mut extended_cmds = Vec::with_capacity(cmds.len());
|
let mut extended_cmds = Vec::with_capacity(cmds.len());
|
||||||
for cmd in cmds {
|
for cmd in cmds {
|
||||||
@ -332,11 +298,6 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
cmd: &ModelingCmd,
|
cmd: &ModelingCmd,
|
||||||
) -> Result<(), crate::errors::KclError> {
|
) -> Result<(), crate::errors::KclError> {
|
||||||
// In isolated mode, we don't send the command to the engine.
|
|
||||||
if self.execution_kind().await.is_isolated() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let req = WebSocketRequest::ModelingCmdReq(ModelingCmdReq {
|
let req = WebSocketRequest::ModelingCmdReq(ModelingCmdReq {
|
||||||
cmd: cmd.clone(),
|
cmd: cmd.clone(),
|
||||||
cmd_id: id.into(),
|
cmd_id: id.into(),
|
||||||
|
@ -5,7 +5,6 @@ use indexmap::IndexMap;
|
|||||||
|
|
||||||
use super::{cad_op::Group, kcl_value::TypeDef, types::PrimitiveType};
|
use super::{cad_op::Group, kcl_value::TypeDef, types::PrimitiveType};
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::ExecutionKind,
|
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{
|
execution::{
|
||||||
annotations,
|
annotations,
|
||||||
@ -62,15 +61,13 @@ impl ExecutorContext {
|
|||||||
exec_state.mod_local.explicit_length_units = true;
|
exec_state.mod_local.explicit_length_units = true;
|
||||||
}
|
}
|
||||||
let new_units = exec_state.length_unit();
|
let new_units = exec_state.length_unit();
|
||||||
if !self.engine.execution_kind().await.is_isolated() {
|
self.engine
|
||||||
self.engine
|
.set_units(
|
||||||
.set_units(
|
new_units.into(),
|
||||||
new_units.into(),
|
annotation.as_source_range(),
|
||||||
annotation.as_source_range(),
|
exec_state.id_generator(),
|
||||||
exec_state.id_generator(),
|
)
|
||||||
)
|
.await?;
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
exec_state.err(CompilationError::err(
|
exec_state.err(CompilationError::err(
|
||||||
annotation.as_source_range(),
|
annotation.as_source_range(),
|
||||||
@ -100,15 +97,13 @@ impl ExecutorContext {
|
|||||||
&self,
|
&self,
|
||||||
program: &Node<Program>,
|
program: &Node<Program>,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
exec_kind: ExecutionKind,
|
|
||||||
preserve_mem: bool,
|
preserve_mem: bool,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
path: &ModulePath,
|
path: &ModulePath,
|
||||||
) -> Result<(Option<KclValue>, EnvironmentRef, Vec<String>), KclError> {
|
) -> Result<(Option<KclValue>, EnvironmentRef, Vec<String>), KclError> {
|
||||||
crate::log::log(format!("enter module {path} {} {exec_kind:?}", exec_state.stack()));
|
crate::log::log(format!("enter module {path} {}", exec_state.stack()));
|
||||||
|
|
||||||
let old_units = exec_state.length_unit();
|
let old_units = exec_state.length_unit();
|
||||||
let original_execution = self.engine.replace_execution_kind(exec_kind).await;
|
|
||||||
|
|
||||||
let mut local_state = ModuleState::new(path.std_path(), exec_state.stack().memory.clone(), Some(module_id));
|
let mut local_state = ModuleState::new(path.std_path(), exec_state.stack().memory.clone(), Some(module_id));
|
||||||
if !preserve_mem {
|
if !preserve_mem {
|
||||||
@ -141,12 +136,11 @@ impl ExecutorContext {
|
|||||||
// If we reset at the end of the main path, then we just add on an extra
|
// If we reset at the end of the main path, then we just add on an extra
|
||||||
// command and we'd need to flush the batch again.
|
// command and we'd need to flush the batch again.
|
||||||
// This avoids that.
|
// This avoids that.
|
||||||
if !exec_kind.is_isolated() && new_units != old_units && *path != ModulePath::Main {
|
if new_units != old_units && *path != ModulePath::Main {
|
||||||
self.engine
|
self.engine
|
||||||
.set_units(old_units.into(), Default::default(), exec_state.id_generator())
|
.set_units(old_units.into(), Default::default(), exec_state.id_generator())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
self.engine.replace_execution_kind(original_execution).await;
|
|
||||||
|
|
||||||
crate::log::log(format!("leave {path}"));
|
crate::log::log(format!("leave {path}"));
|
||||||
|
|
||||||
@ -233,9 +227,8 @@ impl ExecutorContext {
|
|||||||
|
|
||||||
match &import_stmt.selector {
|
match &import_stmt.selector {
|
||||||
ImportSelector::List { items } => {
|
ImportSelector::List { items } => {
|
||||||
let (env_ref, module_exports) = self
|
let (env_ref, module_exports) =
|
||||||
.exec_module_for_items(module_id, exec_state, ExecutionKind::Isolated, source_range)
|
self.exec_module_for_items(module_id, exec_state, source_range).await?;
|
||||||
.await?;
|
|
||||||
for import_item in items {
|
for import_item in items {
|
||||||
// Extract the item from the module.
|
// Extract the item from the module.
|
||||||
let item = exec_state
|
let item = exec_state
|
||||||
@ -276,9 +269,8 @@ impl ExecutorContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImportSelector::Glob(_) => {
|
ImportSelector::Glob(_) => {
|
||||||
let (env_ref, module_exports) = self
|
let (env_ref, module_exports) =
|
||||||
.exec_module_for_items(module_id, exec_state, ExecutionKind::Isolated, source_range)
|
self.exec_module_for_items(module_id, exec_state, source_range).await?;
|
||||||
.await?;
|
|
||||||
for name in module_exports.iter() {
|
for name in module_exports.iter() {
|
||||||
let item = exec_state
|
let item = exec_state
|
||||||
.stack()
|
.stack()
|
||||||
@ -533,7 +525,6 @@ impl ExecutorContext {
|
|||||||
&self,
|
&self,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
exec_kind: ExecutionKind,
|
|
||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
) -> Result<(EnvironmentRef, Vec<String>), KclError> {
|
) -> Result<(EnvironmentRef, Vec<String>), KclError> {
|
||||||
let path = exec_state.global.module_infos[&module_id].path.clone();
|
let path = exec_state.global.module_infos[&module_id].path.clone();
|
||||||
@ -544,7 +535,7 @@ impl ExecutorContext {
|
|||||||
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
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
|
ModuleRepr::Kcl(program, cache) => self
|
||||||
.exec_module_from_ast(program, module_id, &path, exec_state, exec_kind, source_range)
|
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
||||||
.await
|
.await
|
||||||
.map(|(_, er, items)| {
|
.map(|(_, er, items)| {
|
||||||
*cache = Some((er, items.clone()));
|
*cache = Some((er, items.clone()));
|
||||||
@ -566,7 +557,6 @@ impl ExecutorContext {
|
|||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
module_name: &BoxNode<Name>,
|
module_name: &BoxNode<Name>,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
exec_kind: ExecutionKind,
|
|
||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
) -> Result<Option<KclValue>, KclError> {
|
) -> Result<Option<KclValue>, KclError> {
|
||||||
exec_state.global.operations.push(Operation::GroupBegin {
|
exec_state.global.operations.push(Operation::GroupBegin {
|
||||||
@ -585,7 +575,7 @@ impl ExecutorContext {
|
|||||||
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
||||||
ModuleRepr::Kcl(program, cached_items) => {
|
ModuleRepr::Kcl(program, cached_items) => {
|
||||||
let result = self
|
let result = self
|
||||||
.exec_module_from_ast(program, module_id, &path, exec_state, exec_kind, source_range)
|
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
||||||
.await;
|
.await;
|
||||||
match result {
|
match result {
|
||||||
Ok((val, env, items)) => {
|
Ok((val, env, items)) => {
|
||||||
@ -614,13 +604,10 @@ impl ExecutorContext {
|
|||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
path: &ModulePath,
|
path: &ModulePath,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
exec_kind: ExecutionKind,
|
|
||||||
source_range: SourceRange,
|
source_range: SourceRange,
|
||||||
) -> Result<(Option<KclValue>, EnvironmentRef, Vec<String>), KclError> {
|
) -> Result<(Option<KclValue>, EnvironmentRef, Vec<String>), KclError> {
|
||||||
exec_state.global.mod_loader.enter_module(path);
|
exec_state.global.mod_loader.enter_module(path);
|
||||||
let result = self
|
let result = self.exec_module_body(program, exec_state, false, module_id, path).await;
|
||||||
.exec_module_body(program, exec_state, exec_kind, false, module_id, path)
|
|
||||||
.await;
|
|
||||||
exec_state.global.mod_loader.leave_module(path);
|
exec_state.global.mod_loader.leave_module(path);
|
||||||
|
|
||||||
result.map_err(|err| {
|
result.map_err(|err| {
|
||||||
@ -656,7 +643,7 @@ impl ExecutorContext {
|
|||||||
Expr::Name(name) => {
|
Expr::Name(name) => {
|
||||||
let value = name.get_result(exec_state, self).await?.clone();
|
let value = name.get_result(exec_state, self).await?.clone();
|
||||||
if let KclValue::Module { value: module_id, meta } = value {
|
if let KclValue::Module { value: module_id, meta } = value {
|
||||||
self.exec_module_for_result(module_id, name, exec_state, ExecutionKind::Normal, metadata.source_range)
|
self.exec_module_for_result(module_id, name, exec_state, metadata.source_range)
|
||||||
.await?
|
.await?
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
exec_state.warn(CompilationError::err(
|
exec_state.warn(CompilationError::err(
|
||||||
@ -844,7 +831,7 @@ impl Node<Name> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
mem_spec = Some(
|
mem_spec = Some(
|
||||||
ctx.exec_module_for_items(*module_id, exec_state, ExecutionKind::Normal, p.as_source_range())
|
ctx.exec_module_for_items(*module_id, exec_state, p.as_source_range())
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1325,7 +1312,7 @@ impl Node<CallExpressionKw> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = if func.feature_tree_operation() && !ctx.is_isolated_execution().await {
|
let op = if func.feature_tree_operation() {
|
||||||
let op_labeled_args = args
|
let op_labeled_args = args
|
||||||
.kw_args
|
.kw_args
|
||||||
.labeled
|
.labeled
|
||||||
@ -1411,7 +1398,7 @@ impl Node<CallExpressionKw> {
|
|||||||
e.add_source_ranges(vec![callsite])
|
e.add_source_ranges(vec![callsite])
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if matches!(fn_src, FunctionSource::User { .. }) && !ctx.is_isolated_execution().await {
|
if matches!(fn_src, FunctionSource::User { .. }) {
|
||||||
// Track return operation.
|
// Track return operation.
|
||||||
exec_state.global.operations.push(Operation::GroupEnd);
|
exec_state.global.operations.push(Operation::GroupEnd);
|
||||||
}
|
}
|
||||||
@ -1463,7 +1450,7 @@ impl Node<CallExpression> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = if func.feature_tree_operation() && !ctx.is_isolated_execution().await {
|
let op = if func.feature_tree_operation() {
|
||||||
let op_labeled_args = func
|
let op_labeled_args = func
|
||||||
.args(false)
|
.args(false)
|
||||||
.iter()
|
.iter()
|
||||||
@ -1521,19 +1508,17 @@ impl Node<CallExpression> {
|
|||||||
// exec_state.
|
// exec_state.
|
||||||
let func = fn_name.get_result(exec_state, ctx).await?.clone();
|
let func = fn_name.get_result(exec_state, ctx).await?.clone();
|
||||||
|
|
||||||
if !ctx.is_isolated_execution().await {
|
// Track call operation.
|
||||||
// Track call operation.
|
exec_state.global.operations.push(Operation::GroupBegin {
|
||||||
exec_state.global.operations.push(Operation::GroupBegin {
|
group: Group::FunctionCall {
|
||||||
group: Group::FunctionCall {
|
name: Some(fn_name.to_string()),
|
||||||
name: Some(fn_name.to_string()),
|
function_source_range: func.function_def_source_range().unwrap_or_default(),
|
||||||
function_source_range: func.function_def_source_range().unwrap_or_default(),
|
unlabeled_arg: None,
|
||||||
unlabeled_arg: None,
|
// TODO: Add the arguments for legacy positional parameters.
|
||||||
// TODO: Add the arguments for legacy positional parameters.
|
labeled_args: Default::default(),
|
||||||
labeled_args: Default::default(),
|
},
|
||||||
},
|
source_range: callsite,
|
||||||
source_range: callsite,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(fn_src) = func.as_fn() else {
|
let Some(fn_src) = func.as_fn() else {
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
return Err(KclError::Semantic(KclErrorDetails {
|
||||||
@ -1562,10 +1547,8 @@ impl Node<CallExpression> {
|
|||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !ctx.is_isolated_execution().await {
|
// Track return operation.
|
||||||
// Track return operation.
|
exec_state.global.operations.push(Operation::GroupEnd);
|
||||||
exec_state.global.operations.push(Operation::GroupEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
@ -2293,7 +2276,7 @@ impl FunctionSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = if props.include_in_feature_tree && !ctx.is_isolated_execution().await {
|
let op = if props.include_in_feature_tree {
|
||||||
let op_labeled_args = args
|
let op_labeled_args = args
|
||||||
.kw_args
|
.kw_args
|
||||||
.labeled
|
.labeled
|
||||||
@ -2337,28 +2320,26 @@ impl FunctionSource {
|
|||||||
Ok(Some(result))
|
Ok(Some(result))
|
||||||
}
|
}
|
||||||
FunctionSource::User { ast, memory, .. } => {
|
FunctionSource::User { ast, memory, .. } => {
|
||||||
if !ctx.is_isolated_execution().await {
|
// Track call operation.
|
||||||
// Track call operation.
|
let op_labeled_args = args
|
||||||
let op_labeled_args = args
|
.kw_args
|
||||||
.kw_args
|
.labeled
|
||||||
.labeled
|
.iter()
|
||||||
.iter()
|
.map(|(k, arg)| (k.clone(), OpArg::new(OpKclValue::from(&arg.value), arg.source_range)))
|
||||||
.map(|(k, arg)| (k.clone(), OpArg::new(OpKclValue::from(&arg.value), arg.source_range)))
|
.collect();
|
||||||
.collect();
|
exec_state.global.operations.push(Operation::GroupBegin {
|
||||||
exec_state.global.operations.push(Operation::GroupBegin {
|
group: Group::FunctionCall {
|
||||||
group: Group::FunctionCall {
|
name: fn_name,
|
||||||
name: fn_name,
|
function_source_range: ast.as_source_range(),
|
||||||
function_source_range: ast.as_source_range(),
|
unlabeled_arg: args
|
||||||
unlabeled_arg: args
|
.kw_args
|
||||||
.kw_args
|
.unlabeled
|
||||||
.unlabeled
|
.as_ref()
|
||||||
.as_ref()
|
.map(|arg| OpArg::new(OpKclValue::from(&arg.value), arg.source_range)),
|
||||||
.map(|arg| OpArg::new(OpKclValue::from(&arg.value), arg.source_range)),
|
labeled_args: op_labeled_args,
|
||||||
labeled_args: op_labeled_args,
|
},
|
||||||
},
|
source_range: callsite,
|
||||||
source_range: callsite,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
call_user_defined_function_kw(args.kw_args, *memory, ast, exec_state, ctx).await
|
call_user_defined_function_kw(args.kw_args, *memory, ast, exec_state, ctx).await
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ use crate::{
|
|||||||
parsing::ast::types::{Expr, ImportPath, NodeRef},
|
parsing::ast::types::{Expr, ImportPath, NodeRef},
|
||||||
source_range::SourceRange,
|
source_range::SourceRange,
|
||||||
std::StdLib,
|
std::StdLib,
|
||||||
CompilationError, ExecError, ExecutionKind, KclErrorWithOutputs,
|
CompilationError, ExecError, KclErrorWithOutputs,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) mod annotations;
|
pub(crate) mod annotations;
|
||||||
@ -498,13 +498,9 @@ impl ExecutorContext {
|
|||||||
self.context_type == ContextType::Mock || self.context_type == ContextType::MockCustomForwarded
|
self.context_type == ContextType::Mock || self.context_type == ContextType::MockCustomForwarded
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_isolated_execution(&self) -> bool {
|
|
||||||
self.engine.execution_kind().await.is_isolated()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if we should not send engine commands for any reason.
|
/// Returns true if we should not send engine commands for any reason.
|
||||||
pub async fn no_engine_commands(&self) -> bool {
|
pub async fn no_engine_commands(&self) -> bool {
|
||||||
self.is_mock() || self.is_isolated_execution().await
|
self.is_mock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_clear_scene(
|
pub async fn send_clear_scene(
|
||||||
@ -708,7 +704,7 @@ impl ExecutorContext {
|
|||||||
program: &crate::Program,
|
program: &crate::Program,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclErrorWithOutputs> {
|
) -> Result<(EnvironmentRef, Option<ModelingSessionData>), KclErrorWithOutputs> {
|
||||||
self.inner_run(program, exec_state, false).await
|
self.run_concurrent(program, exec_state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform the execution of a program using an (experimental!) concurrent
|
/// Perform the execution of a program using an (experimental!) concurrent
|
||||||
@ -750,12 +746,13 @@ impl ExecutorContext {
|
|||||||
let program = program;
|
let program = program;
|
||||||
|
|
||||||
exec_ctxt
|
exec_ctxt
|
||||||
.run(
|
.inner_run(
|
||||||
&crate::Program {
|
&crate::Program {
|
||||||
ast: program.clone(),
|
ast: program.clone(),
|
||||||
original_file_contents: "".to_owned(),
|
original_file_contents: "".to_owned(),
|
||||||
},
|
},
|
||||||
&mut exec_state,
|
&mut exec_state,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
});
|
});
|
||||||
@ -764,7 +761,7 @@ impl ExecutorContext {
|
|||||||
set.join_all().await;
|
set.join_all().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.run(&program, exec_state).await
|
self.inner_run(&program, exec_state, false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform the execution of a program. Accept all possible parameters and
|
/// Perform the execution of a program. Accept all possible parameters and
|
||||||
@ -842,7 +839,6 @@ impl ExecutorContext {
|
|||||||
.exec_module_body(
|
.exec_module_body(
|
||||||
program,
|
program,
|
||||||
exec_state,
|
exec_state,
|
||||||
ExecutionKind::Normal,
|
|
||||||
preserve_mem,
|
preserve_mem,
|
||||||
ModuleId::default(),
|
ModuleId::default(),
|
||||||
&ModulePath::Main,
|
&ModulePath::Main,
|
||||||
@ -896,9 +892,7 @@ impl ExecutorContext {
|
|||||||
source_range,
|
source_range,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let (module_memory, _) = self
|
let (module_memory, _) = self.exec_module_for_items(id, exec_state, source_range).await?;
|
||||||
.exec_module_for_items(id, exec_state, ExecutionKind::Isolated, source_range)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
exec_state.mut_stack().memory.set_std(module_memory);
|
exec_state.mut_stack().memory.set_std(module_memory);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ pub mod walk;
|
|||||||
mod wasm;
|
mod wasm;
|
||||||
|
|
||||||
pub use coredump::CoreDump;
|
pub use coredump::CoreDump;
|
||||||
pub use engine::{EngineManager, EngineStats, ExecutionKind};
|
pub use engine::{EngineManager, EngineStats};
|
||||||
pub use errors::{
|
pub use errors::{
|
||||||
CompilationError, ConnectionError, ExecError, KclError, KclErrorWithOutputs, Report, ReportWithOutputs,
|
CompilationError, ConnectionError, ExecError, KclError, KclErrorWithOutputs, Report, ReportWithOutputs,
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ use anyhow::Result;
|
|||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use kcl_lib::{
|
use kcl_lib::{
|
||||||
exec::{ArtifactCommand, DefaultPlanes, IdGenerator},
|
exec::{ArtifactCommand, DefaultPlanes, IdGenerator},
|
||||||
EngineStats, ExecutionKind, KclError,
|
EngineStats, KclError,
|
||||||
};
|
};
|
||||||
use kittycad_modeling_cmds::{
|
use kittycad_modeling_cmds::{
|
||||||
self as kcmc,
|
self as kcmc,
|
||||||
@ -23,7 +23,6 @@ pub struct EngineConnection {
|
|||||||
batch: Arc<RwLock<Vec<(WebSocketRequest, kcl_lib::SourceRange)>>>,
|
batch: Arc<RwLock<Vec<(WebSocketRequest, kcl_lib::SourceRange)>>>,
|
||||||
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, kcl_lib::SourceRange)>>>,
|
batch_end: Arc<RwLock<IndexMap<uuid::Uuid, (WebSocketRequest, kcl_lib::SourceRange)>>>,
|
||||||
core_test: Arc<RwLock<String>>,
|
core_test: Arc<RwLock<String>>,
|
||||||
execution_kind: Arc<RwLock<ExecutionKind>>,
|
|
||||||
/// The default planes for the scene.
|
/// The default planes for the scene.
|
||||||
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
|
||||||
stats: EngineStats,
|
stats: EngineStats,
|
||||||
@ -37,7 +36,6 @@ impl EngineConnection {
|
|||||||
batch: Arc::new(RwLock::new(Vec::new())),
|
batch: Arc::new(RwLock::new(Vec::new())),
|
||||||
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
batch_end: Arc::new(RwLock::new(IndexMap::new())),
|
||||||
core_test: result,
|
core_test: result,
|
||||||
execution_kind: Default::default(),
|
|
||||||
default_planes: Default::default(),
|
default_planes: Default::default(),
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
})
|
})
|
||||||
@ -379,18 +377,6 @@ impl kcl_lib::EngineManager for EngineConnection {
|
|||||||
Arc::new(RwLock::new(Vec::new()))
|
Arc::new(RwLock::new(Vec::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execution_kind(&self) -> ExecutionKind {
|
|
||||||
let guard = self.execution_kind.read().await;
|
|
||||||
*guard
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn replace_execution_kind(&self, execution_kind: ExecutionKind) -> ExecutionKind {
|
|
||||||
let mut guard = self.execution_kind.write().await;
|
|
||||||
let original = *guard;
|
|
||||||
*guard = execution_kind;
|
|
||||||
original
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
fn get_default_planes(&self) -> Arc<RwLock<Option<DefaultPlanes>>> {
|
||||||
self.default_planes.clone()
|
self.default_planes.clone()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user