-
Notifications
You must be signed in to change notification settings - Fork 220
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
Types cannot be unquoted to call static methods #6078
Comments
This can be solved with a trick Jake told me today (I needed to do something similar and I didn't want to use a fully qualified name): mod types {
struct Foo {
x: Field,
}
impl Foo {
fn static() -> Field {
3
}
}
pub comptime fn add_static_call(m: Module) -> Quoted {
let static_call = Foo::static;
quote {
fn call_static() -> Field {
$static_call()
}
}
}
}
use types::add_static_call;
#[add_static_call]
mod AMod {} |
I also tried doing this but it didn't work: let foo = std::meta::type_of(Foo { x: 1 });
quote {
fn call_static() -> Field {
$foo::static()
}
} The reason is that Unrelated, but I'm thinking it would be nice to be able to somehow convert a type to a But, we can also do this: struct Foo {
x: Field
}
comptime fn get_type<T>() -> Type {
let exp: T = std::mem::zeroed();
std::meta::type_of(exp)
}
fn main() {
comptime
{
let foo = get_type::<Foo>();
println(foo);
}
} |
This is true, I'm assuming @Thunkar's full example could be using a non-statically known type from user code somewhere so we'd still need this feature to do: comptime fn add_static_call(m: Module, t: Type) -> Quoted {
quote {
fn call_static() -> Field {
$t::static()
}
}
} So I'm working on this issue since we should also support this usecase |
I don't know how you are going to implement this, but some weeks ago I wanted to implement being able to do |
# Description ## Problem\* Resolves #6078 ## Summary\* Adds the ability to do `Type::method` where `Type` is a primitive type or interned type. Other named types should already be supported by existing paths. ## Additional Context I also made a small update to `lookup_method` to support looking up methods without a `self` parameter to allow for us to possibly have something like `Field::static_method()` in the future, although we have no functions like this in the stdlib currently. ## 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.
Requires noir sync and noir-lang/noir#6078 to be merged so `compute_note_hash_and_optionally_a_nullifier` can be autogenerated. Also, fixed a lot of explicit numeric generics, used arithmetics on them (yay!!) and introduced a macro for partial notes --------- Co-authored-by: TomAFrench <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> Co-authored-by: benesjan <janbenes1234@gmail.com> Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com> Co-authored-by: Ary Borenszweig <asterite@gmail.com>
# Description Only blocked by #6078 ![image](https://github.com/user-attachments/assets/b117f8da-f32a-45ec-b3f8-a6028e7e1d40) Hope I didn't miss anything ## 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.
Requires noir sync and noir-lang/noir#6078 to be merged so `compute_note_hash_and_optionally_a_nullifier` can be autogenerated. Also, fixed a lot of explicit numeric generics, used arithmetics on them (yay!!) and introduced a macro for partial notes --------- Co-authored-by: TomAFrench <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> Co-authored-by: benesjan <janbenes1234@gmail.com> Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com> Co-authored-by: Ary Borenszweig <asterite@gmail.com>
Aim
Given
Expected Behavior
The code above should compile, so that
Foo
can be used inAMod
even if it was resolved in its own mod.Bug
The compiler fails to parse the macro token stream
To Reproduce
Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
Blocker
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: