rust/compiler/rustc_const_eval/src/interpret
Matthias Krüger cea6ba7a06
Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung
Make algebraic functions into `const fn` items.

Tracking issue: #136469

This PR makes the algebraic intrinsics and the unstable, algebraic functions of `f16`, `f32`, `f64`, and `f128` into `const fn` items:

```rust
impl f16 {
    pub const fn algebraic_add(self, rhs: f16) -> f16;
    pub const fn algebraic_sub(self, rhs: f16) -> f16;
    pub const fn algebraic_mul(self, rhs: f16) -> f16;
    pub const fn algebraic_div(self, rhs: f16) -> f16;
    pub const fn algebraic_rem(self, rhs: f16) -> f16;
}

impl f32 {
    pub const fn algebraic_add(self, rhs: f32) -> f32;
    pub const fn algebraic_sub(self, rhs: f32) -> f32;
    pub const fn algebraic_mul(self, rhs: f32) -> f32;
    pub const fn algebraic_div(self, rhs: f32) -> f32;
    pub const fn algebraic_rem(self, rhs: f32) -> f32;
}

impl f64 {
    pub const fn algebraic_add(self, rhs: f64) -> f64;
    pub const fn algebraic_sub(self, rhs: f64) -> f64;
    pub const fn algebraic_mul(self, rhs: f64) -> f64;
    pub const fn algebraic_div(self, rhs: f64) -> f64;
    pub const fn algebraic_rem(self, rhs: f64) -> f64;
}

impl f128 {
    pub const fn algebraic_add(self, rhs: f128) -> f128;
    pub const fn algebraic_sub(self, rhs: f128) -> f128;
    pub const fn algebraic_mul(self, rhs: f128) -> f128;
    pub const fn algebraic_div(self, rhs: f128) -> f128;
    pub const fn algebraic_rem(self, rhs: f128) -> f128;
}

// core::intrinsics

pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
```

This PR does not preserve the initial behaviour of these functions yielding non-deterministic output under Miri; it is most likely desired to reimplement this behaviour at some point.
2025-04-24 17:19:46 +02:00
..
call.rs add a doc comment 2025-02-15 08:21:27 +01:00
cast.rs Stop relying on rustc_type_ir in non-type-system crates 2025-03-15 06:42:48 +00:00
discriminant.rs make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00
eval_context.rs Change function visibility to pub 2025-04-17 16:23:44 +02:00
intern.rs intern_with_temp_alloc is for DummyMachine only. 2025-04-17 13:08:31 +10:00
intrinsics.rs Make algebraic intrinsics into 'const fn' items; Make algebraic functions of 'f16', 'f32', 'f64', and 'f128' into 'const fn' items; 2025-04-23 08:54:52 +02:00
machine.rs interpret memory access hooks: also pass through the Pointer used for the access 2025-03-20 17:00:45 +01:00
memory.rs add comment for "Other" case 2025-04-22 11:40:48 +02:00
mod.rs make return type of get_alloc_info a struct, and reduce some code duplication with validity checking 2024-11-09 15:18:52 +01:00
operand.rs Remove BackendRepr::Uninhabited, replaced with an uninhabited: bool field in LayoutData. 2025-02-20 13:27:32 -06:00
operator.rs Contracts core intrinsics. 2025-02-03 12:53:57 -08:00
place.rs miri: optimize zeroed alloc 2025-01-28 12:50:02 +01:00
projection.rs Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
stack.rs Shorten span of panic failures in const context 2025-02-28 16:28:41 +00:00
step.rs minor interpret cleanups 2025-03-12 18:35:40 +01:00
traits.rs interpret: adjust vtable validity check for higher-ranked types 2025-01-31 17:43:28 +01:00
util.rs fix ensure_monomorphic_enough 2025-02-11 01:15:08 +01:00
validity.rs interpret: add a version of run_for_validation for &self 2025-04-01 15:11:10 +02:00
visitor.rs make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00