Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pretty print Quoted token stream (#6111)
# Description ## Problem Resolves #6110 ## Summary This should make it much easier to debug macro code. For example, compare this old output: ```noir quote { pub fn public_entrypoint ( selector : Field ) { let cdoffset = 0 ; let selector = dep :: aztec :: protocol_types :: abis :: function_selector :: FunctionSelector :: from_field ( selector ) ; if selector == (FunctionSelector { inner: 3043802001 }) { let input_calldata : [ Field ; 3 ] = calldata_copy ( 0 , 3 ) ; let input_calldata_index = 0 ; let ( inputs , input_calldata_index ) = PublicContextInputs :: from_calldata ( input_calldata , input_calldata_index ) ; let ( a , input_calldata_index ) = Field :: from_calldata ( input_calldata , input_calldata_index ) ; let return_value = set_storage_single ( inputs , a ) ; let mut return_array : [ Field ; 1 ] = [ 0 ; 1 ] ; return_value . to_calldata ( & mut return_array , 0 ) ; avm_return ( return_array ) ; } else if selector == (FunctionSelector { inner: 1695189557 }) { let input_calldata : [ Field ; 2 ] = calldata_copy ( 0 , 2 ) ; let input_calldata_index = 0 ; let ( inputs , input_calldata_index ) = PublicContextInputs :: from_calldata ( input_calldata , input_calldata_index ) ; let return_value = read_storage_single ( inputs ) ; let mut return_array : [ Field ; 1 ] = [ 0 ; 1 ] ; return_value . to_calldata ( & mut return_array , 0 ) ; avm_return ( return_array ) ; } else if selector == (FunctionSelector { inner: 1009316778 }) { let input_calldata : [ Field ; 3 ] = calldata_copy ( 0 , 3 ) ; let input_calldata_index = 0 ; let ( inputs , input_calldata_index ) = PublicContextInputs :: from_calldata ( input_calldata , input_calldata_index ) ; let ( a , input_calldata_index ) = Field :: from_calldata ( input_calldata , input_calldata_index ) ; let return_value = set_read_storage_single ( inputs , a ) ; let mut return_array : [ Field ; 1 ] = [ 0 ; 1 ] ; return_value . to_calldata ( & mut return_array , 0 ) ; avm_return ( return_array ) ; } else { panic ( f"Unknown selector" ) } } } ``` to this new one: ```noir quote { pub fn public_entrypoint(selector: Field) { let cdoffset = 0; let selector = dep::aztec::protocol_types::abis::function_selector::FunctionSelector::from_field(selector); if selector == (FunctionSelector { inner: 1009316778 }) { let input_calldata: [Field; 3] = calldata_copy(0, 3); let input_calldata_index = 0; let(inputs, input_calldata_index) = PublicContextInputs::from_calldata(input_calldata, input_calldata_index); let(a, input_calldata_index) = Field::from_calldata(input_calldata, input_calldata_index); let return_value = set_read_storage_single(inputs, a); let mut return_array: [Field; 1] = [0; 1]; return_value.to_calldata( & mut return_array, 0); avm_return(return_array); } else if selector == (FunctionSelector { inner: 3043802001 }) { let input_calldata: [Field; 3] = calldata_copy(0, 3); let input_calldata_index = 0; let(inputs, input_calldata_index) = PublicContextInputs::from_calldata(input_calldata, input_calldata_index); let(a, input_calldata_index) = Field::from_calldata(input_calldata, input_calldata_index); let return_value = set_storage_single(inputs, a); let mut return_array: [Field; 1] = [0; 1]; return_value.to_calldata( & mut return_array, 0); avm_return(return_array); } else if selector == (FunctionSelector { inner: 1695189557 }) { let input_calldata: [Field; 2] = calldata_copy(0, 2); let input_calldata_index = 0; let(inputs, input_calldata_index) = PublicContextInputs::from_calldata(input_calldata, input_calldata_index); let return_value = read_storage_single(inputs); let mut return_array: [Field; 1] = [0; 1]; return_value.to_calldata( & mut return_array, 0); avm_return(return_array); } else { panic(f"Unknown selector") } } } ``` ## Additional Context ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information