From 01d45ad755b93884e553edfec3e12bf7357df920 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Wed, 19 Jun 2024 13:37:55 -0700 Subject: [PATCH] Clarify a comment about safety in the environment impl We use an unusual pattern of protecting data via a global lock, but it's safe. --- src/env/environment_impl.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index 58e61bdb9..f08d11215 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -273,10 +273,7 @@ impl Iterator for EnvNodeIter { } lazy_static! { - /// XXX: Possible safety issue here as EnvNodeRef is not Send/Sync and shouldn't - /// be placed in a static context without some sort of Send/Sync wrapper. - /// lazy_static papers over this but it triggers rust lints if you use - /// once_cell::sync::Lazy or std::sync::OnceLock instead. + // All accesses to the EnvNode are protected by a global lock. static ref GLOBAL_NODE: EnvNodeRef = EnvNodeRef::new(false, None); } @@ -703,7 +700,6 @@ pub struct EnvStackImpl { impl EnvStackImpl { /// Return a new impl representing global variables, with a single local scope. pub fn new() -> EnvMutex { - // XXX: Safety issue: We are accessing GLOBAL_NODE without having the global mutex locked! let globals = GLOBAL_NODE.clone(); let locals = EnvNodeRef::new(false, None); let base = EnvScopedImpl::new(locals, globals);