Move turns to a submodule of std (#6039)
* Move turns to a submodule of std Signed-off-by: Nick Cameron <nrc@ncameron.org> * Cache module infos as well as memory; fix a bug with deprecated constants Signed-off-by: Nick Cameron <nrc@ncameron.org> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -6,7 +6,7 @@ use itertools::{EitherOrBoth, Itertools};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{
|
||||
execution::{annotations, memory::Stack, EnvironmentRef, ExecState, ExecutorSettings},
|
||||
execution::{annotations, memory::Stack, state::ModuleInfoMap, EnvironmentRef, ExecState, ExecutorSettings},
|
||||
parsing::ast::types::{Annotation, Node, Program},
|
||||
walk::Node as WalkNode,
|
||||
};
|
||||
@ -15,7 +15,7 @@ lazy_static::lazy_static! {
|
||||
/// A static mutable lock for updating the last successful execution state for the cache.
|
||||
static ref OLD_AST: Arc<RwLock<Option<OldAstState>>> = Default::default();
|
||||
// The last successful run's memory. Not cleared after an unssuccessful run.
|
||||
static ref PREV_MEMORY: Arc<RwLock<Option<Stack>>> = Default::default();
|
||||
static ref PREV_MEMORY: Arc<RwLock<Option<(Stack, ModuleInfoMap)>>> = Default::default();
|
||||
}
|
||||
|
||||
/// Read the old ast memory from the lock.
|
||||
@ -29,12 +29,12 @@ pub(super) async fn write_old_ast(old_state: OldAstState) {
|
||||
*old_ast = Some(old_state);
|
||||
}
|
||||
|
||||
pub(crate) async fn read_old_memory() -> Option<Stack> {
|
||||
pub(crate) async fn read_old_memory() -> Option<(Stack, ModuleInfoMap)> {
|
||||
let old_mem = PREV_MEMORY.read().await;
|
||||
old_mem.clone()
|
||||
}
|
||||
|
||||
pub(super) async fn write_old_memory(mem: Stack) {
|
||||
pub(super) async fn write_old_memory(mem: (Stack, ModuleInfoMap)) {
|
||||
let mut old_mem = PREV_MEMORY.write().await;
|
||||
*old_mem = Some(mem);
|
||||
}
|
||||
|
@ -559,7 +559,10 @@ impl ExecutorContext {
|
||||
let mut exec_state = ExecState::new(self);
|
||||
if use_prev_memory {
|
||||
match cache::read_old_memory().await {
|
||||
Some(mem) => *exec_state.mut_stack() = mem,
|
||||
Some(mem) => {
|
||||
*exec_state.mut_stack() = mem.0;
|
||||
exec_state.global.module_infos = mem.1;
|
||||
}
|
||||
None => self.prepare_mem(&mut exec_state).await?,
|
||||
}
|
||||
} else {
|
||||
@ -577,10 +580,11 @@ impl ExecutorContext {
|
||||
// memory, not to the exec_state which is not cached for mock execution.
|
||||
|
||||
let mut mem = exec_state.stack().clone();
|
||||
let module_infos = exec_state.global.module_infos.clone();
|
||||
let outcome = exec_state.to_mock_wasm_outcome(result.0).await;
|
||||
|
||||
mem.squash_env(result.0);
|
||||
cache::write_old_memory(mem).await;
|
||||
cache::write_old_memory((mem, module_infos)).await;
|
||||
|
||||
Ok(outcome)
|
||||
}
|
||||
@ -770,7 +774,7 @@ impl ExecutorContext {
|
||||
if !self.is_mock() {
|
||||
let mut mem = exec_state.stack().deep_clone();
|
||||
mem.restore_env(env_ref);
|
||||
cache::write_old_memory(mem).await;
|
||||
cache::write_old_memory((mem, exec_state.global.module_infos.clone())).await;
|
||||
}
|
||||
let session_data = self.engine.get_session_data().await;
|
||||
Ok((env_ref, session_data))
|
||||
|
@ -30,6 +30,8 @@ pub struct ExecState {
|
||||
pub(super) exec_context: Option<super::ExecutorContext>,
|
||||
}
|
||||
|
||||
pub type ModuleInfoMap = IndexMap<ModuleId, ModuleInfo>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(super) struct GlobalState {
|
||||
/// Map from source file absolute path to module ID.
|
||||
@ -37,7 +39,7 @@ pub(super) struct GlobalState {
|
||||
/// Map from module ID to source file.
|
||||
pub id_to_source: IndexMap<ModuleId, ModuleSource>,
|
||||
/// Map from module ID to module info.
|
||||
pub module_infos: IndexMap<ModuleId, ModuleInfo>,
|
||||
pub module_infos: ModuleInfoMap,
|
||||
/// Output map of UUIDs to artifacts.
|
||||
pub artifacts: IndexMap<ArtifactId, Artifact>,
|
||||
/// Output commands to allow building the artifact graph by the caller.
|
||||
|
Reference in New Issue
Block a user