Sitelet https://github.com/starkware-libs/cairo/pull/10011
Skip to content

fix(starknet): respect #[cfg] when generating deploy_for_test - #10011

Merged
orizi merged 1 commit into
mainfrom
orizi/05-31-fix_starknet_respect_cfg_when_generating_deploy_for_test
May 31, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/05-31-fix_starknet_respect_cfg_when_generating_deploy_for_test

Conversation

@orizi

@orizi orizi commented May 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a #[constructor] function is annotated with #[cfg(feature: 'xyz')] and that feature is inactive, the constructor was still being picked up by generate_constructor_deploy_function and used to generate the deploy_for_test function. This happened because the body was iterated with iter_items instead of iter_items_in_cfg, ignoring cfg conditions entirely.

The fix passes the active CfgSet down to generate_constructor_deploy_function and handle_contract_impl, replacing iter_items with iter_items_in_cfg so that constructors (and impl items) behind inactive #[cfg] attributes are correctly excluded.

A new test case is added to verify that a constructor behind an inactive #[cfg(feature: 'xyz')] does not appear in the generated __constructor module or influence deploy_for_test.


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?

A constructor gated behind an inactive #[cfg] attribute was being included in the generated contract code because iter_items does not respect cfg conditions. This caused incorrect code generation — the inactive constructor's signature would influence the deploy_for_test helper, leading to a mismatch between what is actually compiled and what the test infrastructure expects.


What was the behavior or documentation before?

generate_constructor_deploy_function iterated over all module body items unconditionally, so a #[constructor] behind an inactive #[cfg] would still be treated as the contract's constructor when generating test deployment code.


What is the behavior or documentation after?

generate_constructor_deploy_function and handle_contract_impl now filter items through iter_items_in_cfg, so only constructors and impl items that are active under the current CfgSet are considered during code generation.


Related issue or discussion (if any)

N/A


Additional context

The MacroPluginMetadata argument to handle_contract_impl was narrowed to just &CfgSet since that is the only field used, which also makes the dependency explicit.

  `generate_constructor_deploy_function` iterated with cfg-unaware `iter_items`, while the
  main contract loop uses `iter_items_in_cfg`. A constructor behind an inactive #[cfg(...)]
  was correctly dropped as an entry point but still used to synthesize `deploy_for_test`,
  producing a test helper with parameters from a constructor that doesn't exist in the build.

  Thread `cfg_set` into the deploy generation and iterate cfg-aware, matching the main and
  impl loops.

  Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented May 31, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review May 31, 2026 08:15
@cursor

cursor Bot commented May 31, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Targeted plugin codegen fix with a regression test; no runtime auth or on-chain behavior changes beyond aligning generated test helpers with cfg-filtered sources.

Overview
The Starknet contract plugin now filters module and impl items through the active CfgSet when picking constructors for test deploy_for_test generation and when walking contract impl bodies, replacing unconditional iter_items so items behind inactive #[cfg] are ignored.

handle_contract_impl takes &CfgSet instead of full plugin metadata so cfg usage is explicit. A contract expansion test asserts that a #[constructor] under an inactive #[cfg(feature: 'xyz')] does not populate __constructor or shape deploy_for_test.

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

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi added this pull request to the merge queue May 31, 2026
Merged via the queue into main with commit 4749099 May 31, 2026
54 checks passed
@orizi
orizi deleted the orizi/05-31-fix_starknet_respect_cfg_when_generating_deploy_for_test branch May 31, 2026 08:46
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