Skip to content

Conversation

@eytan-starkware
Copy link
Contributor

@eytan-starkware eytan-starkware commented Jan 13, 2026

Summary

Added extended versions of build_enum_match_short and build_enum_match_long functions that allow prepending instructions. The new functions build_enum_match_short_ex and build_enum_match_long_ex take an additional parameter for initial instructions and properly handle relocation offsets. The original functions were refactored to call these extended versions with empty instruction vectors.


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

Why is this change needed?

This change enables more flexibility when generating code for enum matching operations by allowing custom instructions to be prepended before the standard matching logic. This is particularly useful for complex enum operations that require setup code before the actual matching logic.


What was the behavior or documentation before?

Previously, the enum matching functions could only generate a fixed set of instructions without the ability to prepend custom setup instructions.


What is the behavior or documentation after?

Now, there are extended versions of the enum matching functions that accept an additional parameter for initial instructions. The original functions remain unchanged in behavior but internally call the new extended versions.


Additional context

The implementation carefully handles relocation offsets to ensure that jump targets remain correct when instructions are prepended. This change maintains backward compatibility while providing more flexibility for code generation.

Copy link
Contributor Author

eytan-starkware commented Jan 13, 2026

@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 4 comments.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @eytan-starkware, @ilyalesokhin-starkware, and @TomerStarkware).


crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 234 at r1 (raw file):

    >,
) -> Result<CompiledInvocation, InvocationError> {
    build_enum_match_short_ex(builder, variant_selector, output_expressions, vec![])

Suggestion:

    build_enum_match_short_ex(builder, variant_selector, output_expressions, Vec::with_capacity(1))

crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 247 at r1 (raw file):

) -> Result<CompiledInvocation, InvocationError> {
    let mut relocations = Vec::new();
    let relocation_offset = instructions.len();

Suggestion:

    let base_instruction_count = instructions.len();

crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 301 at r1 (raw file):

    >,
) -> Result<CompiledInvocation, InvocationError> {
    build_enum_match_long_ex(builder, variant_selector, output_expressions, vec![])

Suggestion:

    build_enum_match_long_ex(builder, variant_selector, output_expressions, , Vec::with_capacity(builder.invocation.branches.len() + 1))

crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 318 at r1 (raw file):

    });

    let relocation_offset = instructions.len();

Suggestion:

    let base_instruction_count = instructions.len();

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 254407f to 7de9b91 Compare January 13, 2026 13:10
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from f4ea7ec to 36c875a Compare January 13, 2026 13:10
Copy link
Contributor Author

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware made 4 comments.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @ilyalesokhin-starkware, @orizi, and @TomerStarkware).


crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 234 at r1 (raw file):

    >,
) -> Result<CompiledInvocation, InvocationError> {
    build_enum_match_short_ex(builder, variant_selector, output_expressions, vec![])

Done.


crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 247 at r1 (raw file):

) -> Result<CompiledInvocation, InvocationError> {
    let mut relocations = Vec::new();
    let relocation_offset = instructions.len();

Done.


crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 301 at r1 (raw file):

    >,
) -> Result<CompiledInvocation, InvocationError> {
    build_enum_match_long_ex(builder, variant_selector, output_expressions, vec![])

Done.


crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 318 at r1 (raw file):

    });

    let relocation_offset = instructions.len();

Done.

Copy link
Collaborator

@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.

:lgtm:

@TomerStarkware partially reviewed 1 file and made 1 comment.
Reviewable status: all files reviewed (commit messages unreviewed), 4 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi).

@eytan-starkware eytan-starkware changed the base branch from eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions to graphite-base/9463 January 14, 2026 12:35
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 7de9b91 to 2f62226 Compare January 14, 2026 13:18
@eytan-starkware eytan-starkware changed the base branch from graphite-base/9463 to eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions January 14, 2026 13:18
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 2f62226 to 68b0a7d Compare January 14, 2026 15:17
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from 612b112 to a0f42e0 Compare January 14, 2026 15:17
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 68b0a7d to c4c9d0f Compare January 15, 2026 13:42
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from a0f42e0 to 4e956b9 Compare January 15, 2026 13:42
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:

@orizi reviewed 1 file and all commit messages, made 1 comment, and resolved 4 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware).

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from 4e956b9 to 7b6d2af Compare January 18, 2026 13:59
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from c4c9d0f to 7638bf8 Compare January 18, 2026 13:59
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from 7b6d2af to a793aa3 Compare January 18, 2026 14:03
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 7638bf8 to 902d2d9 Compare January 18, 2026 14:03
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from a793aa3 to 2ba5194 Compare January 19, 2026 15:31
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch 2 times, most recently from 09cc3cb to dc02369 Compare January 20, 2026 11:20
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from 2ba5194 to 0e998a4 Compare January 20, 2026 11:20
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from dc02369 to 900b6c4 Compare January 20, 2026 12:08
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions branch from 0e998a4 to 442b9c0 Compare January 20, 2026 12:08
@graphite-app graphite-app bot changed the base branch from eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions to graphite-base/9463 January 20, 2026 12:58
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from 900b6c4 to b5e7058 Compare January 20, 2026 13:38
@eytan-starkware eytan-starkware changed the base branch from graphite-base/9463 to eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions January 20, 2026 13:39
@eytan-starkware eytan-starkware changed the base branch from eytan_graphite/refactored_boxed_deconstruct_signature_code_creating_reusable_functions to main January 20, 2026 15:07
SIERRA_UPDATE_MINOR_CHANGE_TAG=Refactored jump table building functions
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_refactor_build_jump_and_jump_table_to_support_prepended_instructions branch from b5e7058 to 4503ac9 Compare January 20, 2026 15:32
@eytan-starkware eytan-starkware added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit 3f3e35f Jan 20, 2026
55 checks passed
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.

5 participants