-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
These used to require if to work, but are forwarded to llvm intrinsics nowadays (#58003). We can now implement them as const eval intrinsics, too.
Impl instructions:
- add to
| "add_with_overflow" // ~> .overflowing_add - remove
unsafefor calls to the intrinsic - add to
| "add_with_overflow" - make functions calling the intrinsic
const fn - Implement in (implementation is basically the two
rust/src/librustc_mir/interpret/intrinsics.rs
Line 102 in 79d8a0f
| "overflowing_add" read_immediatecalls, a call tobinary_op_immwith arguments similar to the other add/sub intrinsics, in case the overflow bool in the return value is false, write the actual value to the destination like in. In case the overflow bool is true, compute the min or max value of the type like inself.write_scalar(val, dest) and write that value torust/src/librustc_mir/interpret/operator.rs
Line 217 in 79d8a0f
let max = 1 << (size.bits() - 1); dest. - Write some tests that use the saturating methods in constants
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.