Skip to content

Commit

Permalink
chore: Use the elaborator by default (noir-lang#5246)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

## Summary\*

Removes the `--use-elaborator` flag, replacing it with `--use-legacy` to
enable the old name resolver & type checker passes which are now off by
default in favor of the elaborator.

## Additional Context

No user visible changes are expected from this PR.

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
jfecher authored Jun 17, 2024
1 parent 540bef3 commit 55d8e05
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
12 changes: 6 additions & 6 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub struct CompileOptions {
#[arg(long, hide = true)]
pub force_brillig: bool,

/// Enable the experimental elaborator pass
/// Use the deprecated name resolution & type checking passes instead of the elaborator
#[arg(long, hide = true)]
pub use_elaborator: bool,
pub use_legacy: bool,

/// Outputs the paths to any modified artifacts
#[arg(long, hide = true)]
Expand Down Expand Up @@ -257,13 +257,13 @@ pub fn check_crate(
crate_id: CrateId,
deny_warnings: bool,
disable_macros: bool,
use_elaborator: bool,
use_legacy: bool,
) -> CompilationResult<()> {
let macros: &[&dyn MacroProcessor] =
if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };

let mut errors = vec![];
let diagnostics = CrateDefMap::collect_defs(crate_id, context, use_elaborator, macros);
let diagnostics = CrateDefMap::collect_defs(crate_id, context, use_legacy, macros);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
let diagnostic = CustomDiagnostic::from(&error);
diagnostic.in_file(file_id)
Expand Down Expand Up @@ -300,7 +300,7 @@ pub fn compile_main(
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_elaborator,
options.use_legacy,
)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
Expand Down Expand Up @@ -341,7 +341,7 @@ pub fn compile_contract(
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_elaborator,
options.use_legacy,
)?;

// TODO: We probably want to error if contracts is empty
Expand Down
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ impl<'context> Elaborator<'context> {
fn elaborate_global(&mut self, global: UnresolvedGlobal) {
let old_module = std::mem::replace(&mut self.local_module, global.module_id);
let old_file = std::mem::replace(&mut self.file, global.file_id);
let old_item = self.current_item.take();

let global_id = global.global_id;
self.current_item = Some(DependencyId::Global(global_id));
Expand Down Expand Up @@ -1171,6 +1172,7 @@ impl<'context> Elaborator<'context> {
self.type_variables.clear();
self.local_module = old_module;
self.file = old_file;
self.current_item = old_item;
}

fn elaborate_comptime_global(&mut self, global_id: GlobalId) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl DefCollector {
context: &mut Context,
ast: SortedModule,
root_file_id: FileId,
use_elaborator: bool,
use_legacy: bool,
macro_processors: &[&dyn MacroProcessor],
) -> Vec<(CompilationError, FileId)> {
let mut errors: Vec<(CompilationError, FileId)> = vec![];
Expand All @@ -273,7 +273,7 @@ impl DefCollector {
errors.extend(CrateDefMap::collect_defs(
dep.crate_id,
context,
use_elaborator,
use_legacy,
macro_processors,
));

Expand Down Expand Up @@ -351,7 +351,7 @@ impl DefCollector {
}
}

if use_elaborator {
if !use_legacy {
let mut more_errors = Elaborator::elaborate(context, crate_id, def_collector.items);
errors.append(&mut more_errors);
return errors;
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl CrateDefMap {
pub fn collect_defs(
crate_id: CrateId,
context: &mut Context,
use_elaborator: bool,
use_legacy: bool,
macro_processors: &[&dyn MacroProcessor],
) -> Vec<(CompilationError, FileId)> {
// Check if this Crate has already been compiled
Expand Down Expand Up @@ -122,7 +122,7 @@ impl CrateDefMap {
context,
ast,
root_file_id,
use_elaborator,
use_legacy,
macro_processors,
));

Expand Down
55 changes: 27 additions & 28 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ fn generate_execution_success_tests(test_file: &mut File, test_data_dir: &Path)
test_file,
r#"
#[test]
fn execution_success_{test_name}() {{
fn execution_success_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force");
cmd.arg("execute").arg("--force").arg("--use-legacy");
cmd.assert().success();
}}
#[test]
fn execution_success_elaborator_{test_name}() {{
fn execution_success_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force").arg("--use-elaborator");
cmd.arg("execute").arg("--force");
cmd.assert().success();
}}
Expand Down Expand Up @@ -146,23 +146,23 @@ fn generate_execution_failure_tests(test_file: &mut File, test_data_dir: &Path)
test_file,
r#"
#[test]
fn execution_failure_{test_name}() {{
fn execution_failure_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force");
cmd.arg("execute").arg("--force").arg("--use-legacy");
cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
#[test]
fn execution_failure_elaborator_{test_name}() {{
fn execution_failure_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force").arg("--use-elaborator");
cmd.arg("execute").arg("--force");
cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
Expand Down Expand Up @@ -194,23 +194,23 @@ fn generate_noir_test_success_tests(test_file: &mut File, test_data_dir: &Path)
test_file,
r#"
#[test]
fn noir_test_success_{test_name}() {{
fn noir_test_success_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("test");
cmd.arg("test").arg("--use-legacy");
cmd.assert().success();
}}
#[test]
fn noir_test_success_elaborator_{test_name}() {{
fn noir_test_success_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("test").arg("--use-elaborator");
cmd.arg("test");
cmd.assert().success();
}}
Expand Down Expand Up @@ -242,23 +242,23 @@ fn generate_noir_test_failure_tests(test_file: &mut File, test_data_dir: &Path)
test_file,
r#"
#[test]
fn noir_test_failure_{test_name}() {{
fn noir_test_failure_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("test");
cmd.arg("test").arg("--use-legacy");
cmd.assert().failure();
}}
#[test]
fn noir_test_failure_elaborator_{test_name}() {{
fn noir_test_failure_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("test").arg("--use-elaborator");
cmd.arg("test");
cmd.assert().failure();
}}
Expand Down Expand Up @@ -293,14 +293,14 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa
test_file,
r#"
#[test]{comptime_ignored}
fn compile_success_empty_{test_name}() {{
fn compile_success_empty_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("info");
cmd.arg("--json");
cmd.arg("--force");
cmd.arg("--use-legacy");
let output = cmd.output().expect("Failed to execute command");
Expand All @@ -317,14 +317,13 @@ fn compile_success_empty_{test_name}() {{
}}
#[test]
fn compile_success_empty_elaborator_{test_name}() {{
fn compile_success_empty_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("info");
cmd.arg("--json");
cmd.arg("--force");
cmd.arg("--use-elaborator");
let output = cmd.output().expect("Failed to execute command");
Expand Down Expand Up @@ -367,22 +366,22 @@ fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir:
test_file,
r#"
#[test]
fn compile_success_contract_{test_name}() {{
fn compile_success_contract_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("compile").arg("--force");
cmd.arg("compile").arg("--force").arg("--use-legacy");
cmd.assert().success();
}}
#[test]
fn compile_success_contract_elaborator_{test_name}() {{
fn compile_success_contract_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("compile").arg("--force").arg("--use-elaborator");
cmd.arg("compile").arg("--force");
cmd.assert().success();
}}
Expand Down Expand Up @@ -414,22 +413,22 @@ fn generate_compile_failure_tests(test_file: &mut File, test_data_dir: &Path) {
test_file,
r#"
#[test]
fn compile_failure_{test_name}() {{
fn compile_failure_legacy_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("compile").arg("--force");
cmd.arg("compile").arg("--force").arg("--use-legacy");
cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
#[test]
fn compile_failure_elaborator_{test_name}() {{
fn compile_failure_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("compile").arg("--force").arg("--use-elaborator");
cmd.arg("compile").arg("--force");
cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
Expand Down
6 changes: 3 additions & 3 deletions tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn check_package(
compile_options.deny_warnings,
compile_options.disable_macros,
compile_options.silence_warnings,
compile_options.use_elaborator,
compile_options.use_legacy,
)?;

if package.is_library() || package.is_contract() {
Expand Down Expand Up @@ -160,9 +160,9 @@ pub(crate) fn check_crate_and_report_errors(
deny_warnings: bool,
disable_macros: bool,
silence_warnings: bool,
use_elaborator: bool,
use_legacy: bool,
) -> Result<(), CompileError> {
let result = check_crate(context, crate_id, deny_warnings, disable_macros, use_elaborator);
let result = check_crate(context, crate_id, deny_warnings, disable_macros, use_legacy);
report_errors(result, &context.file_manager, deny_warnings, silence_warnings)
}

Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/export_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn compile_exported_functions(
compile_options.deny_warnings,
compile_options.disable_macros,
compile_options.silence_warnings,
compile_options.use_elaborator,
compile_options.use_legacy,
)?;

let exported_functions = context.get_all_exported_functions_in_crate(&crate_id);
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn run_test<S: BlackBoxFunctionSolver<FieldElement> + Default>(
crate_id,
compile_options.deny_warnings,
compile_options.disable_macros,
compile_options.use_elaborator,
compile_options.use_legacy,
)
.expect("Any errors should have occurred when collecting test functions");

Expand Down Expand Up @@ -209,7 +209,7 @@ fn get_tests_in_package(
compile_options.deny_warnings,
compile_options.disable_macros,
compile_options.silence_warnings,
compile_options.use_elaborator,
compile_options.use_legacy,
)?;

Ok(context
Expand Down

0 comments on commit 55d8e05

Please sign in to comment.