argotorg / argotorg/fe

saturating arithmetic methods don’t work in `const fn`

Open
#1,349 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.7k
Forks
218
Avg merge
1d 4h
Merged PRs (30d)
8

Description

**![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat) 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.