diff --git a/assembly/src/assembler/instruction/mod.rs b/assembly/src/assembler/instruction/mod.rs index 0695ff04b..51080e82b 100644 --- a/assembly/src/assembler/instruction/mod.rs +++ b/assembly/src/assembler/instruction/mod.rs @@ -1,14 +1,13 @@ use core::ops::RangeBounds; +use miette::miette; use vm_core::{mast::MastNodeId, Decorator, ONE, ZERO}; use super::{ ast::InvokeKind, mast_forest_builder::MastForestBuilder, Assembler, BasicBlockBuilder, Felt, Operation, ProcedureContext, }; -use crate::{ - ast::Instruction, diagnostics::Report, utils::bound_into_included_u64, AssemblyError, Span, -}; +use crate::{ast::Instruction, utils::bound_into_included_u64, AssemblyError, Span}; mod adv_ops; mod crypto_ops; @@ -480,10 +479,10 @@ where let min = bound_into_included_u64(range.start_bound(), true); let max = bound_into_included_u64(range.end_bound(), false); AssemblyError::Other( - Report::msg(format!( + miette!( "parameter value must be greater than or equal to {min} and \ less than or equal to {max}, but was {value}", - )) + ) .into(), ) }) diff --git a/assembly/src/assembler/mod.rs b/assembly/src/assembler/mod.rs index 01c53e1c0..ac2712b7c 100644 --- a/assembly/src/assembler/mod.rs +++ b/assembly/src/assembler/mod.rs @@ -193,8 +193,7 @@ impl Assembler { namespace: crate::LibraryNamespace, dir: &std::path::Path, ) -> Result<(), Report> { - let source_manager = self.source_manager.clone(); - for module in crate::parser::read_modules_from_dir(namespace, dir, source_manager)? { + for module in crate::parser::read_modules_from_dir(namespace, dir, &self.source_manager)? { self.module_graph.add_ast_module(module)?; } diff --git a/assembly/src/compile.rs b/assembly/src/compile.rs index 1d4243809..1d2fda3a4 100644 --- a/assembly/src/compile.rs +++ b/assembly/src/compile.rs @@ -6,6 +6,8 @@ use alloc::{ vec::Vec, }; +use miette::miette; + use crate::{ ast::{Module, ModuleKind}, diagnostics::{ @@ -152,10 +154,10 @@ impl Compile for Box { } Ok(self) } else { - Err(Report::msg(format!( + Err(miette!( "compilation failed: expected a {} module, but got a {actual} module", options.kind - ))) + )) } } } diff --git a/assembly/src/library/mod.rs b/assembly/src/library/mod.rs index b2a40fa5f..283f89044 100644 --- a/assembly/src/library/mod.rs +++ b/assembly/src/library/mod.rs @@ -276,7 +276,7 @@ mod use_std_library { let path = path.as_ref(); let modules = - crate::parser::read_modules_from_dir(namespace, path, assembler.source_manager())?; + crate::parser::read_modules_from_dir(namespace, path, &assembler.source_manager())?; assembler.assemble_library(modules) } diff --git a/assembly/src/parser/mod.rs b/assembly/src/parser/mod.rs index d1bef3019..440f0cb5a 100644 --- a/assembly/src/parser/mod.rs +++ b/assembly/src/parser/mod.rs @@ -21,6 +21,8 @@ mod token; use alloc::{boxed::Box, collections::BTreeSet, string::ToString, sync::Arc, vec::Vec}; +use miette::miette; + pub use self::{ error::{BinErrorKind, HexErrorKind, LiteralErrorKind, ParsingError}, lexer::Lexer, @@ -33,6 +35,9 @@ use crate::{ sema, LibraryPath, SourceManager, }; +// TYPE ALIASES +// ================================================================================================ + type ParseError<'a> = lalrpop_util::ParseError, ParsingError>; // MODULE PARSER @@ -173,7 +178,7 @@ fn parse_forms_internal( pub fn read_modules_from_dir( namespace: crate::LibraryNamespace, dir: &std::path::Path, - source_manager: Arc, + source_manager: &dyn SourceManager, ) -> Result>, Report> { use std::collections::{btree_map::Entry, BTreeMap}; @@ -182,18 +187,12 @@ pub fn read_modules_from_dir( use crate::diagnostics::{IntoDiagnostic, WrapErr}; if !dir.is_dir() { - return Err(Report::msg(format!( - "the provided path '{}' is not a valid directory", - dir.display() - ))); + return Err(miette!("the provided path '{}' is not a valid directory", dir.display())); } // mod.masm is not allowed in the root directory if dir.join(ast::Module::ROOT_FILENAME).exists() { - return Err(Report::msg(format!( - "{} is not allowed in the root directory", - ast::Module::ROOT_FILENAME - ))); + return Err(miette!("{} is not allowed in the root directory", ast::Module::ROOT_FILENAME)); } let mut modules = BTreeMap::default(); @@ -209,10 +208,10 @@ pub fn read_modules_from_dir( // Parse module at the given path let mut parser = ModuleParser::new(ast::ModuleKind::Library); - let ast = parser.parse_file(name.clone(), &source_path, &source_manager)?; + let ast = parser.parse_file(name.clone(), &source_path, source_manager)?; match modules.entry(name) { Entry::Occupied(ref entry) => { - return Err(Report::msg(format!("duplicate module '{0}'", entry.key().clone()))); + return Err(miette!("duplicate module '{0}'", entry.key().clone())); }, Entry::Vacant(entry) => { entry.insert(ast); @@ -233,6 +232,7 @@ mod module_walker { path::{Path, PathBuf}, }; + use super::miette; use crate::{ ast::Module, diagnostics::{IntoDiagnostic, Report}, @@ -282,10 +282,10 @@ mod module_walker { // Remove the file extension and the root prefix, leaving a namespace-relative path file_path.set_extension(""); if file_path.is_dir() { - return Err(Report::msg(format!( + return Err(miette!( "file and directory with same name are not allowed: {}", file_path.display() - ))); + )); } let relative_path = file_path .strip_prefix(self.root) @@ -296,7 +296,7 @@ mod module_walker { for component in relative_path.iter() { let component = component.to_str().ok_or_else(|| { let p = entry.path(); - Report::msg(format!("{} is an invalid directory entry", p.display())) + miette!("{} is an invalid directory entry", p.display()) })?; libpath.push(component).into_diagnostic()?; } diff --git a/miden/src/cli/bundle.rs b/miden/src/cli/bundle.rs index c4f4bd7dd..07ae7aa56 100644 --- a/miden/src/cli/bundle.rs +++ b/miden/src/cli/bundle.rs @@ -42,8 +42,6 @@ impl BundleCmd { let assembler = Assembler::default().with_debug_mode(true); let library_namespace = namespace.parse::().expect("invalid base namespace"); - // TODO: Add version to `Library` - // let version = self.version.parse::().expect("invalid cargo version"); let library = Library::from_dir(&self.dir, library_namespace, assembler)?; // write the masl output diff --git a/stdlib/build.rs b/stdlib/build.rs index d30159fc1..231cf9e62 100644 --- a/stdlib/build.rs +++ b/stdlib/build.rs @@ -27,8 +27,6 @@ fn main() -> Result<()> { let assembler = Assembler::default().with_debug_mode(cfg!(feature = "with-debug-info")); let namespace = "std".parse::().expect("invalid base namespace"); - // TODO: Add version to `Library` - //let version = env!("CARGO_PKG_VERSION").parse::().expect("invalid cargo version"); let stdlib = Library::from_dir(asm_dir, namespace, assembler)?; // write the masl output