From 35e5286e573df9c9570df64241c3ed1d38476d3b Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Thu, 27 Aug 2026 13:55:31 -0400 Subject: [PATCH 1/2] Remove 'get_module' function and cleanup. --- slicec/src/grammar/traits.rs | 12 ++---------- slicec/src/grammar/util.rs | 15 ++++----------- slicec/src/parsers/slice/grammar.rs | 11 +++++------ 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/slicec/src/grammar/traits.rs b/slicec/src/grammar/traits.rs index 8468f16c..c113d4a9 100644 --- a/slicec/src/grammar/traits.rs +++ b/slicec/src/grammar/traits.rs @@ -2,7 +2,7 @@ use super::attributes::AttributeKind; use super::comments::DocComment; -use super::elements::{Attribute, Identifier, Integer, Module, TypeRef}; +use super::elements::{Attribute, Identifier, Integer, TypeRef}; use super::util::Scope; use super::wrappers::{AsEntities, AsTypes}; use crate::slice_file::Span; @@ -18,7 +18,6 @@ pub trait Symbol: Element { pub trait ScopedSymbol: Symbol { fn parser_scope(&self) -> &str; fn module_scope(&self) -> &str; - fn get_module(&self) -> &Module; fn get_raw_scope(&self) -> &Scope; } @@ -121,14 +120,7 @@ macro_rules! implement_Scoped_Symbol_for { } fn module_scope(&self) -> &str { - match &self.scope.module { - Some(module_ptr) => module_ptr.borrow().nested_module_identifier(), - None => "", - } - } - - fn get_module(&self) -> &Module { - self.scope.module.as_ref().unwrap().borrow() + &self.scope.module_scope } fn get_raw_scope(&self) -> &Scope { diff --git a/slicec/src/grammar/util.rs b/slicec/src/grammar/util.rs index 080d481b..0edb650d 100644 --- a/slicec/src/grammar/util.rs +++ b/slicec/src/grammar/util.rs @@ -1,12 +1,9 @@ // Copyright (c) ZeroC, Inc. -use super::Module; -use crate::utils::ptr_util::WeakPtr; - #[derive(Clone, Debug, Default)] pub struct Scope { pub parser_scope: String, - pub module: Option>, + pub module_scope: String, } impl Scope { @@ -21,16 +18,12 @@ impl Scope { if let Some(last_scope_index) = self.parser_scope.rfind("::") { // Remove any characters after the last '::' in the string. // We ensure that we're only removing additional parser scopes, and not any scopes that came from a module. - #[cfg(debug_assertions)] - { - let module_scope = self.module.as_ref().map(|m| m.borrow().nested_module_identifier()); - debug_assert!(self.parser_scope.len() > module_scope.map_or(0, str::len)) - } + debug_assert!(self.parser_scope.len() > self.module_scope.len()); self.parser_scope.truncate(last_scope_index); } else { // If the string doesn't contain '::', there's only a single scope. We pop it off by clearing the string. - // This is only possible if we're not in a module, otherwise we'd always have at least 1 module scope. - debug_assert!(self.module.is_none()); + // This means the user forgot to write a module, which is an error. But we have to handle this gracefully. + debug_assert!(self.module_scope.is_empty()); self.parser_scope.clear(); } } diff --git a/slicec/src/parsers/slice/grammar.rs b/slicec/src/parsers/slice/grammar.rs index 7f7a7ee5..cf1fd105 100644 --- a/slicec/src/parsers/slice/grammar.rs +++ b/slicec/src/parsers/slice/grammar.rs @@ -71,15 +71,14 @@ fn construct_module( .push_into(parser.diagnostics); } - let module_ptr = OwnedPtr::new(Module { + parser.current_scope.module_scope = identifier.value.clone(); + parser.current_scope.parser_scope = identifier.value.clone(); + + OwnedPtr::new(Module { identifier, attributes, span, - }); - - parser.current_scope.module = Some(module_ptr.downgrade()); - parser.current_scope.parser_scope = module_ptr.borrow().nested_module_identifier().to_owned(); - module_ptr + }) } fn construct_struct( From 4d599f69420ce44e3f8bb1b60ca0d987257345c7 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Thu, 27 Aug 2026 14:12:02 -0400 Subject: [PATCH 2/2] More cleanup. --- slicec/src/grammar/traits.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/slicec/src/grammar/traits.rs b/slicec/src/grammar/traits.rs index c113d4a9..f04d74b6 100644 --- a/slicec/src/grammar/traits.rs +++ b/slicec/src/grammar/traits.rs @@ -3,7 +3,6 @@ use super::attributes::AttributeKind; use super::comments::DocComment; use super::elements::{Attribute, Identifier, Integer, TypeRef}; -use super::util::Scope; use super::wrappers::{AsEntities, AsTypes}; use crate::slice_file::Span; @@ -18,7 +17,6 @@ pub trait Symbol: Element { pub trait ScopedSymbol: Symbol { fn parser_scope(&self) -> &str; fn module_scope(&self) -> &str; - fn get_raw_scope(&self) -> &Scope; } pub trait NamedSymbol: Symbol + Attributable { @@ -122,10 +120,6 @@ macro_rules! implement_Scoped_Symbol_for { fn module_scope(&self) -> &str { &self.scope.module_scope } - - fn get_raw_scope(&self) -> &Scope { - &self.scope - } } }; }