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

fixed closure type dependencies so it does not depend on the number o… #7258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TomerStarkware
Copy link
Collaborator

…f captured variables or their order

@reviewable-StarkWare
Copy link

This change is Reviewable

@TomerStarkware TomerStarkware force-pushed the tomer/fix_closure_types_dependdencies branch from ecbef14 to 34ae46e Compare February 11, 2025 16:02
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r1.
Reviewable status: 2 of 5 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1898 at r2 (raw file):

        chain!(
            closure_type_long
                .captured_types

add a specific test that the destruct properly works.


crates/cairo-lang-lowering/src/lower/block_builder.rs line 308 at r1 (raw file):

                .iter()
                .eq(inputs.iter().map(|var_usage| &ctx.variables[var_usage.var_id].ty))
        );

should we really add this?

Code quote:

        let TypeLongId::Closure(closure_id) = expr.ty.lookup_intern(ctx.db) else {
            unreachable!("Closure Expr should have a Closure type.");
        };

        // Assert that the closure type matches the input we pass to it.
        assert!(
            closure_id
                .captured_types
                .iter()
                .eq(inputs.iter().map(|var_usage| &ctx.variables[var_usage.var_id].ty))
        );

@orizi orizi linked an issue Feb 11, 2025 that may be closed by this pull request
@ilyalesokhin-starkware
Copy link
Contributor

crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r2 (raw file):

                .captured_types
                .iter()
                .sorted_by_key(|ty| ty.as_intern_id())

I don't think this is stable

Code quote:

 ty.as_intern_id(

@ilyalesokhin-starkware
Copy link
Contributor

tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

}

fn main() {

what was the issue before this fix?

Code quote:

fn main() {

@TomerStarkware TomerStarkware force-pushed the tomer/fix_closure_types_dependdencies branch from 34ae46e to 4fa2ed9 Compare February 12, 2025 10:09
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 3 files at r3, all commit messages.
Reviewable status: 3 of 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @TomerStarkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

I don't think this is stable

It isn't - but it is consistent within an instance, and these are basically just impl bounds.


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

what was the issue before this fix?

Compiler crash.

Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-lowering/src/lower/block_builder.rs line 308 at r1 (raw file):

Previously, orizi wrote…

should we really add this?

I want some coupling between the sierra's number fo struct members, and arguments we pass to its constructor.


crates/cairo-lang-semantic/src/items/imp.rs line 1898 at r2 (raw file):

Previously, orizi wrote…

add a specific test that the destruct properly works.

Done.


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

I don't think this is stable

do we need it to be stable, its just the list of impl params


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

what was the issue before this fix?

the closure's sierra type had only one member (since captured types contained only one bytearray)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 4 files at r1, 1 of 1 files at r2, 1 of 3 files at r3.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)

Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r2 (raw file):

Previously, TomerStarkware wrote…

do we need it to be stable, its just the list of impl params

Done.


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, TomerStarkware wrote…

the closure's sierra type had only one member (since captured types contained only one bytearray)

Done.

@ilyalesokhin-starkware
Copy link
Contributor

tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, TomerStarkware wrote…

Done.

"the closure's sierra type had only one member (since captured types contained only one bytearray)"
why is that an issue?

what was the compiler crash?

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

"the closure's sierra type had only one member (since captured types contained only one bytearray)"
why is that an issue?

what was the compiler crash?

the number of parameters for the construction of the closure was wrong. (as well as their order).
so depending on the specific configuration there was a failing zip_eq or a later function specialization in sierra gen error.

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

                .captured_types
                .iter()
                .sorted_by_key(|ty| ty.as_intern_id())

can you add a todo to make this stable.

I'm worried that we would get an unstable compilation.

Code quote:

       .sorted_by_key(|ty| ty.as_intern_id())

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

can you add a todo to make this stable.

I'm worried that we would get an unstable compilation.

no need for to do - gave simple code suggestion.


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

                .captured_types
                .iter()
                .sorted_by_key(|ty| ty.as_intern_id())

a bit pricier - but always stable.

Suggestion:

                .unique()

@ilyalesokhin-starkware
Copy link
Contributor

crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, orizi wrote…

a bit pricier - but always stable.

How can it always be stable? where is the order coming from?

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @orizi)


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, orizi wrote…

the number of parameters for the construction of the closure was wrong. (as well as their order).
so depending on the specific configuration there was a failing zip_eq or a later function specialization in sierra gen error.

I was unable to reproduce the crash after reverting the other canges

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

How can it always be stable? where is the order coming from?

from the order of the capture - this is provided by the usage algorithm - we should be using an OrderedHashMap

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware)


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

I was unable to reproduce the crash after reverting the other canges

what are "the other changes"?
the crash was fixed by removing the dedup.

the readded dedup was required to make the implementation of Destruct workable (otherwise we would have had multiple Destruct implementations - therefore the additional test)

@TomerStarkware TomerStarkware force-pushed the tomer/fix_closure_types_dependdencies branch from 4fa2ed9 to 9a5b4c3 Compare February 13, 2025 08:31
Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, orizi wrote…

from the order of the capture - this is provided by the usage algorithm - we should be using an OrderedHashMap

Done.

@ilyalesokhin-starkware
Copy link
Contributor

tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, orizi wrote…

what are "the other changes"?
the crash was fixed by removing the dedup.

the readded dedup was required to make the implementation of Destruct workable (otherwise we would have had multiple Destruct implementations - therefore the additional test)

"the other changes" == changes to .rs files

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 6 files reviewed, 3 unresolved discussions (waiting on @orizi)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, TomerStarkware wrote…

Done.

Ok, makes sense.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 6 files reviewed, 4 unresolved discussions (waiting on @ilyalesokhin-starkware)


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, ilyalesokhin-starkware wrote…

"the other changes" == changes to .rs files

indeed - was missing #[test] as sierra-gen must be called for the crash.

good catch.


tests/bug_samples/issue7234.cairo line 9 at r4 (raw file):

}

fn main() {

Suggestion:

#[test]
fn main() {

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 5 of 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @TomerStarkware)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @TomerStarkware)

@TomerStarkware TomerStarkware force-pushed the tomer/fix_closure_types_dependdencies branch from 9a5b4c3 to 9cdc747 Compare February 13, 2025 09:02
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)

Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

Ok, makes sense.

Done.


crates/cairo-lang-semantic/src/items/imp.rs line 1900 at r3 (raw file):

Previously, orizi wrote…

no need for to do - gave simple code suggestion.

Done.


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, orizi wrote…

indeed - was missing #[test] as sierra-gen must be called for the crash.

good catch.

Done.

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)


tests/bug_samples/issue7234.cairo line 9 at r2 (raw file):

Previously, TomerStarkware wrote…

Done.

does not pass the ci now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Failed calculating gas usage in closure
4 participants