Skip to content

Conversation

@cburgdorf
Copy link
Collaborator

@cburgdorf cburgdorf commented Jan 20, 2026

  • Implement checked arithmetic for integer operations, making overflow/underflow revert by default at runtime
  • Add compile-time detection for const expressions that would overflow
  • Extend the core num library with explicit wrapping_* and saturating_* methods for cases where non-reverting behavior is desired
  • Add #[test(should_revert)] test attribute to enable testing that code correctly reverts under expected conditions

@cburgdorf cburgdorf force-pushed the checked_arithmetic branch 3 times, most recently from d3bec03 to ae5a7a3 Compare January 21, 2026 16:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements checked arithmetic for integer operations in the Fe programming language. The changes make integer overflow and underflow cause runtime reverts by default, add compile-time detection for const expressions that would overflow, introduce explicit wrapping_* and saturating_* methods for non-reverting behavior, and add a #[test(should_revert)] attribute for testing revert conditions.

Changes:

  • Default arithmetic operations now check for overflow/underflow and revert on detection
  • Added wrapping_* and saturating_* trait methods for explicit overflow handling semantics
  • Augmented assignment operators now return the updated value instead of unit type
  • Compile-time const evaluation validates arithmetic operations don't overflow

Reviewed changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated no comments.

Show a summary per file
File Description
library/core/src/ops.fe Added new traits for wrapping/saturating arithmetic; changed augmented assignment signatures to return Self
library/core/src/num.fe Implemented checked arithmetic for all integer types with overflow detection; added wrapping/saturating variants
crates/hir/src/analysis/ty/const_ty.rs Added compile-time checked arithmetic evaluation for const expressions
crates/hir/src/analysis/diagnostics.rs Updated error message for invalid const expressions
crates/hir/src/core/hir_def/attr.rs Added attribute helper methods for test annotations
crates/mir/src/lower/expr.rs Updated MIR lowering to handle arithmetic as trait calls
crates/mir/src/lower/intrinsics.rs Added panic detection for MIR terminating calls
crates/mir/src/lower/prepass.rs Extended prepass to handle binary/unary expressions
crates/fe/src/test.rs Added support for #[test(should_revert)] test attribute
Test files Multiple new tests and snapshot updates for checked arithmetic behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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