-
Notifications
You must be signed in to change notification settings - Fork 245
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
Bigcurve trait regression #7038
Comments
My guess is that we're not properly applying the trait constraints on
|
Apparently this PR broke this: #6645 That is, once we started type-checking trait default methods. Now I'll try to understand why, because there are no default methods in the snippet above 🤔 |
I found that if the trait BigNumTrait {}
pub struct MyBigNum;
impl crate::BigNumTrait for MyBigNum {}
trait CurveParamsTrait<BigNum>
{
fn one() where BigNum: BigNumTrait;
}
pub struct BN254Params;
impl CurveParamsTrait<MyBigNum> for BN254Params {
fn one() {}
}
trait BigCurveTrait {
fn two();
}
pub struct BigCurve<BigNum, CurveParams> {}
type BN254 = BigCurve<MyBigNum, BN254Params>;
impl<BigNum, CurveParams> BigCurveTrait for BigCurve<BigNum, CurveParams>
where
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
fn two() {
let _ = CurveParams::one();
}
}
fn main() {
let _ = BN254::two();
} then we get the same error, but we also get the same error before #6645 was merged, so that PR just exposed the bug in more cases. I'm still not sure how to fix it or why it happens. I have a code change that apparently makes it work, I have an intuition about how it works but I'm not sure. I'll push it anyway to check external repos in the meantime. |
Trying to reduce the code a bit I found this code crashes (and it crashes in commit 6515e4e which is before all the trait type-checking work started): trait BigNumTrait {}
trait CurveParamsTrait<BigNum> {
fn one()
where
BigNum: BigNumTrait;
}
pub struct MyBigNum;
impl BigNumTrait for MyBigNum {}
pub struct Params;
impl CurveParamsTrait<MyBigNum> for Params {
fn one() {}
}
fn foo<C>()
where
C: CurveParamsTrait<MyBigNum>,
{
let _ = C::one();
}
fn main() {
foo::<Params>();
} This crashes with this:
It seems there's something wrong with how trait methods are solved. |
So what I'm seeing is happening in the code above is that for this call: let _ = C::one();
When popping the function context we check any trait constraints we pushed. One was pushed in point 1 so we check it. We find that |
This is a minimised (maybe not minimal) reproduction of the issue currently affecting https://github.com/noir-lang/noir_bigcurve as reported by @kashbrti.
fyi @asterite as you've been working on the trait system recently.
The text was updated successfully, but these errors were encountered: