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

added calling expressions on closures #6192

Merged
merged 1 commit into from
Aug 18, 2024
Merged

Conversation

TomerStarkware
Copy link
Collaborator

@TomerStarkware TomerStarkware commented Aug 12, 2024

This change is Reviewable

@TomerStarkware TomerStarkware force-pushed the tomer/calling_closure branch 2 times, most recently from c643d46 to e957ee9 Compare August 12, 2024 08:51
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 3 files at r1, 1 of 2 files at r2, all commit messages.
Reviewable status: 2 of 3 files reviewed, 7 unresolved discussions (waiting on @ilyalesokhin-starkware and @TomerStarkware)


crates/cairo-lang-semantic/src/expr/compute.rs line 146 at r2 (raw file):

    cfg_set: Arc<CfgSet>,
    /// whether to look for closures when calling variables.
    /// TODO(TomerStarkware): Remove this once we disallow calling overshadowed functions.

Suggestion:

    /// whether to look for closures when calling variables.
    /// TODO(TomerStarkware): Remove this once we disallow calling shadowed functions.

crates/cairo-lang-semantic/src/expr/compute.rs line 880 at r2 (raw file):

        }
        ResolvedConcreteItem::Function(function) => {
            if is_over_shadow_by_variable {

Suggestion:

            if is_shadowed_by_variable {

crates/cairo-lang-semantic/src/expr/test_data/closure line 297 at r2 (raw file):

error: Trait has no implementation in context: core::traits::Into::<core::integer::u256, core::integer::u32>.
 --> lib.cairo:3:22
        a.into() + b.into() + c.into()

have a tests without diagnostics.

also explain why there's only one.


crates/cairo-lang-semantic/src/expr/test_data/closure line 302 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a variable.

Suggestion:

Test shadowing of a function with a variable.

crates/cairo-lang-semantic/src/expr/test_data/closure line 305 at r2 (raw file):


//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

Suggestion:

test_function_diagnostics(expect_diagnostics: warnings_only)

crates/cairo-lang-semantic/src/expr/test_data/closure line 329 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a variable when closure are in context.

Suggestion:

//! > Test shadowing a function with a variable when closure are in context.

crates/cairo-lang-semantic/src/expr/test_data/closure line 368 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a closure.

Suggestion:

//! > Test shadowing a function with a closure.

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: 2 of 3 files reviewed, 7 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-semantic/src/expr/compute.rs line 146 at r2 (raw file):

    cfg_set: Arc<CfgSet>,
    /// whether to look for closures when calling variables.
    /// TODO(TomerStarkware): Remove this once we disallow calling overshadowed functions.

Done.


crates/cairo-lang-semantic/src/expr/compute.rs line 880 at r2 (raw file):

        }
        ResolvedConcreteItem::Function(function) => {
            if is_over_shadow_by_variable {

Done.


crates/cairo-lang-semantic/src/expr/test_data/closure line 297 at r2 (raw file):

Previously, orizi wrote…

have a tests without diagnostics.

also explain why there's only one.

Done.


crates/cairo-lang-semantic/src/expr/test_data/closure line 302 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a variable.

Done.


crates/cairo-lang-semantic/src/expr/test_data/closure line 305 at r2 (raw file):


//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

Done.


crates/cairo-lang-semantic/src/expr/test_data/closure line 329 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a variable when closure are in context.

Done.


crates/cairo-lang-semantic/src/expr/test_data/closure line 368 at r2 (raw file):

//! > ==========================================================================

//! > Test overshadowing a function with a closure.

Done.

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 r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)

@ilyalesokhin-starkware
Copy link
Contributor

crates/cairo-lang-semantic/src/expr/compute.rs line 769 at r3 (raw file):

        if let Some(var) = get_variable_by_name(ctx, &variable_name, path.stable_ptr().into()) {
            is_shadowed_by_variable = true;
            if ctx.are_closures_in_context {

why is this needed? Is this an optimization?

Code quote:

if ctx.are_closures_in_context {

@ilyalesokhin-starkware
Copy link
Contributor

crates/cairo-lang-semantic/src/expr/compute.rs line 812 at r3 (raw file):

                let args_expr = Expr::Tuple(ExprTuple {
                    items: args,
                    ty: TypeLongId::Tuple(arg_types.clone()).intern(db),

why is this cloned?

Code quote:

arg_types.clone()

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: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-semantic/src/expr/compute.rs line 769 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

why is this needed? Is this an optimization?

For now we dont want to break old code which called a function that has the same name has local variable


crates/cairo-lang-semantic/src/expr/compute.rs line 812 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

why is this cloned?

removed

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 r2, 1 of 2 files at r4.
Reviewable status: 3 of 4 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)


crates/cairo-lang-semantic/src/expr/compute.rs line 769 at r3 (raw file):

Previously, TomerStarkware wrote…

For now we dont want to break old code which called a function that has the same name has local variable

can't you check the type of the variable instead of checking are_closures_in_context?

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 4 files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware and @orizi)


crates/cairo-lang-semantic/src/expr/compute.rs line 769 at r3 (raw file):

Previously, ilyalesokhin-starkware wrote…

can't you check the type of the variable instead of checking are_closures_in_context?

The type may also be var or generic.

Also, we eventually want to always look for the impl, and give an error if it is not found, this is just a workaround to not break existing code.

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: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @TomerStarkware)


ai8.txt line 1 at r4 (raw file):

0. before_all: Parameters:

?

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 4 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi)


ai8.txt line 1 at r4 (raw file):

Previously, orizi wrote…

?

reverted

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 r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware)

@TomerStarkware TomerStarkware force-pushed the tomer/fn_once_trait branch 2 times, most recently from cc09a80 to 086a183 Compare August 14, 2024 12:55
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.

:lgtm:

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

@TomerStarkware TomerStarkware changed the base branch from tomer/fn_once_trait to main August 15, 2024 07:43
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 r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @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 r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)

@TomerStarkware TomerStarkware added this pull request to the merge queue Aug 18, 2024
Merged via the queue into main with commit 6e5f2d6 Aug 18, 2024
44 checks passed
@orizi orizi deleted the tomer/calling_closure branch August 19, 2024 06:51
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.

3 participants