Skip to content
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
12 changes: 9 additions & 3 deletions crates/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub(crate) struct TestCommand {
/// If given, only tests with names containing this string will be run
test_name: Option<String>,

/// Display output of `println` statements
#[arg(long)]
show_output: bool,

#[clap(flatten)]
compile_options: CompileOptions,
}
Expand All @@ -31,13 +35,14 @@ pub(crate) fn run<B: Backend>(
) -> Result<(), CliError<B>> {
let test_name: String = args.test_name.unwrap_or_else(|| "".to_owned());

run_tests(backend, &config.program_dir, &test_name, &args.compile_options)
run_tests(backend, &config.program_dir, &test_name, args.show_output, &args.compile_options)
}

fn run_tests<B: Backend>(
backend: &B,
program_dir: &Path,
test_name: &str,
show_output: bool,
compile_options: &CompileOptions,
) -> Result<(), CliError<B>> {
let (mut context, crate_id) = resolve_root_manifest(program_dir, None)?;
Expand Down Expand Up @@ -65,7 +70,7 @@ fn run_tests<B: Backend>(
writeln!(writer, "Testing {test_name}...").expect("Failed to write to stdout");
writer.flush().ok();

match run_test(backend, &test_name, test_function, &context, compile_options) {
match run_test(backend, &test_name, test_function, &context, show_output, compile_options) {
Ok(_) => {
writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).ok();
writeln!(writer, "ok").ok();
Expand Down Expand Up @@ -93,9 +98,10 @@ fn run_test<B: Backend>(
test_name: &str,
main: FuncId,
context: &Context,
show_output: bool,
config: &CompileOptions,
) -> Result<(), CliError<B>> {
let mut program = compile_no_check(context, config, main)
let mut program = compile_no_check(context, show_output, config, main)
.map_err(|_| CliError::Generic(format!("Test '{test_name}' failed to compile")))?;
// Note: We could perform this test using the unoptimized ACIR as generated by `compile_no_check`.
program.circuit = optimize_circuit(backend, program.circuit).unwrap().0;
Expand Down
33 changes: 6 additions & 27 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod program;
pub use contract::{CompiledContract, ContractFunction, ContractFunctionType};
pub use program::CompiledProgram;

#[derive(Args, Clone, Debug, Serialize, Deserialize)]
#[derive(Args, Clone, Debug, Default, Serialize, Deserialize)]
pub struct CompileOptions {
/// Emit debug information for the intermediate SSA IR
#[arg(short, long)]
Expand All @@ -39,28 +39,11 @@ pub struct CompileOptions {
#[arg(short, long)]
pub deny_warnings: bool,

/// Display output of `println` statements
#[arg(long)]
pub show_output: bool,

/// Compile and optimize using the new experimental SSA pass
#[arg(long)]
pub experimental_ssa: bool,
}

impl Default for CompileOptions {
fn default() -> Self {
Self {
show_ssa: false,
show_brillig: false,
print_acir: false,
deny_warnings: false,
show_output: true,
experimental_ssa: false,
}
}
}

/// Helper type used to signify where only warnings are expected in file diagnostics
pub type Warnings = Vec<FileDiagnostic>;

Expand Down Expand Up @@ -216,7 +199,7 @@ pub fn compile_main(
}
};

let compiled_program = compile_no_check(context, options, main)?;
let compiled_program = compile_no_check(context, true, options, main)?;

if options.print_acir {
println!("Compiled ACIR for main:");
Expand Down Expand Up @@ -283,7 +266,7 @@ fn compile_contract(
let mut errs = Vec::new();
for function_id in &contract.functions {
let name = context.function_name(function_id).to_owned();
let function = match compile_no_check(context, options, *function_id) {
let function = match compile_no_check(context, true, options, *function_id) {
Ok(function) => function,
Err(err) => {
errs.push(err);
Expand Down Expand Up @@ -320,20 +303,16 @@ fn compile_contract(
#[allow(deprecated)]
pub fn compile_no_check(
context: &Context,
show_output: bool,
options: &CompileOptions,
main_function: FuncId,
) -> Result<CompiledProgram, FileDiagnostic> {
let program = monomorphize(main_function, &context.def_interner);

let (circuit, debug, abi) = if options.experimental_ssa {
experimental_create_circuit(
program,
options.show_ssa,
options.show_brillig,
options.show_output,
)?
experimental_create_circuit(program, options.show_ssa, options.show_brillig, show_output)?
} else {
create_circuit(program, options.show_ssa, options.show_output)?
create_circuit(program, options.show_ssa, show_output)?
};

Ok(CompiledProgram { circuit, debug, abi })
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ pub fn compile(args: JsValue) -> JsValue {
<JsValue as JsValueSerdeExt>::from_serde(&optimized_contracts).unwrap()
} else {
let main = context.get_main_function(&crate_id).expect("Could not find main function!");
let mut compiled_program =
compile_no_check(&context, &options.compile_options, main).expect("Compilation failed");
let mut compiled_program = compile_no_check(&context, true, &options.compile_options, main)
.expect("Compilation failed");

compiled_program.circuit = optimize_circuit(compiled_program.circuit);

Expand Down