Skip to content

Emit a multi-map of Sierra to Cairo variables in FunctionDebugInfo#9991

Open
integraledelebesgue wants to merge 1 commit into
mainfrom
debugger-annotations-v2/var-multimap
Open

Emit a multi-map of Sierra to Cairo variables in FunctionDebugInfo#9991
integraledelebesgue wants to merge 1 commit into
mainfrom
debugger-annotations-v2/var-multimap

Conversation

@integraledelebesgue

Copy link
Copy Markdown
Collaborator

Summary

Changed SerializableFunctionDebugInfo's' sierra_to_cairo_variable to sierra_to_cairo_variables, which is now populated by a vector of Cairo variables.
The mapping now includes entries for Sierra variables whose ID's are re-used, e.g. produced by store_temp or dup libfuncs.

Treat this PR as a preparation for changing the logic of reconstructing the Sierra -> Cairo variable mapping that handles every problematic case, implemented later in the stack.


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?

It allows the Cairo debugger to handle variables with re-used IDs.


What was the behavior or documentation before?


What is the behavior or documentation after?


Related issue or discussion (if any)


Additional context

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@integraledelebesgue

integraledelebesgue commented May 27, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor

cursor Bot commented Jun 2, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes serialized debugger annotation schema and debug extraction logic; incorrect mappings could confuse debugging but do not affect compilation semantics.

Overview
Function debug annotations for cairo-debugger now expose sierra_to_cairo_variables: each Sierra var id maps to a vector of Cairo names/spans, so reused ids (e.g. from store_temp / dup) can list every binding instead of a single winner.

Serialization no longer builds that map only from variables_locations. extract_serializable_debug_info takes the Sierra program and statement locations, slices each function’s statements, walks invocations, and attaches Cairo vars from source locations to libfunc branch outputs (skipping builtins). Params are aligned with Sierra params (reverse zip to skip implicits). Starknet compilation runs replace_function_ids before extraction so keys match the canonical program.

Breaking shape for consumers of the debugger annotation: field renamed from sierra_to_cairo_variable to sierra_to_cairo_variables with Vec values. A TODO notes output-to-Cairo mapping is still coarse per statement and will be refined in a follow-up.

Reviewed by Cursor Bugbot for commit caca9d7. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread crates/cairo-lang-sierra-generator/src/debug_info/function_debug_info.rs Outdated
Comment thread crates/cairo-lang-starknet/src/compile.rs Outdated
@integraledelebesgue integraledelebesgue force-pushed the debugger-annotations-v2/var-multimap branch from bda4cf2 to abd9ac1 Compare June 8, 2026 10:13
Comment thread crates/cairo-lang-sierra-generator/src/debug_info/function_debug_info.rs Outdated
@integraledelebesgue integraledelebesgue force-pushed the debugger-annotations-v2/var-multimap branch from abd9ac1 to 142b89f Compare June 8, 2026 10:53
@piotmag769 piotmag769 force-pushed the debugger-annotations-v2/var-multimap branch from 142b89f to 0890266 Compare July 3, 2026 16:59

for (sierra_param, (name, span)) in params_without_builtins {
let sierra_var = SierraVarId(sierra_param.id.id);
bindings.entry(sierra_var).or_default().push((name, span));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Param zip misaligns after drops

Medium Severity

Parameter mapping pairs Sierra and Cairo params by reverse zip, assuming equal-length suffixes after skipping builtins. get_function_params_as_cairo_variables can omit entries when span resolution fails, shortening the Cairo list without shortening Sierra params, so later Sierra parameters get incorrect names and spans in sierra_to_cairo_variables.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0890266. Configure here.

@piotmag769 piotmag769 force-pushed the debugger-annotations-v2/var-multimap branch from 0890266 to caca9d7 Compare July 5, 2026 20:53

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit caca9d7. Configure here.

let sierra_var = SierraVarId(sierra_param.id.id);
bindings.entry(sierra_var).or_default().push((name, span));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Loop functions lose param mappings

Medium Severity

Serializable debug info no longer uses variables_locations, and parameter bindings are built only when get_function_params_as_cairo_variables can cast the signature to FunctionSignature. For loop/while/for bodies lowered to recursive Sierra functions, that cast fails, so Sierra parameter variables are never added to sierra_to_cairo_variables even though they still appear in function.params.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit caca9d7. Configure here.

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.

2 participants