Skip to content

Commit 0ba9191

Browse files
committed
Separate {Add,Sub,Mul}Unchecked
1 parent c26cc9c commit 0ba9191

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

engine/lib/import_thir.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ end) : EXPR = struct
244244
(typ : ty) =
245245
let overloaded_names_of_binop : Thir.bin_op -> Concrete_ident.name =
246246
function
247-
| Add -> Core__ops__arith__Add__add
248-
| Sub -> Core__ops__arith__Sub__sub
249-
| Mul -> Core__ops__arith__Mul__mul
247+
| Add | AddUnchecked -> Core__ops__arith__Add__add
248+
| Sub | SubUnchecked -> Core__ops__arith__Sub__sub
249+
| Mul | MulUnchecked -> Core__ops__arith__Mul__mul
250250
| Div -> Core__ops__arith__Div__div
251251
| Rem -> Core__ops__arith__Rem__rem
252252
| BitXor -> Core__ops__bit__BitXor__bitxor
253253
| BitAnd -> Core__ops__bit__BitAnd__bitand
254254
| BitOr -> Core__ops__bit__BitOr__bitor
255-
| Shl -> Core__ops__bit__Shl__shl
256-
| Shr -> Core__ops__bit__Shr__shr
255+
| Shl | ShlUnchecked -> Core__ops__bit__Shl__shl
256+
| Shr | ShrUnchecked -> Core__ops__bit__Shr__shr
257257
| Lt -> Core__cmp__PartialOrd__lt
258258
| Le -> Core__cmp__PartialOrd__le
259259
| Ne -> Core__cmp__PartialEq__ne
@@ -269,16 +269,16 @@ end) : EXPR = struct
269269
| Offset -> Core__ptr__const_ptr__Impl__offset
270270
in
271271
let primitive_names_of_binop : Thir.bin_op -> Concrete_ident.name = function
272-
| Add -> Rust_primitives__u128__add
273-
| Sub -> Rust_primitives__u128__sub
274-
| Mul -> Rust_primitives__u128__mul
272+
| Add | AddUnchecked -> Rust_primitives__u128__add
273+
| Sub | SubUnchecked -> Rust_primitives__u128__sub
274+
| Mul | MulUnchecked -> Rust_primitives__u128__mul
275275
| Div -> Rust_primitives__u128__div
276276
| Rem -> Rust_primitives__u128__rem
277277
| BitXor -> Rust_primitives__u128__bit_xor
278278
| BitAnd -> Rust_primitives__u128__bit_and
279279
| BitOr -> Rust_primitives__u128__bit_or
280-
| Shl -> Rust_primitives__u128__shl
281-
| Shr -> Rust_primitives__u128__shr
280+
| Shl | ShlUnchecked -> Rust_primitives__u128__shl
281+
| Shr | ShrUnchecked -> Rust_primitives__u128__shr
282282
| Lt -> Rust_primitives__u128__lt
283283
| Le -> Rust_primitives__u128__le
284284
| Ne -> Rust_primitives__u128__ne
@@ -330,11 +330,12 @@ end) : EXPR = struct
330330
let expected, f =
331331
match op with
332332
| Add | Sub | Mul | AddWithOverflow | SubWithOverflow
333-
| MulWithOverflow | Div ->
333+
| MulWithOverflow | AddUnchecked | SubUnchecked | MulUnchecked | Div
334+
->
334335
both int <|> both float
335336
| Rem | Cmp -> both int
336337
| BitXor | BitAnd | BitOr -> both int <|> both bool
337-
| Shl | Shr -> int <*> int
338+
| Shl | Shr | ShlUnchecked | ShrUnchecked -> int <*> int
338339
| Lt | Le | Ne | Ge | Gt -> both int <|> both float
339340
| Eq -> both int <|> both float <|> both bool
340341
| Offset -> ("", fun _ -> Some "")

frontend/exporter/src/types/mir.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,35 +1034,24 @@ pub enum UnOp {
10341034
#[derive(AdtInto, Copy, Clone, Debug, JsonSchema)]
10351035
#[args(<'slt, S: UnderOwnerState<'slt>>, from: mir::BinOp, state: S as _s)]
10361036
pub enum BinOp {
1037-
// We merge the checked and unchecked variants because in either case overflow is failure.
1038-
#[custom_arm(
1039-
rustc_middle::mir::BinOp::Add | rustc_middle::mir::BinOp::AddUnchecked => BinOp::Add,
1040-
)]
10411037
Add,
1042-
#[custom_arm(
1043-
rustc_middle::mir::BinOp::Sub | rustc_middle::mir::BinOp::SubUnchecked => BinOp::Sub,
1044-
)]
1045-
Sub,
1046-
#[custom_arm(
1047-
rustc_middle::mir::BinOp::Mul | rustc_middle::mir::BinOp::MulUnchecked => BinOp::Mul,
1048-
)]
1049-
Mul,
1038+
AddUnchecked,
10501039
AddWithOverflow,
1040+
Sub,
1041+
SubUnchecked,
10511042
SubWithOverflow,
1043+
Mul,
1044+
MulUnchecked,
10521045
MulWithOverflow,
10531046
Div,
10541047
Rem,
10551048
BitXor,
10561049
BitAnd,
10571050
BitOr,
1058-
#[custom_arm(
1059-
rustc_middle::mir::BinOp::Shl | rustc_middle::mir::BinOp::ShlUnchecked => BinOp::Shl,
1060-
)]
10611051
Shl,
1062-
#[custom_arm(
1063-
rustc_middle::mir::BinOp::Shr | rustc_middle::mir::BinOp::ShrUnchecked => BinOp::Shr,
1064-
)]
1052+
ShlUnchecked,
10651053
Shr,
1054+
ShrUnchecked,
10661055
Eq,
10671056
Lt,
10681057
Le,

0 commit comments

Comments
 (0)