Skip to content

Fold bounded constant frozenset operators - #10153

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fold-frozenset-constant-operators
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fold-frozenset-constant-operators

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Follow CPython 3.15.2's flowgraph dispatch to the frozenset operations for constant union, intersection, difference and symmetric difference. This applies to frozensets already present in an input AST as constants, not arbitrary calls to frozenset().

Use the compiler's existing set-element comparisons and keep the same typed representatives as the runtime (for example, intersecting equal-size sets selects the right member). Defer NaN-bearing constants, unsupported members and expensive collections to the existing runtime path. No change to VM set operations or Ruff.

Verification

  • 24 bounded CPython 3.15.2 cases now agree on folding and result element types, including equal bool/int/float representatives, signed zero, and tuple members. Main deferred all 24.
  • All 801 codegen unit tests, codegen Clippy, five selected standard frozenset tests, and the existing disassembly snippet with the added regression passed on Linux.
  • Eight benign NaN-bearing controls retain the baseline runtime path and results. Object identity parity for NaN members is out of scope.
  • Full workspace, C API, non-Linux platforms and performance were not tested locally.

Related to #9852.

AI assistance: Codex (GPT-6.2) compared CPython sources, implemented the change and tests, and ran verification.

Assisted-by: Codex:GPT-6.2
@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant