Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/ast/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ impl Scope {
}
}

/// Creates a deep clone of the scope, copying the bindings vector
/// so that runtime mutations (e.g. from `eval`) do not leak back
/// into the shared compile-time scope.
#[must_use]
pub fn deep_clone(&self) -> Self {
Self {
inner: Rc::new(Inner {
unique_id: self.inner.unique_id,
outer: self.inner.outer.clone(),
index: self.inner.index.clone(),
bindings: RefCell::new(self.inner.bindings.borrow().clone()),
function: self.inner.function,
this_escaped: self.inner.this_escaped.clone(),
context: self.inner.context.clone(),
}),
}
}

/// Checks if the scope has only local bindings.
#[must_use]
pub fn all_bindings_local(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl FunctionEnvironment {
Self {
bindings: GcRefCell::new(vec![None; bindings_count as usize]),
slots: Box::new(slots),
scope,
scope: scope.deep_clone(),
}
}

Expand Down
1 change: 1 addition & 0 deletions core/macros/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn module_impl_impl(_args: ModuleArguments, mut mod_: ItemMod) -> SpannedResult<

for item in mod_.content.map_or_else(Vec::new, |c| c.1).as_mut_slice() {
// Check for skip attributes.
#[allow(clippy::collapsible_match)]
match item {
Item::Const(ItemConst { attrs, .. })
| Item::Enum(ItemEnum { attrs, .. })
Expand Down
Loading