Skip to content

Commit

Permalink
Remove error type
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jul 30, 2024
1 parent 9446402 commit 7a87785
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 49 deletions.
27 changes: 14 additions & 13 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,20 @@ pub fn check_crate(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<()> {
let macros: &[&dyn MacroProcessor] =
if options.disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };
let macros: &[&dyn MacroProcessor] = if options.disable_macros {
&[]
} else {
&[&aztec_macros::AztecMacro as &dyn MacroProcessor]
};

let mut errors = vec![];
let diagnostics = CrateDefMap::collect_defs(crate_id, context, options.debug_comptime_in_file.as_deref(), options.arithmetic_generics, macros);
let diagnostics = CrateDefMap::collect_defs(
crate_id,
context,
options.debug_comptime_in_file.as_deref(),
options.arithmetic_generics,
macros,
);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
let diagnostic = CustomDiagnostic::from(&error);
diagnostic.in_file(file_id)
Expand Down Expand Up @@ -304,11 +313,7 @@ pub fn compile_main(
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
) -> CompilationResult<CompiledProgram> {
let (_, mut warnings) = check_crate(
context,
crate_id,
options,
)?;
let (_, mut warnings) = check_crate(context, crate_id, options)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
// TODO(#2155): This error might be a better to exist in Nargo
Expand Down Expand Up @@ -343,11 +348,7 @@ pub fn compile_contract(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<CompiledContract> {
let (_, warnings) = check_crate(
context,
crate_id,
options,
)?;
let (_, warnings) = check_crate(context, crate_id, options)?;

// TODO: We probably want to error if contracts is empty
let contracts = context.get_all_contracts(&crate_id);
Expand Down
16 changes: 14 additions & 2 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ impl<'context> Elaborator<'context> {
debug_comptime_in_file: Option<FileId>,
enable_arithmetic_generics: bool,
) -> Vec<(CompilationError, FileId)> {
Self::elaborate_and_return_self(context, crate_id, items, debug_comptime_in_file, enable_arithmetic_generics).errors
Self::elaborate_and_return_self(
context,
crate_id,
items,
debug_comptime_in_file,
enable_arithmetic_generics,
)
.errors
}

pub fn elaborate_and_return_self(
Expand All @@ -259,7 +266,12 @@ impl<'context> Elaborator<'context> {
debug_comptime_in_file: Option<FileId>,
enable_arithmetic_generics: bool,
) -> Self {
let mut this = Self::from_context(context, crate_id, debug_comptime_in_file, enable_arithmetic_generics);
let mut this = Self::from_context(
context,
crate_id,
debug_comptime_in_file,
enable_arithmetic_generics,
);
this.elaborate_items(items);
this.check_and_pop_function_context();
this
Expand Down
9 changes: 7 additions & 2 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,13 @@ impl DefCollector {
})
});

let mut more_errors =
Elaborator::elaborate(context, crate_id, def_collector.items, debug_comptime_in_file, enable_arithmetic_generics);
let mut more_errors = Elaborator::elaborate(
context,
crate_id,
def_collector.items,
debug_comptime_in_file,
enable_arithmetic_generics,
);

errors.append(&mut more_errors);

Expand Down
9 changes: 0 additions & 9 deletions compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ pub enum ResolverError {
NonFunctionInAnnotation { span: Span },
#[error("Unknown annotation")]
UnknownAnnotation { span: Span },
#[error("Arithmetic Generics are currently experimental")]
ArithmeticGenerics { span: Span },
}

impl ResolverError {
Expand Down Expand Up @@ -469,13 +467,6 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
*span,
)
},
ResolverError::ArithmeticGenerics { span } => {
Diagnostic::simple_warning(
"Arithmetic Generics are currently an experimental feature".into(),
"Use --arithmetic-generics to enable this feature".into(),
*span,
)
},
}
}
}
9 changes: 2 additions & 7 deletions tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ fn check_package(
allow_overwrite: bool,
) -> Result<bool, CompileError> {
let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package);
check_crate_and_report_errors(
&mut context,
crate_id,
compile_options,
)?;
check_crate_and_report_errors(&mut context, crate_id, compile_options)?;

if package.is_library() || package.is_contract() {
// Libraries do not have ABIs while contracts have many, so we cannot generate a `Prover.toml` file.
Expand Down Expand Up @@ -156,8 +152,7 @@ pub(crate) fn check_crate_and_report_errors(
crate_id: CrateId,
options: &CompileOptions,
) -> Result<(), CompileError> {
let result =
check_crate(context, crate_id, options);
let result = check_crate(context, crate_id, options);
report_errors(result, &context.file_manager, options.deny_warnings, options.silence_warnings)
}

Expand Down
6 changes: 1 addition & 5 deletions tooling/nargo_cli/src/cli/export_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ fn compile_exported_functions(
compile_options: &CompileOptions,
) -> Result<(), CliError> {
let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package);
check_crate_and_report_errors(
&mut context,
crate_id,
compile_options,
)?;
check_crate_and_report_errors(&mut context, crate_id, compile_options)?;

let exported_functions = context.get_all_exported_functions_in_crate(&crate_id);

Expand Down
14 changes: 3 additions & 11 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,8 @@ fn run_test<S: BlackBoxFunctionSolver<FieldElement> + Default>(
// We then need to construct a separate copy for each test.

let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package);
check_crate(
&mut context,
crate_id,
compile_options,
)
.expect("Any errors should have occurred when collecting test functions");
check_crate(&mut context, crate_id, compile_options)
.expect("Any errors should have occurred when collecting test functions");

let test_functions = context
.get_all_test_functions_in_crate_matching(&crate_id, FunctionNameMatch::Exact(fn_name));
Expand Down Expand Up @@ -235,11 +231,7 @@ fn get_tests_in_package(
compile_options: &CompileOptions,
) -> Result<Vec<String>, CliError> {
let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package);
check_crate_and_report_errors(
&mut context,
crate_id,
compile_options,
)?;
check_crate_and_report_errors(&mut context, crate_id, compile_options)?;

Ok(context
.get_all_test_functions_in_crate_matching(&crate_id, fn_name)
Expand Down

0 comments on commit 7a87785

Please sign in to comment.