diff options
Diffstat (limited to 'crates/nu-protocol/src/engine/engine_state.rs')
-rw-r--r-- | crates/nu-protocol/src/engine/engine_state.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 6d7aff120..28463f752 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -93,7 +93,7 @@ pub struct EngineState { pub config: Arc<Config>, pub pipeline_externals_state: Arc<(AtomicU32, AtomicU32)>, pub repl_state: Arc<Mutex<ReplState>>, - pub table_decl_id: Option<usize>, + pub table_decl_id: Option<DeclId>, #[cfg(feature = "plugin")] pub plugin_path: Option<PathBuf>, #[cfg(feature = "plugin")] @@ -114,9 +114,9 @@ pub struct EngineState { // The max number of compiled regexes to keep around in a LRU cache, arbitrarily chosen const REGEX_CACHE_SIZE: usize = 100; // must be nonzero, otherwise will panic -pub const NU_VARIABLE_ID: usize = 0; -pub const IN_VARIABLE_ID: usize = 1; -pub const ENV_VARIABLE_ID: usize = 2; +pub const NU_VARIABLE_ID: VarId = VarId::new(0); +pub const IN_VARIABLE_ID: VarId = VarId::new(1); +pub const ENV_VARIABLE_ID: VarId = VarId::new(2); // NOTE: If you add more to this list, make sure to update the > checks based on the last in the list // The first span is unknown span @@ -144,7 +144,7 @@ impl EngineState { // make sure we have some default overlay: scope: ScopeFrame::with_empty_overlay( DEFAULT_OVERLAY_NAME.as_bytes().to_vec(), - 0, + ModuleId::new(0), false, ), signal_handlers: None, @@ -380,7 +380,7 @@ impl EngineState { let other_names = other.active_overlays.iter().map(|other_id| { &other .overlays - .get(*other_id) + .get(other_id.get()) .expect("internal error: missing overlay") .0 }); @@ -410,7 +410,7 @@ impl EngineState { &self .scope .overlays - .get(overlay_id) + .get(overlay_id.get()) .expect("internal error: missing overlay") .0 } @@ -419,7 +419,7 @@ impl EngineState { &self .scope .overlays - .get(overlay_id) + .get(overlay_id.get()) .expect("internal error: missing overlay") .1 } @@ -763,7 +763,7 @@ impl EngineState { pub fn get_var(&self, var_id: VarId) -> &Variable { self.vars - .get(var_id) + .get(var_id.get()) .expect("internal error: missing variable") } @@ -773,12 +773,12 @@ impl EngineState { } pub fn generate_nu_constant(&mut self) { - self.vars[NU_VARIABLE_ID].const_val = Some(create_nu_constant(self, Span::unknown())); + self.vars[NU_VARIABLE_ID.get()].const_val = Some(create_nu_constant(self, Span::unknown())); } pub fn get_decl(&self, decl_id: DeclId) -> &dyn Command { self.decls - .get(decl_id) + .get(decl_id.get()) .expect("internal error: missing declaration") .as_ref() } @@ -810,7 +810,7 @@ impl EngineState { pub fn get_signature(&self, decl: &dyn Command) -> Signature { if let Some(block_id) = decl.block_id() { - *self.blocks[block_id].signature.clone() + *self.blocks[block_id.get()].signature.clone() } else { decl.signature() } @@ -830,7 +830,7 @@ impl EngineState { pub fn get_block(&self, block_id: BlockId) -> &Arc<Block> { self.blocks - .get(block_id) + .get(block_id.get()) .expect("internal error: missing block") } @@ -840,18 +840,18 @@ impl EngineState { /// are normally a compiler error. This only exists to stop plugins from crashing the engine if /// they send us something invalid. pub fn try_get_block(&self, block_id: BlockId) -> Option<&Arc<Block>> { - self.blocks.get(block_id) + self.blocks.get(block_id.get()) } pub fn get_module(&self, module_id: ModuleId) -> &Module { self.modules - .get(module_id) + .get(module_id.get()) .expect("internal error: missing module") } pub fn get_virtual_path(&self, virtual_path_id: VirtualPathId) -> &(String, VirtualPath) { self.virtual_paths - .get(virtual_path_id) + .get(virtual_path_id.get()) .expect("internal error: missing virtual path") } @@ -879,7 +879,7 @@ impl EngineState { covered_span, }); - self.num_files() - 1 + FileId::new(self.num_files() - 1) } pub fn set_config_path(&mut self, key: &str, val: PathBuf) { @@ -1065,7 +1065,7 @@ mod engine_state_tests { let mut engine_state = StateWorkingSet::new(&engine_state); let id = engine_state.add_file("test.nu".into(), &[]); - assert_eq!(id, 0); + assert_eq!(id, FileId::new(0)); } #[test] @@ -1076,8 +1076,8 @@ mod engine_state_tests { let mut working_set = StateWorkingSet::new(&engine_state); let working_set_id = working_set.add_file("child.nu".into(), &[]); - assert_eq!(parent_id, 0); - assert_eq!(working_set_id, 1); + assert_eq!(parent_id, FileId::new(0)); + assert_eq!(working_set_id, FileId::new(1)); } #[test] |