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

The output of printing quoted values is hard to understand #6110

Closed
asterite opened this issue Sep 20, 2024 · 0 comments · Fixed by #6111
Closed

The output of printing quoted values is hard to understand #6110

asterite opened this issue Sep 20, 2024 · 0 comments · Fixed by #6111
Assignees
Labels
enhancement New feature or request

Comments

@asterite
Copy link
Collaborator

Problem

In comptime code when we println(q) and q is Quoted, the output is just the list of tokens separated by spaces. One usually outputs these to be able to undersand and debug what's going on, but because the code is not somehow formatted it's really hard to do. What one (at least I) end up doing is copying that output to a separate file and running nargo fmt on it (well, I let the editor do it for me) to understand things.

It would be nice if the output of that stream of tokens was somehow easier to understand.

Happy Case

The output of printing quoted values is easier to understand.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@asterite asterite added the enhancement New feature or request label Sep 20, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 20, 2024
@asterite asterite self-assigned this Sep 20, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 20, 2024
# 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.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant