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: Add Acir debug information #1864

Merged
merged 29 commits into from
Jul 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b749264
generates acir debug information
guipublic Jul 5, 2023
7745e8c
reset location
guipublic Jul 5, 2023
c4a5912
Merge branch 'master' into gd/debug_location
guipublic Jul 6, 2023
f2d847c
merge from master
guipublic Jul 6, 2023
9e65375
Display the location in the error and use index from acvm
guipublic Jul 6, 2023
f338a72
update cargo.toml
guipublic Jul 6, 2023
3bf33a5
clean-up: restore unit tests
guipublic Jul 6, 2023
f52d26e
restore the prover.toml
guipublic Jul 6, 2023
e72fd88
Merge branch 'master' into gd/debug_location
guipublic Jul 7, 2023
20a34bf
notify unsatisfied constraint only once
guipublic Jul 7, 2023
b863806
set the location and use it when inserting an instruction
guipublic Jul 7, 2023
bf27d1a
Merge remote-tracking branch 'origin/master' into gd/debug_location
kevaundray Jul 10, 2023
0ee7a8f
update to the corresponding acvm PR
guipublic Jul 11, 2023
95992e4
Merge branch 'master' into gd/debug_location
guipublic Jul 11, 2023
1ffb258
update cargo toml
guipublic Jul 11, 2023
0ceb640
Merge branch 'master' into gd/debug_location
guipublic Jul 11, 2023
90afcae
code review: remove temp code
guipublic Jul 12, 2023
7e48183
Code review
guipublic Jul 12, 2023
8bd17d9
Code review
guipublic Jul 12, 2023
e066dea
Update crates/noirc_errors/src/debug_info.rs
kevaundray Jul 12, 2023
0d21f7e
Merge remote-tracking branch 'origin/master' into gd/debug_location
kevaundray Jul 12, 2023
d440022
fix typo
kevaundray Jul 12, 2023
2ce27f7
fix merge
kevaundray Jul 12, 2023
97b3f8d
minor nit
kevaundray Jul 12, 2023
f1587b8
revert all test changes
kevaundray Jul 12, 2023
566648d
add noirc_errors as a dependency to nargo
kevaundray Jul 12, 2023
82241b6
preprocess_program returns DebugInfo
kevaundray Jul 12, 2023
aa7a8ea
modify all methods which call preprocess_program
kevaundray Jul 12, 2023
b0c34b6
change unwrap to expect
kevaundray Jul 12, 2023
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
Prev Previous commit
Next Next commit
Merge branch 'master' into gd/debug_location
guipublic committed Jul 7, 2023
commit e72fd88f5bc34c049c790abf54b41906fba01308
10 changes: 5 additions & 5 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
@@ -112,15 +112,15 @@ pub(crate) fn compile_circuit<B: Backend>(
backend: &B,
program_dir: &Path,
compile_options: &CompileOptions,
) -> Result<(CompiledProgram, Driver), CliError<B>> {
let mut driver = Resolver::resolve_root_manifest(program_dir)?;
let result = driver.compile_main(
) -> Result<CompiledProgram, CliError<B>> {
let mut context = resolve_root_manifest(program_dir)?;
let result = compile_main(
&mut context,
backend.np_language(),
&|op| backend.supports_opcode(op),
compile_options,
);
let compiled_program = report_errors(result, &driver, compile_options.deny_warnings);
Ok((compiled_program?, driver))
report_errors(result, &context, compile_options.deny_warnings).map_err(Into::into)
}

/// Helper function for reporting any errors in a Result<(T, Warnings), ErrorsAndWarnings>
144 changes: 6 additions & 138 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -253,140 +253,8 @@ pub fn compile_contracts(
}
}
}
}

/// True if there are (non-warning) errors present and we should halt compilation
fn has_errors(errors: &[FileDiagnostic], deny_warnings: bool) -> bool {
if deny_warnings {
!errors.is_empty()
} else {
errors.iter().any(|error| error.diagnostic.is_error())
}
}

