saturating arithmetic methods don’t work in `const fn`
- Dominant language
- Rust
- Stars
- 1.7k
- Forks
- 218
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 8
Description
** Keep saturating methods evaluable during CTFE**
Replacing the per-type Fe implementations with calls to `__saturating_*` makes every `const`/array-length/other CTFE use of `saturating_add`/`sub`/`mul` hit an extern. `CtfeInterpreter::eval_extern_const_fn` only handles `__as_bytes` and `__keccak256` (`crates/hir/src/analysis/ty/ctfe.rs:1414`), so expressions like `const N: u8 = 255u8.saturating_add(1);` now regress from being foldable to `ConstEvalUnsupported`. The old bodies in `num.fe` were plain Fe code, so this is a new user-visible loss of functionality in compile-time contexts.
_Originally posted by @chatgpt-codex-connector[bot] in https://github.com/argotorg/fe/pull/1347#discussion_r2970960483_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in crates/hir/src/analysis/ty/ctfe.rs at eval_extern_const_fn and inspect how saturating_add, saturating_sub, and saturating_mul are represented after the num.fe changes referenced by PR #1347. Reproduce the u8 const example, compare it with the old num.fe bodies, and verify these methods remain CTFE-evaluable without ConstEvalUnsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100