-
Notifications
You must be signed in to change notification settings - Fork 387
feat: Refactor Logging to use Brillig foreign calls #1917
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
730c9ff
initial stdlib methods to start refactoring logign
vezenovm d75aedb
foreign call enum
vezenovm f28b915
Merge branch 'master' into mv/brillig_logs
vezenovm ce082b6
working println and println_format w/ brillig oracles
vezenovm 4501b69
merge conflicts w/ master
vezenovm 44ef833
fix up brillig_oracle test
vezenovm e9f6488
uncomment regression test for slice return from foreign calls in brillig
vezenovm e457faf
cargo clippy
vezenovm 7cb1b10
got structs serialized correctly without aos_to_soa
vezenovm c7e4f0a
remove dbg
vezenovm 1c64aff
working println_format
vezenovm e3d8931
merge conflicts w/ master
vezenovm 5c24bf7
cargo clippy
vezenovm f4b17d4
rename enable_slices to experimental_ssa
vezenovm d2065ea
remove dbg and fix format_field_string
vezenovm 3623283
master conflicts
vezenovm e6f5815
pr comments, and remove format work to move into separate PR
vezenovm 13f6de6
add comment about removing old println
vezenovm 2c0a8ba
remove old comment
vezenovm 20f060f
have println return nothing
vezenovm b28e598
Update crates/noirc_frontend/src/hir/def_map/mod.rs
vezenovm 1cc1c0e
Merge branch 'master' into mv/brillig_logs
vezenovm 461829a
Merge branch 'master' into mv/brillig_logs
vezenovm 46daccc
Update crates/noirc_frontend/src/hir/def_map/mod.rs
vezenovm dece385
add comment to append_abi_arg call
vezenovm 269696f
include println oracle comment in stdlib
vezenovm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| use acvm::{ | ||
| acir::brillig::{ForeignCallResult, Value}, | ||
| pwg::ForeignCallWaitInfo, | ||
| }; | ||
| use iter_extended::vecmap; | ||
| use noirc_abi::{decode_string_value, decode_value, input_parser::json::JsonTypes, AbiType}; | ||
|
|
||
| use crate::errors::ForeignCallError; | ||
|
|
||
| /// This enumeration represents the Brillig foreign calls that are natively supported by nargo. | ||
| /// After resolution of a foreign call, nargo will restart execution of the ACVM | ||
| pub(crate) enum ForeignCall { | ||
| Println, | ||
| Sequence, | ||
| ReverseSequence, | ||
| } | ||
|
|
||
| impl std::fmt::Display for ForeignCall { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| write!(f, "{}", self.name()) | ||
| } | ||
| } | ||
|
|
||
| impl ForeignCall { | ||
| pub(crate) fn name(&self) -> &'static str { | ||
| match self { | ||
| ForeignCall::Println => "println", | ||
| ForeignCall::Sequence => "get_number_sequence", | ||
| ForeignCall::ReverseSequence => "get_reverse_number_sequence", | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn lookup(op_name: &str) -> Option<ForeignCall> { | ||
| match op_name { | ||
| "println" => Some(ForeignCall::Println), | ||
| "get_number_sequence" => Some(ForeignCall::Sequence), | ||
| "get_reverse_number_sequence" => Some(ForeignCall::ReverseSequence), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn execute( | ||
| foreign_call: &ForeignCallWaitInfo, | ||
| ) -> Result<ForeignCallResult, ForeignCallError> { | ||
| let foreign_call_name = foreign_call.function.as_str(); | ||
| match Self::lookup(foreign_call_name) { | ||
| Some(ForeignCall::Println) => { | ||
| Self::execute_println(&foreign_call.inputs)?; | ||
| Ok(ForeignCallResult { values: vec![] }) | ||
| } | ||
| Some(ForeignCall::Sequence) => { | ||
| let sequence_length: u128 = foreign_call.inputs[0][0].to_field().to_u128(); | ||
|
|
||
| Ok(vecmap(0..sequence_length, Value::from).into()) | ||
| } | ||
| Some(ForeignCall::ReverseSequence) => { | ||
| let sequence_length: u128 = foreign_call.inputs[0][0].to_field().to_u128(); | ||
|
|
||
| Ok(vecmap((0..sequence_length).rev(), Value::from).into()) | ||
| } | ||
| None => panic!("unexpected foreign call {:?}", foreign_call_name), | ||
| } | ||
| } | ||
|
|
||
| fn execute_println(foreign_call_inputs: &[Vec<Value>]) -> Result<(), ForeignCallError> { | ||
| let (abi_type, input_values) = fetch_abi_type(foreign_call_inputs)?; | ||
|
|
||
| // We must use a flat map here as each value in a struct will be in a separate input value | ||
| let mut input_values_as_fields = | ||
| input_values.iter().flat_map(|values| values.iter().map(|value| value.to_field())); | ||
| let decoded_value = decode_value(&mut input_values_as_fields, &abi_type)?; | ||
|
|
||
| let json_value = JsonTypes::try_from_input_value(&decoded_value, &abi_type)?; | ||
|
|
||
| println!("{json_value}"); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Fetch the abi type from the foreign call input | ||
| /// The remaining input values should hold the values to be printed | ||
| fn fetch_abi_type( | ||
| foreign_call_inputs: &[Vec<Value>], | ||
| ) -> Result<(AbiType, &[Vec<Value>]), ForeignCallError> { | ||
| let (abi_type_as_values, input_values) = | ||
| foreign_call_inputs.split_last().ok_or(ForeignCallError::MissingForeignCallInputs)?; | ||
| let abi_type_as_fields = vecmap(abi_type_as_values, |value| value.to_field()); | ||
| let abi_type_as_string = decode_string_value(&abi_type_as_fields); | ||
| let abi_type: AbiType = serde_json::from_str(&abi_type_as_string) | ||
| .map_err(|err| ForeignCallError::InputParserError(err.into()))?; | ||
|
|
||
| Ok((abi_type, input_values)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/debug_logs/Nargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [package] | ||
| authors = [""] | ||
| compiler_version = "0.8.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/test_data_ssa_refactor/debug_logs/Prover.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| x = "5" | ||
| y = "10" |
22 changes: 22 additions & 0 deletions
22
crates/nargo_cli/tests/test_data_ssa_refactor/debug_logs/src/main.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use dep::std; | ||
|
|
||
| fn main(x : Field, y : pub Field) { | ||
|
|
||
| std::println("*** println ***"); | ||
| std::println(x); | ||
| std::println([x, y]); | ||
|
|
||
| let s = myStruct { y: x, x: y }; | ||
| let foo = fooStruct { my_struct: s, foo: 15 }; | ||
| std::println(foo); | ||
| } | ||
|
|
||
| struct myStruct { | ||
| y: Field, | ||
| x: Field, | ||
| } | ||
|
|
||
| struct fooStruct { | ||
| my_struct: myStruct, | ||
| foo: Field, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| mod json; | ||
| pub mod json; | ||
| mod toml; | ||
|
|
||
| use std::collections::BTreeMap; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.