Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: prevent inconsistent language usage in Driver #881

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/nargo/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ pub fn compile_circuit<P: AsRef<Path>>(
let mut driver = Resolver::resolve_root_config(program_dir.as_ref(), backend.np_language())?;
add_std_lib(&mut driver);

driver
.into_compiled_program(backend.np_language(), show_ssa, allow_warnings)
.map_err(|_| std::process::exit(1))
driver.into_compiled_program(show_ssa, allow_warnings).map_err(|_| std::process::exit(1))
}

fn preprocess_with_path<P: AsRef<Path>>(
Expand Down
3 changes: 1 addition & 2 deletions crates/nargo/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ fn run_test(
show_output: bool,
) -> Result<(), CliError> {
let backend = crate::backends::ConcreteBackend;
let language = backend.np_language();

let program = driver
.compile_no_check(language, false, allow_warnings, Some(main), show_output)
.compile_no_check(false, allow_warnings, Some(main), show_output)
.map_err(|_| CliError::Generic(format!("Test '{test_name}' failed to compile")))?;

let mut solved_witness = BTreeMap::new();
Expand Down
14 changes: 6 additions & 8 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};

pub struct Driver {
context: Context,
language: Language,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand All @@ -25,8 +26,8 @@ pub struct CompiledProgram {
}

impl Driver {
pub fn new(np_language: &acvm::Language) -> Self {
let mut driver = Driver { context: Context::default() };
pub fn new(np_language: &Language) -> Self {
let mut driver = Driver { context: Context::default(), language: np_language.clone() };
driver.context.def_interner.set_language(np_language);
driver
}
Expand All @@ -37,9 +38,7 @@ impl Driver {
let mut driver = Driver::new(&np_language);
driver.create_local_crate(root_file, CrateType::Binary);

driver
.into_compiled_program(np_language, false, false)
.unwrap_or_else(|_| std::process::exit(1))
driver.into_compiled_program(false, false).unwrap_or_else(|_| std::process::exit(1))
}

/// Compiles a file and returns true if compilation was successful
Expand Down Expand Up @@ -146,19 +145,17 @@ impl Driver {

pub fn into_compiled_program(
mut self,
np_language: acvm::Language,
show_ssa: bool,
allow_warnings: bool,
) -> Result<CompiledProgram, ReportedError> {
self.check_crate(allow_warnings)?;
self.compile_no_check(np_language, show_ssa, allow_warnings, None, true)
self.compile_no_check(show_ssa, allow_warnings, None, true)
}

/// Compile the current crate. Assumes self.check_crate is called beforehand!
#[allow(deprecated)]
pub fn compile_no_check(
&self,
np_language: acvm::Language,
show_ssa: bool,
allow_warnings: bool,
// Optional override to provide a different `main` function to start execution
Expand All @@ -183,6 +180,7 @@ impl Driver {

let program = monomorphize(main_function, &self.context.def_interner);

let np_language = self.language.clone();
let blackbox_supported = acvm::default_is_black_box_supported(np_language.clone());

match create_circuit(program, np_language, blackbox_supported, show_ssa, show_output) {
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ fn main() {
driver.add_dep(LOCAL_CRATE, crate_id1, "coo4");
driver.add_dep(LOCAL_CRATE, crate_id2, "coo3");

driver.into_compiled_program(acvm::Language::R1CS, false, false).ok();
driver.into_compiled_program(false, false).ok();
}