Skip to content

Conversation

@mattvaux
Copy link

Summary

Optimizes function_with_body_direct_function_with_body_callees by replacing collect::<Maybe<Vec<Option<_>>>>()? + flatten() with direct iteration. Processes Maybe<Option<_>> in a single pass, collecting only Some values and avoiding an intermediate vector.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

⚠️ Note:
To keep maintainer workload sustainable, we generally do not accept PRs that
are only minor wording, grammar, formatting, or style changes.
Such PRs may be closed without detailed review.


Why is this change needed?

The previous implementation created an intermediate Vec<Option<_>> with all values (including None), then filtered in a second pass. This caused unnecessary allocations and two passes over the data.


What was the behavior or documentation before?

Used collect::<Maybe<Vec<Option<_>>>>()? + flatten(), creating an intermediate vector and iterating twice.


What is the behavior or documentation after?

Uses direct iteration in a single pass, collecting only Some values directly into the result set.


Related issue or discussion (if any)


Additional context

The same pattern exists in db.rs, but this PR addresses only the confirmed issue in cycles.rs. All tests pass (62 passed).

@reviewable-StarkWare
Copy link

This change is Reviewable

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.

@orizi made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @mattvaux).


crates/cairo-lang-lowering/src/graph_algorithms/cycles.rs line 46 at r1 (raw file):

 } } Ok(result)

Suggestion:

 db.function_with_body_direct_callees(function_id, dependency_type)? .into_iter() .filter_map(|function_id| { Some(function_id.body(db).transpose()?.map(|id| match id.generic_or_specialized(db) { GenericOrSpecialized::Generic(id) => id, GenericOrSpecialized::Specialized(_) => { unreachable!("Specialization of functions only occurs post concretization.") } })) }) .collect()
@mattvaux
Copy link
Author

Fixed it

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.

@orizi made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @mattvaux).


crates/cairo-lang-lowering/src/graph_algorithms/cycles.rs line 46 at r1 (raw file):

 } } Ok(result)

i removed the extra collect - but you added it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants