diff options
Diffstat (limited to 'dhall/src/semantics/resolve/env.rs')
-rw-r--r-- | dhall/src/semantics/resolve/env.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs index 29dd16b..82f21e8 100644 --- a/dhall/src/semantics/resolve/env.rs +++ b/dhall/src/semantics/resolve/env.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::error::{Error, ImportError}; use crate::semantics::{AlphaVar, Cache, ImportLocation, VarEnv}; use crate::syntax::{Hash, Label, V}; -use crate::Typed; +use crate::{Ctxt, ImportResultId, Typed}; /// Environment for resolving names. #[derive(Debug, Clone, Default)] @@ -11,14 +11,13 @@ pub struct NameEnv { names: Vec<Label>, } -pub type MemCache = HashMap<ImportLocation, Typed>; pub type CyclesStack = Vec<ImportLocation>; /// Environment for resolving imports -#[derive(Debug)] -pub struct ImportEnv { - disk_cache: Option<Cache>, // Missing if it failed to initialize - mem_cache: MemCache, +pub struct ImportEnv<'cx> { + cx: Ctxt<'cx>, + disk_cache: Option<Cache>, // `None` if it failed to initialize + mem_cache: HashMap<ImportLocation, ImportResultId>, stack: CyclesStack, } @@ -66,26 +65,28 @@ impl NameEnv { } } -impl ImportEnv { - pub fn new() -> Self { +impl<'cx> ImportEnv<'cx> { + pub fn new(cx: Ctxt<'cx>) -> Self { ImportEnv { + cx, disk_cache: Cache::new().ok(), mem_cache: Default::default(), stack: Default::default(), } } + pub fn cx(&self) -> Ctxt<'cx> { + self.cx + } + pub fn get_from_mem_cache( - &mut self, + &self, location: &ImportLocation, - ) -> Option<Typed> { - Some(self.mem_cache.get(location)?.clone()) + ) -> Option<ImportResultId> { + Some(*self.mem_cache.get(location)?) } - pub fn get_from_disk_cache( - &mut self, - hash: &Option<Hash>, - ) -> Option<Typed> { + pub fn get_from_disk_cache(&self, hash: &Option<Hash>) -> Option<Typed> { let hash = hash.as_ref()?; let expr = self.disk_cache.as_ref()?.get(hash).ok()?; Some(expr) @@ -94,12 +95,12 @@ impl ImportEnv { pub fn write_to_mem_cache( &mut self, location: ImportLocation, - expr: Typed, + result: ImportResultId, ) { - self.mem_cache.insert(location, expr); + self.mem_cache.insert(location, result); } - pub fn write_to_disk_cache(&mut self, hash: &Option<Hash>, expr: &Typed) { + pub fn write_to_disk_cache(&self, hash: &Option<Hash>, expr: &Typed) { if let Some(disk_cache) = self.disk_cache.as_ref() { if let Some(hash) = hash { let _ = disk_cache.insert(hash, &expr); |