diff --git a/CHANGELOG.md b/CHANGELOG.md index 90287a730d..baf7f7547d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Improve error messages for some assembler instruction (#1785) - Remove `idx` column from Kernel ROM chiplet and use chiplet bus for initialization. (#1818) - [BREAKING] Make `Assembler::source_manager()` be `Send + Sync` (#1822) +- Add `SourceManagerSync` trait and generic implementation. (#1858) - Simplify and optimize the recursive verifier (#1801). - Simplify auxiliary randomness generation (#1810). - Add handling of variable length public inputs to the recursive verifier (#1813). diff --git a/assembly/src/assembler/mod.rs b/assembly/src/assembler/mod.rs index e48d733c8c..e5a830a480 100644 --- a/assembly/src/assembler/mod.rs +++ b/assembly/src/assembler/mod.rs @@ -11,7 +11,8 @@ use vm_core::{ }; use crate::{ - AssemblyError, Compile, CompileOptions, LibraryNamespace, LibraryPath, SourceManager, Spanned, + AssemblyError, Compile, CompileOptions, LibraryNamespace, LibraryPath, SourceManager, + SourceManagerSync, Spanned, ast::{self, Export, InvocationTarget, InvokeKind, ModuleKind, QualifiedProcedureName}, diagnostics::Report, library::{KernelLibrary, Library}, @@ -64,7 +65,7 @@ pub use self::{ #[derive(Clone)] pub struct Assembler { /// The source manager to use for compilation and source location information - source_manager: Arc, + source_manager: Arc, /// The global [ModuleGraph] for this assembler. module_graph: ModuleGraph, /// Whether to treat warning diagnostics as errors @@ -93,7 +94,7 @@ impl Default for Assembler { /// Constructors impl Assembler { /// Start building an [Assembler] - pub fn new(source_manager: Arc) -> Self { + pub fn new(source_manager: Arc) -> Self { let module_graph = ModuleGraph::new(source_manager.clone()); Self { source_manager, @@ -106,7 +107,7 @@ impl Assembler { /// Start building an [`Assembler`] with a kernel defined by the provided [KernelLibrary]. pub fn with_kernel( - source_manager: Arc, + source_manager: Arc, kernel_lib: KernelLibrary, ) -> Self { let (kernel, kernel_module, _) = kernel_lib.into_parts(); @@ -303,7 +304,7 @@ impl Assembler { } /// Returns a link to the source manager used by this assembler. - pub fn source_manager(&self) -> Arc { + pub fn source_manager(&self) -> Arc { self.source_manager.clone() } diff --git a/assembly/src/lib.rs b/assembly/src/lib.rs index 350199fee1..feba3f58f3 100644 --- a/assembly/src/lib.rs +++ b/assembly/src/lib.rs @@ -39,8 +39,8 @@ pub use self::{ assembler::Assembler, compile::{Compile, Options as CompileOptions}, diagnostics::{ - DefaultSourceManager, Report, SourceFile, SourceId, SourceManager, SourceSpan, Span, - Spanned, + DefaultSourceManager, Report, SourceFile, SourceId, SourceManager, SourceManagerSync, + SourceSpan, Span, Spanned, }, errors::AssemblyError, library::{ diff --git a/assembly/src/testing.rs b/assembly/src/testing.rs index 256f21c145..9cfb9e8996 100644 --- a/assembly/src/testing.rs +++ b/assembly/src/testing.rs @@ -10,7 +10,7 @@ use crate::{ assembler::Assembler, ast::{Form, Module, ModuleKind}, diagnostics::{ - Report, SourceFile, SourceManager, + Report, SourceFile, SourceManagerSync, reporting::{ReportHandlerOpts, set_hook}, }, library::Library, @@ -195,7 +195,7 @@ macro_rules! parse_module { /// /// Some of the assertion macros defined above require a [TestContext], so be aware of that. pub struct TestContext { - source_manager: Arc, + source_manager: Arc, assembler: Assembler, } @@ -233,7 +233,7 @@ impl TestContext { } #[inline(always)] - pub fn source_manager(&self) -> Arc { + pub fn source_manager(&self) -> Arc { self.source_manager.clone() } diff --git a/core/src/debuginfo/mod.rs b/core/src/debuginfo/mod.rs index 27772806de..52a11c7433 100644 --- a/core/src/debuginfo/mod.rs +++ b/core/src/debuginfo/mod.rs @@ -10,6 +10,6 @@ pub use self::{ source_file::{ ByteIndex, ByteOffset, ColumnIndex, LineIndex, SourceContent, SourceFile, SourceFileRef, }, - source_manager::{DefaultSourceManager, SourceId, SourceManager}, + source_manager::{DefaultSourceManager, SourceId, SourceManager, SourceManagerSync}, span::{SourceSpan, Span, Spanned}, }; diff --git a/core/src/debuginfo/source_manager.rs b/core/src/debuginfo/source_manager.rs index 77071b51e9..7a7234fe2b 100644 --- a/core/src/debuginfo/source_manager.rs +++ b/core/src/debuginfo/source_manager.rs @@ -101,6 +101,9 @@ impl SourceManagerError { } } +pub trait SourceManagerSync: SourceManager + Send + Sync {} +impl SourceManagerSync for T {} + pub trait SourceManager: Debug { /// Returns true if `file` is managed by this source manager fn is_manager_of(&self, file: &SourceFile) -> bool { diff --git a/miden/src/cli/data.rs b/miden/src/cli/data.rs index 9b0c82ec39..f64b2bcbd4 100644 --- a/miden/src/cli/data.rs +++ b/miden/src/cli/data.rs @@ -6,7 +6,7 @@ use std::{ }; use assembly::{ - Assembler, Library, LibraryNamespace, SourceManager, + Assembler, Library, LibraryNamespace, SourceManagerSync, ast::{Module, ModuleKind}, diagnostics::{Report, WrapErr}, report, @@ -109,7 +109,7 @@ impl OutputFile { pub struct ProgramFile { ast: Box, - source_manager: Arc, + source_manager: Arc, } /// Helper methods to interact with masm program file. @@ -125,7 +125,7 @@ impl ProgramFile { #[instrument(name = "read_program_file", skip(source_manager), fields(path = %path.as_ref().display()))] pub fn read_with( path: impl AsRef, - source_manager: Arc, + source_manager: Arc, ) -> Result { // parse the program into an AST let path = path.as_ref(); @@ -160,7 +160,7 @@ impl ProgramFile { } /// Returns the source manager for this program file. - pub fn source_manager(&self) -> &Arc { + pub fn source_manager(&self) -> &Arc { &self.source_manager } } diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index b515eb9f7a..bb913461a0 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -14,7 +14,9 @@ use alloc::{ }; use assembly::{KernelLibrary, Library}; -pub use assembly::{LibraryPath, SourceFile, SourceManager, diagnostics::Report}; +pub use assembly::{ + LibraryPath, SourceFile, SourceManager, SourceManagerSync, diagnostics::Report, +}; pub use pretty_assertions::{assert_eq, assert_ne, assert_str_eq}; pub use processor::{ AdviceInputs, AdviceProvider, ContextId, ExecutionError, ExecutionOptions, ExecutionTrace, @@ -171,7 +173,7 @@ macro_rules! assert_assembler_diagnostic { /// - Execution error test: check that running a program compiled from the given source causes an /// ExecutionError which contains the specified substring. pub struct Test { - pub source_manager: Arc, + pub source_manager: Arc, pub source: Arc, pub kernel_source: Option>, pub stack_inputs: StackInputs,