Skip to content

Commit 48cda7a

Browse files
authored
fix!: prevent inconsistent language usage in Driver (#881)
fix: prevent inconsistent language usage in `Driver`
1 parent f304afc commit 48cda7a

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

crates/nargo/src/cli/compile_cmd.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ pub fn compile_circuit<P: AsRef<Path>>(
6262
let mut driver = Resolver::resolve_root_config(program_dir.as_ref(), backend.np_language())?;
6363
add_std_lib(&mut driver);
6464

65-
driver
66-
.into_compiled_program(backend.np_language(), show_ssa, allow_warnings)
67-
.map_err(|_| std::process::exit(1))
65+
driver.into_compiled_program(show_ssa, allow_warnings).map_err(|_| std::process::exit(1))
6866
}
6967

7068
fn preprocess_with_path<P: AsRef<Path>>(

crates/nargo/src/cli/test_cmd.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ fn run_test(
9191
show_output: bool,
9292
) -> Result<(), CliError> {
9393
let backend = crate::backends::ConcreteBackend;
94-
let language = backend.np_language();
9594

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

10099
let mut solved_witness = BTreeMap::new();

crates/noirc_driver/src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};
1616

1717
pub struct Driver {
1818
context: Context,
19+
language: Language,
1920
}
2021

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

2728
impl Driver {
28-
pub fn new(np_language: &acvm::Language) -> Self {
29-
let mut driver = Driver { context: Context::default() };
29+
pub fn new(np_language: &Language) -> Self {
30+
let mut driver = Driver { context: Context::default(), language: np_language.clone() };
3031
driver.context.def_interner.set_language(np_language);
3132
driver
3233
}
@@ -37,9 +38,7 @@ impl Driver {
3738
let mut driver = Driver::new(&np_language);
3839
driver.create_local_crate(root_file, CrateType::Binary);
3940

40-
driver
41-
.into_compiled_program(np_language, false, false)
42-
.unwrap_or_else(|_| std::process::exit(1))
41+
driver.into_compiled_program(false, false).unwrap_or_else(|_| std::process::exit(1))
4342
}
4443

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

147146
pub fn into_compiled_program(
148147
mut self,
149-
np_language: acvm::Language,
150148
show_ssa: bool,
151149
allow_warnings: bool,
152150
) -> Result<CompiledProgram, ReportedError> {
153151
self.check_crate(allow_warnings)?;
154-
self.compile_no_check(np_language, show_ssa, allow_warnings, None, true)
152+
self.compile_no_check(show_ssa, allow_warnings, None, true)
155153
}
156154

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

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

183+
let np_language = self.language.clone();
186184
let blackbox_supported = acvm::default_is_black_box_supported(np_language.clone());
187185

188186
match create_circuit(program, np_language, blackbox_supported, show_ssa, show_output) {

crates/noirc_driver/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ fn main() {
1818
driver.add_dep(LOCAL_CRATE, crate_id1, "coo4");
1919
driver.add_dep(LOCAL_CRATE, crate_id2, "coo3");
2020

21-
driver.into_compiled_program(acvm::Language::R1CS, false, false).ok();
21+
driver.into_compiled_program(false, false).ok();
2222
}

0 commit comments

Comments
 (0)