Make env var eval order during "use" deterministic (#742)

* Make env var eval order during "use" deterministic

Fixes #726.

* Merge delta after getting config

To make sure env vars are all in the engine state and not in the stack.
This commit is contained in:
Jakub Žádník
2022-01-14 23:06:32 +02:00
committed by GitHub
parent 7c23ae5cb0
commit 40484966c3
5 changed files with 63 additions and 36 deletions

View File

@ -586,7 +586,27 @@ pub struct StateDelta {
plugins_changed: bool, // marks whether plugin file should be updated
}
impl Default for StateDelta {
fn default() -> Self {
Self::new()
}
}
impl StateDelta {
pub fn new() -> Self {
StateDelta {
files: vec![],
file_contents: vec![],
vars: vec![],
decls: vec![],
blocks: vec![],
overlays: vec![],
scope: vec![ScopeFrame::new()],
#[cfg(feature = "plugin")]
plugins_changed: false,
}
}
pub fn num_files(&self) -> usize {
self.files.len()
}
@ -615,17 +635,7 @@ impl StateDelta {
impl<'a> StateWorkingSet<'a> {
pub fn new(permanent_state: &'a EngineState) -> Self {
Self {
delta: StateDelta {
files: vec![],
file_contents: vec![],
vars: vec![],
decls: vec![],
blocks: vec![],
overlays: vec![],
scope: vec![ScopeFrame::new()],
#[cfg(feature = "plugin")]
plugins_changed: false,
},
delta: StateDelta::new(),
permanent_state,
}
}

View File

@ -1,6 +1,6 @@
use crate::{BlockId, DeclId};
use std::collections::HashMap;
use indexmap::IndexMap;
// TODO: Move the import pattern matching logic here from use/hide commands and
// parse_use/parse_hide
@ -8,15 +8,15 @@ use std::collections::HashMap;
/// Collection of definitions that can be exported from a module
#[derive(Debug, Clone)]
pub struct Overlay {
pub decls: HashMap<Vec<u8>, DeclId>,
pub env_vars: HashMap<Vec<u8>, BlockId>,
pub decls: IndexMap<Vec<u8>, DeclId>,
pub env_vars: IndexMap<Vec<u8>, BlockId>,
}
impl Overlay {
pub fn new() -> Self {
Overlay {
decls: HashMap::new(),
env_vars: HashMap::new(),
decls: IndexMap::new(),
env_vars: IndexMap::new(),
}
}