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

feat: increase default expression width to 4 #4995

Merged
merged 5 commits into from
May 8, 2024
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
2 changes: 1 addition & 1 deletion acvm-repo/acir/benches/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn sample_program(num_opcodes: usize) -> Program {
functions: vec![Circuit {
current_witness_index: 4000,
opcodes: assert_zero_opcodes.to_vec(),
expression_width: ExpressionWidth::Bounded { width: 3 },
expression_width: ExpressionWidth::Bounded { width: 4 },
private_parameters: BTreeSet::from([Witness(1), Witness(2), Witness(3), Witness(4)]),
public_parameters: PublicInputs(BTreeSet::from([Witness(5)])),
return_values: PublicInputs(BTreeSet::from([Witness(6)])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mod tests {
fn test_circuit(opcodes: Vec<Opcode>) -> Circuit {
Circuit {
current_witness_index: 1,
expression_width: ExpressionWidth::Bounded { width: 3 },
expression_width: ExpressionWidth::Bounded { width: 4 },
opcodes,
private_parameters: BTreeSet::new(),
public_parameters: PublicInputs::default(),
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {

Circuit {
current_witness_index: 1,
expression_width: ExpressionWidth::Bounded { width: 3 },
expression_width: ExpressionWidth::Bounded { width: 4 },
opcodes,
private_parameters: BTreeSet::new(),
public_parameters: PublicInputs::default(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub const NOIR_ARTIFACT_VERSION_STRING: &str =
#[derive(Args, Clone, Debug, Default)]
pub struct CompileOptions {
/// Override the expression width requested by the backend.
#[arg(long, value_parser = parse_expression_width, default_value = "3")]
#[arg(long, value_parser = parse_expression_width, default_value = "4")]
pub expression_width: ExpressionWidth,

/// Force a full recompilation.
Expand Down
21 changes: 13 additions & 8 deletions compiler/wasm/src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use acvm::acir::circuit::ExpressionWidth;
use fm::FileManager;
use gloo_utils::format::JsValueSerdeExt;
use js_sys::{JsString, Object};
Expand Down Expand Up @@ -169,9 +170,10 @@ pub fn compile_program(
console_error_panic_hook::set_once();
let (crate_id, mut context) = prepare_context(entry_point, dependency_graph, file_source_map)?;

let compile_options = CompileOptions::default();
// For now we default to a bounded width of 3, though we can add it as a parameter
let expression_width = acvm::acir::circuit::ExpressionWidth::Bounded { width: 3 };
let compile_options = CompileOptions {
expression_width: ExpressionWidth::Bounded { width: 4 },
..CompileOptions::default()
};

let compiled_program =
noirc_driver::compile_main(&mut context, crate_id, &compile_options, None)
Expand All @@ -184,7 +186,8 @@ pub fn compile_program(
})?
.0;

let optimized_program = nargo::ops::transform_program(compiled_program, expression_width);
let optimized_program =
nargo::ops::transform_program(compiled_program, compile_options.expression_width);
let warnings = optimized_program.warnings.clone();

Ok(JsCompileProgramResult::new(optimized_program.into(), warnings))
Expand All @@ -199,9 +202,10 @@ pub fn compile_contract(
console_error_panic_hook::set_once();
let (crate_id, mut context) = prepare_context(entry_point, dependency_graph, file_source_map)?;

let compile_options = CompileOptions::default();
// For now we default to a bounded width of 3, though we can add it as a parameter
let expression_width = acvm::acir::circuit::ExpressionWidth::Bounded { width: 3 };
let compile_options = CompileOptions {
expression_width: ExpressionWidth::Bounded { width: 4 },
..CompileOptions::default()
};

let compiled_contract =
noirc_driver::compile_contract(&mut context, crate_id, &compile_options)
Expand All @@ -214,7 +218,8 @@ pub fn compile_contract(
})?
.0;

let optimized_contract = nargo::ops::transform_contract(compiled_contract, expression_width);
let optimized_contract =
nargo::ops::transform_contract(compiled_contract, compile_options.expression_width);

let functions =
optimized_contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();
Expand Down
30 changes: 20 additions & 10 deletions compiler/wasm/src/compile_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::compile::{
PathToFileSourceMap,
};
use crate::errors::{CompileError, JsCompileError};
use acvm::acir::circuit::ExpressionWidth;
use nargo::artifacts::contract::{ContractArtifact, ContractFunctionArtifact};
use nargo::parse_all;
use noirc_driver::{
Expand Down Expand Up @@ -96,11 +97,14 @@ impl CompilerContext {
mut self,
program_width: usize,
) -> Result<JsCompileProgramResult, JsCompileError> {
let compile_options = CompileOptions::default();
let np_language = acvm::acir::circuit::ExpressionWidth::Bounded { width: program_width };
let expression_width = if program_width == 0 {
ExpressionWidth::Unbounded
} else {
ExpressionWidth::Bounded { width: 4 }
};
let compile_options = CompileOptions { expression_width, ..CompileOptions::default() };

let root_crate_id = *self.context.root_crate_id();

let compiled_program =
compile_main(&mut self.context, root_crate_id, &compile_options, None)
.map_err(|errs| {
Expand All @@ -112,7 +116,8 @@ impl CompilerContext {
})?
.0;

let optimized_program = nargo::ops::transform_program(compiled_program, np_language);
let optimized_program =
nargo::ops::transform_program(compiled_program, compile_options.expression_width);
let warnings = optimized_program.warnings.clone();

Ok(JsCompileProgramResult::new(optimized_program.into(), warnings))
Expand All @@ -122,10 +127,14 @@ impl CompilerContext {
mut self,
program_width: usize,
) -> Result<JsCompileContractResult, JsCompileError> {
let compile_options = CompileOptions::default();
let np_language = acvm::acir::circuit::ExpressionWidth::Bounded { width: program_width };
let root_crate_id = *self.context.root_crate_id();
let expression_width = if program_width == 0 {
ExpressionWidth::Unbounded
} else {
ExpressionWidth::Bounded { width: 4 }
};
let compile_options = CompileOptions { expression_width, ..CompileOptions::default() };

let root_crate_id = *self.context.root_crate_id();
let compiled_contract =
compile_contract(&mut self.context, root_crate_id, &compile_options)
.map_err(|errs| {
Expand All @@ -137,7 +146,8 @@ impl CompilerContext {
})?
.0;

let optimized_contract = nargo::ops::transform_contract(compiled_contract, np_language);
let optimized_contract =
nargo::ops::transform_contract(compiled_contract, compile_options.expression_width);

let functions =
optimized_contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();
Expand Down Expand Up @@ -166,7 +176,7 @@ pub fn compile_program_(

let compiler_context =
prepare_compiler_context(entry_point, dependency_graph, file_source_map)?;
let program_width = 3;
let program_width = 4;

compiler_context.compile_program(program_width)
}
Expand All @@ -183,7 +193,7 @@ pub fn compile_contract_(

let compiler_context =
prepare_compiler_context(entry_point, dependency_graph, file_source_map)?;
let program_width = 3;
let program_width = 4;

compiler_context.compile_contract(program_width)
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/dap_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use noir_debugger::errors::{DapError, LoadError};
#[derive(Debug, Clone, Args)]
pub(crate) struct DapCommand {
/// Override the expression width requested by the backend.
#[arg(long, value_parser = parse_expression_width, default_value = "3")]
#[arg(long, value_parser = parse_expression_width, default_value = "4")]
expression_width: ExpressionWidth,

#[clap(long)]
Expand Down
Loading