-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
unsafe
for calls to the intrinsic - add to
| "add_with_overflow" - make functions calling the intrinsic
const fn
- Implement in
rust/src/librustc_mir/interpret/intrinsics.rs
Line 102 in 79d8a0f
| "overflowing_add" read_immediate
calls, a call tobinary_op_imm
with 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 inself.write_scalar(val, dest) rust/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.