Skip to content

flow-control: Add cache node optimization.#8115

Merged
liorgold2 merged 1 commit intomainfrom
pr/liorgold2/lior/flow-control/edbf06d2
Aug 10, 2025
Merged

flow-control: Add cache node optimization.#8115
liorgold2 merged 1 commit intomainfrom
pr/liorgold2/lior/flow-control/edbf06d2

Conversation

@liorgold2
Copy link
Collaborator

@liorgold2 liorgold2 commented Aug 5, 2025

@reviewable-StarkWare
Copy link

This change is Reviewable

@liorgold2 liorgold2 force-pushed the pr/liorgold2/lior/flow-control/2789b93c branch from b7ee27c to 0a909b4 Compare August 5, 2025 19:25
@liorgold2 liorgold2 force-pushed the pr/liorgold2/lior/flow-control/edbf06d2 branch from 80b3efb to 95b9ca7 Compare August 5, 2025 19:25
@liorgold2 liorgold2 requested a review from orizi August 5, 2025 19:25
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 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @liorgold2)


crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 12 at r1 (raw file):

/// identically.
pub struct Cache<Input> {
    cache: RefCell<UnorderedHashMap<Input, NodeId>>,

doc why refcell.

@liorgold2 liorgold2 force-pushed the pr/liorgold2/lior/flow-control/edbf06d2 branch from 95b9ca7 to b1ca544 Compare August 7, 2025 20:03
@liorgold2 liorgold2 changed the base branch from pr/liorgold2/lior/flow-control/2789b93c to main August 7, 2025 20:03
@liorgold2 liorgold2 force-pushed the pr/liorgold2/lior/flow-control/edbf06d2 branch from b1ca544 to f61aad1 Compare August 8, 2025 10:15
Copy link
Collaborator Author

@liorgold2 liorgold2 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 @orizi)


crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 12 at r1 (raw file):

Previously, orizi wrote…

doc why refcell.

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.

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


crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 15 at r2 (raw file):

    //
    // The cache is wrapped in a `RefCell` to allow modifying it without holding a `&mut` to it
    // (which would complicate its usage).

Suggestion:

    /// A map from input to the cached result.
    ///
    /// The cache is wrapped in a `RefCell` to allow modifying it without holding a `&mut` to it
    /// (which would complicate its usage).

crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 15 at r2 (raw file):

    //
    // The cache is wrapped in a `RefCell` to allow modifying it without holding a `&mut` to it
    // (which would complicate its usage).

this is pretty much the definition of a refcell - why is this specifically more difficult?
i now understand - it is since it is a cache - and not an explicitly built mapper - so you consider caching as a non-mutating action. (i think i'd rather see something similar to this line)

but couldn't you just make it a mut fn?
you have it as a local variable in both usecases.

Code quote:

    // The cache is wrapped in a `RefCell` to allow modifying it without holding a `&mut` to it
    // (which would complicate its usage).

Copy link
Collaborator Author

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


crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 15 at r2 (raw file):

Previously, orizi wrote…

this is pretty much the definition of a refcell - why is this specifically more difficult?
i now understand - it is since it is a cache - and not an explicitly built mapper - so you consider caching as a non-mutating action. (i think i'd rather see something similar to this line)

but couldn't you just make it a mut fn?
you have it as a local variable in both usecases.

Nice, works :)


crates/cairo-lang-lowering/src/lower/flow_control/create_graph/cache.rs line 15 at r2 (raw file):

    //
    // The cache is wrapped in a `RefCell` to allow modifying it without holding a `&mut` to it
    // (which would complicate its usage).

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

@liorgold2 liorgold2 added this pull request to the merge queue Aug 10, 2025
Merged via the queue into main with commit dc7939f Aug 10, 2025
49 checks passed
@orizi orizi deleted the pr/liorgold2/lior/flow-control/edbf06d2 branch August 10, 2025 11:04
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