/// Compile all of the functions associated with a Noir contract.
fn compile_contract(
&self,
contract: Contract,
np_language: Language,
is_opcode_supported: &impl Fn(&Opcode) -> bool,
options: &CompileOptions,
) -> Result<CompiledContract, Vec<FileDiagnostic>> {
let mut functions = Vec::new();
let mut errs = Vec::new();
for function_id in &contract.functions {
let name = self.function_name(*function_id).to_owned();
let function = match self.compile_no_check(
options,
*function_id,
np_language,
is_opcode_supported,
) {
Ok(function) => function,
Err(err) => {
errs.push(err);
continue;
}
};
let func_meta = self.context.def_interner.function_meta(function_id);
let func_type = func_meta
.contract_function_type
.expect("Expected contract function to have a contract visibility");

let function_type = ContractFunctionType::new(func_type, func_meta.is_unconstrained);

functions.push(ContractFunction {
name,
function_type,
abi: function.abi,
bytecode: function.circuit,
});
}

if errs.is_empty() {
Ok(CompiledContract { name: contract.name, functions })
} else {
Err(errs)
}
}

/// Returns the FuncId of the 'main' function.
/// - Expects check_crate to be called beforehand
/// - Panics if no main function is found
pub fn main_function(&self) -> Option<FuncId> {
// Find the local crate, one should always be present
let local_crate = self.context.def_map(LOCAL_CRATE).unwrap();

// Check the crate type
// We don't panic here to allow users to `evaluate` libraries which will do nothing
if self.context.crate_graph[LOCAL_CRATE].crate_type != CrateType::Binary {
None
} else {
// All Binaries should have a main function
local_crate.main_function()
}
}

/// Compile the current crate. Assumes self.check_crate is called beforehand!
///
/// This function also assumes all errors in experimental_create_circuit and create_circuit
/// are not warnings.
#[allow(deprecated)]
pub fn compile_no_check(
&self,
options: &CompileOptions,
main_function: FuncId,
np_language: Language,
is_opcode_supported: &impl Fn(&Opcode) -> bool,
) -> Result<CompiledProgram, FileDiagnostic> {
let program = monomorphize(main_function, &self.context.def_interner);

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

let abi_len = abi.field_count();

let simplifier = CircuitSimplifier::new(abi_len);
let (optimized_circuit, opcode_ids) =
acvm::compiler::compile(circuit, np_language, is_opcode_supported, &simplifier)
.map_err(|_| FileDiagnostic {
file_id: FileId::dummy(),
diagnostic: CustomDiagnostic::from_message("produced an acvm compile error"),
})?;
debug.update_acir(opcode_ids);
Ok(CompiledProgram { circuit: optimized_circuit, debug, abi })
}

/// Returns a list of all functions in the current crate marked with #[test]
/// whose names contain the given pattern string. An empty pattern string
/// will return all functions marked with #[test].
pub fn get_all_test_functions_in_crate_matching(&self, pattern: &str) -> Vec<FuncId> {
let interner = &self.context.def_interner;
self.context
.def_map(LOCAL_CRATE)
.expect("The local crate should be analyzed already")
.get_all_test_functions(interner)
.filter_map(|id| interner.function_name(&id).contains(pattern).then_some(id))
.collect()
}

/// Return a Vec of all `contract` declarations in the source code and the functions they contain
pub fn get_all_contracts(&self) -> Vec<Contract> {
self.context
.def_map(LOCAL_CRATE)
.expect("The local crate should be analyzed already")
.get_all_contracts()
}

pub fn function_name(&self, id: FuncId) -> &str {
self.context.def_interner.function_name(&id)
}

pub fn function_meta(&self, func_id: &FuncId) -> FuncMeta {
self.context.def_interner.function_meta(func_id)
// errors here is either empty or contains only warnings
Ok((compiled_contracts, errors))
}
}

@@ -460,7 +328,7 @@ pub fn compile_no_check(
) -> Result<CompiledProgram, FileDiagnostic> {
let program = monomorphize(main_function, &context.def_interner);

let (circuit, abi) = if options.experimental_ssa {
let (circuit, debug, abi) = if options.experimental_ssa {
experimental_create_circuit(program, options.show_ssa, options.show_output)?
} else {
create_circuit(program, options.show_ssa, options.show_output)?
@@ -469,13 +337,13 @@ pub fn compile_no_check(
let abi_len = abi.field_count();

let simplifier = CircuitSimplifier::new(abi_len);
let optimized_circuit =
let (optimized_circuit, opcode_ids) =
acvm::compiler::compile(circuit, np_language, is_opcode_supported, &simplifier).map_err(
|_| FileDiagnostic {
file_id: FileId::dummy(),
diagnostic: CustomDiagnostic::from_message("produced an acvm compile error"),
},
)?;

Ok(CompiledProgram { circuit: optimized_circuit, abi })
debug.update_acir(opcode_ids);
Ok(CompiledProgram { circuit: optimized_circuit, debug, abi })
}
You are viewing a condensed version of this merge commit. You can view the full changes here.