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

fix(semantic): evaluate const !, &, |, ^ on bool operands - #10212

Merged
orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_evaluate_const_on_bool_operands
Jul 19, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_evaluate_const_on_bool_operands

Conversation

@orizi

@orizi orizi commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds support for evaluating bool bitwise operations (&, |, ^) at compile time in constant expressions. The not_fn handling is also refactored to sit alongside the new bitwise operations under a shared guard that ensures all arguments are valid boolean constants.


Type of change

Please check one:

  • New feature

Why is this change needed?

Previously, constant expressions involving boolean bitwise operations (&, |, ^) were not evaluated at compile time, causing them to fail or be rejected in const contexts. Only ! (not), ==, and != were handled.


What was the behavior or documentation before?

Boolean bitwise operations such as true & false, true | false, and true ^ false could not be used in const declarations.


What is the behavior or documentation after?

const declarations can now use boolean bitwise operations. For example:

const AND: bool = true & false;
const OR: bool = true | false;
const XOR: bool = true ^ false;

These are correctly evaluated at compile time to false, true, and true respectively.


Related issue or discussion (if any)


Additional context

A new test test_const_bool_bitwise is added to const_test.cairo to verify the correct compile-time evaluation of all three boolean bitwise operations.

Const bitwise ops on bool operands (`ConstValue::Enum`) fell through to the
numeric path, where `NumericArg::try_new` rejects them, dropping the value to
`Missing` and surfacing later as a sierra-generation ICE. Handle bool operands
directly alongside the existing `eq`/`ne` cases: `not`, `bitand`, `bitor`,
`bitxor`. Integer operands still take the numeric path.
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jul 18, 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 July 18, 2026 13:17
@cursor

cursor Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Small, localized change to const-expression evaluation in the semantic layer; covered by a new test and does not touch runtime or security-sensitive paths.

Overview
Extends compile-time constant evaluation so boolean &, |, and ^ fold to true/false in const expressions, matching behavior that already existed for ==, !=, and (partially) !.

In constant.rs, not is grouped with the new bitwise cases behind a guard that requires every argument to be the compiler’s true/false const values; those ops are evaluated with Rust bool logic and returned as bool constants. Integer bitwise &/|/^ still use the existing numeric path when operands are not bool constants.

Adds test_const_bool_bitwise in const_test.cairo to assert true & false, true | false, and true ^ false evaluate correctly at compile time.

Reviewed by Cursor Bugbot for commit f84e76a. 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 Jul 19, 2026
Merged via the queue into main with commit 7bca806 Jul 19, 2026
55 checks passed
@orizi
orizi deleted the orizi/07-18-fix_semantic_evaluate_const_on_bool_operands branch July 19, 2026 16:13
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