You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive_via(derive_serialize)]
traitSerialize<letN: u32> {
fnserialize(self) -> [Field; N];
}
fnflatten_to_fields(name: Quoted, typ: Type) -> ([Quoted], [Quoted]) {
// ...not important, aux function that given name/type// returns a slice of flattened Fields, for example: self.a, self.b self.nested.a, self.an_array[i] // It also returns aux vars needed to generate said array// for example in case strings exist in the struct// and we need let field_as_str = str.to_bytes();
(fields, aux_vars)
}
comptimefnderive_serialize(s: StructDefinition) ->Quoted {
lettyp = s.as_type();
let (fields, aux_vars) = flatten_to_fields(quote { self }, typ);
letaux_vars_quote = ifaux_vars.len() > 0 {
letjoint = aux_vars.join(quote {;});
quote { $joint; }
} else {
quote {}
};
letfield_serializations = fields.join(quote {,});
// Here comes troubleletserialized_len = fields.len(); // Setting this to a constant doesn't work eitherquote {
implSerialize<$serialized_len> for $typ {
fnserialize(self) -> [Field; $serialized_len] {
$aux_vars_quote
[ $field_serializations ]
}
}
}
}
In the above example, serialized_len cannot be unquoted into the trait impl generic, compiler fails with
error: Failed to parse macro's token stream into an expression
┌─ src/main.nr:75:1
│
75 │ ╭ ╭ #[derive(Serialize)]
76 │ │ │ struct Smol {
77 │ │ │ a: Field,
78 │ │ │ b: Field,
79 │ │ │ }
│ ╰─│─'
│ ╰─' expected <, where or { after impl type
│
= The resulting token stream was: impl Serialize < (UnquoteMarker) > for (type) { fn serialize ( self ) -> [ Field ; (UnquoteMarker) ] { [ self . a as Field , self . b as Field ] } }
= To avoid this error in the future, try adding input validation to your macro. Erroring out early with an `assert` can be a good way to provide a user-friendly error message
Ahh, ok. So when we unquote expressions we actually usually keep them as expressions to avoid re-typechecking them and stuff. We leave little “UnquoteMarker” tokens where this happens, and these are later picked up by the parser as expressions. What is happening here is that the parser sees an UnquoteMarker in a type position and says “No, I wanted a Type, not an expression 😤.” Should be a quick fix.
To Reproduce
Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
None
Blocker Context
No response
Nargo Version
No response
NoirJS Version
No response
Proving Backend Tooling & Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered:
Thunkar
changed the title
Unquoting computed values in comptime fails in certain positions)
Unquoting computed values in comptime fails in certain positions
Sep 4, 2024
# Description
## Problem
Resolves#5916
## Summary
## Additional Context
I think there might be other `Value`s that we could convert into tokens,
like `String`, but I didn't want to handle those in this PR (should it
be `Str` or `RawStr`? etc.). And it's possible that we only need this
special logic for integers anyway.
## 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.
Aim
In the above example, serialized_len cannot be unquoted into the trait impl generic, compiler fails with
Expected Behavior
Example above should work
Bug
From a slack convo with @jfecher
To Reproduce
Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
None
Blocker Context
No response
Nargo Version
No response
NoirJS Version
No response
Proving Backend Tooling & Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: