Skip to content

Commit 5f817f7

Browse files
committed
Removed Tys from #applyBinOp
1 parent 66a4864 commit 5f817f7

File tree

1 file changed

+19
-20
lines changed
  • kmir/src/kmir/kdist/mir-semantics/rt

1 file changed

+19
-20
lines changed

kmir/src/kmir/kdist/mir-semantics/rt/data.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ These operations only read a single operand.
746746

747747
#### Arithmetic
748748

749-
The arithmetic operations require operands of the same numeric type.
749+
The arithmetic operations require operands of the same numeric type, however these rules assume the `Ty`s
750+
are correct.
750751

751752
| `BinOp` | | Operands can be |
752753
|-------------------|--------------------------------------- |-----------------|-------------------------------------- |
@@ -788,21 +789,20 @@ The arithmetic operations require operands of the same numeric type.
788789
// operation undefined otherwise
789790
790791
// error cases for isArithmetic(BOP):
791-
// * arguments must have the same type (TY match)
792792
// * arguments must be Numbers
793793
794794
// Checked operations return a pair of the truncated value and an overflow flag
795795
// signed numbers: must check for wrap-around (operation specific)
796796
rule #applyBinOp(
797797
BOP,
798-
typedValue(Integer(ARG1, WIDTH, true), TY, _), //signed
799-
typedValue(Integer(ARG2, WIDTH, true), TY, _),
798+
typedValue(Integer(ARG1, WIDTH, true), _, _), //signed
799+
typedValue(Integer(ARG2, WIDTH, true), _, _),
800800
true) // checked
801801
=>
802802
typedValue(
803803
Aggregate(
804804
variantIdx(0),
805-
ListItem(typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Signed), WIDTH, true), TY, mutabilityNot))
805+
ListItem(typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Signed), WIDTH, true), TyUnknown, mutabilityNot))
806806
ListItem(
807807
typedValue(
808808
BoolVal(
@@ -823,14 +823,14 @@ The arithmetic operations require operands of the same numeric type.
823823
// unsigned numbers: simple overflow check using a bit mask
824824
rule #applyBinOp(
825825
BOP,
826-
typedValue(Integer(ARG1, WIDTH, false), TY, _), // unsigned
827-
typedValue(Integer(ARG2, WIDTH, false), TY, _),
826+
typedValue(Integer(ARG1, WIDTH, false), _, _), // unsigned
827+
typedValue(Integer(ARG2, WIDTH, false), _, _),
828828
true) // checked
829829
=>
830830
typedValue(
831831
Aggregate(
832832
variantIdx(0),
833-
ListItem(typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Unsigned), WIDTH, false), TY, mutabilityNot))
833+
ListItem(typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Unsigned), WIDTH, false), TyUnknown, mutabilityNot))
834834
ListItem(
835835
typedValue(
836836
BoolVal(
@@ -852,10 +852,10 @@ The arithmetic operations require operands of the same numeric type.
852852
853853
rule #applyBinOp(
854854
BOP,
855-
typedValue(Integer(ARG1, WIDTH, true), TY, _), // signed
856-
typedValue(Integer(ARG2, WIDTH, true), TY, _),
855+
typedValue(Integer(ARG1, WIDTH, true), _, _), // signed
856+
typedValue(Integer(ARG2, WIDTH, true), _, _),
857857
false) // unchecked
858-
=> typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Signed), WIDTH, true), TY, mutabilityNot)
858+
=> typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Signed), WIDTH, true), TyUnknown, mutabilityNot)
859859
requires isArithmetic(BOP)
860860
// infinite precision result must equal truncated result
861861
andBool truncate(onInt(BOP, ARG1, ARG2), WIDTH, Signed) ==Int onInt(BOP, ARG1, ARG2)
@@ -864,10 +864,10 @@ The arithmetic operations require operands of the same numeric type.
864864
// unsigned numbers: simple overflow check using a bit mask
865865
rule #applyBinOp(
866866
BOP,
867-
typedValue(Integer(ARG1, WIDTH, false), TY, _), // unsigned
868-
typedValue(Integer(ARG2, WIDTH, false), TY, _),
867+
typedValue(Integer(ARG1, WIDTH, false), _, _), // unsigned
868+
typedValue(Integer(ARG2, WIDTH, false), _, _),
869869
false) // unchecked
870-
=> typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Unsigned), WIDTH, false), TY, mutabilityNot)
870+
=> typedValue(Integer(truncate(onInt(BOP, ARG1, ARG2), WIDTH, Unsigned), WIDTH, false), TyUnknown, mutabilityNot)
871871
requires isArithmetic(BOP)
872872
// infinite precision result must equal truncated result
873873
andBool truncate(onInt(BOP, ARG1, ARG2), WIDTH, Unsigned) ==Int onInt(BOP, ARG1, ARG2)
@@ -878,7 +878,7 @@ The arithmetic operations require operands of the same numeric type.
878878

879879
Comparison operations can be applied to all integral types and to boolean values (where `false < true`).
880880
All operations except `binOpCmp` return a `BoolVal`.
881-
The argument types must be the same for all comparison operations.
881+
The argument types must be the same for all comparison operations, however this is not checked by the rules.
882882

883883
```k
884884
syntax Bool ::= isComparison(BinOp) [function, total]
@@ -909,16 +909,15 @@ The argument types must be the same for all comparison operations.
909909
rule cmpOpBool(binOpGt, X, Y) => cmpOpBool(binOpLt, Y, X)
910910
911911
// error cases for isComparison and binOpCmp:
912-
// * arguments must have the same type
913912
// * arguments must be numbers or Bool
914913
915-
rule #applyBinOp(OP, typedValue(Integer(VAL1, WIDTH, SIGN), TY, _), typedValue(Integer(VAL2, WIDTH, SIGN), TY, _), _)
914+
rule #applyBinOp(OP, typedValue(Integer(VAL1, WIDTH, SIGN), _, _), typedValue(Integer(VAL2, WIDTH, SIGN), _, _), _)
916915
=>
917916
typedValue(BoolVal(cmpOpInt(OP, VAL1, VAL2)), TyUnknown, mutabilityNot)
918917
requires isComparison(OP)
919918
[preserves-definedness] // OP known to be a comparison
920919
921-
rule #applyBinOp(OP, typedValue(BoolVal(VAL1), TY, _), typedValue(BoolVal(VAL2), TY, _), _)
920+
rule #applyBinOp(OP, typedValue(BoolVal(VAL1), _, _), typedValue(BoolVal(VAL2), _, _), _)
922921
=>
923922
typedValue(BoolVal(cmpOpBool(OP, VAL1, VAL2)), TyUnknown, mutabilityNot)
924923
requires isComparison(OP)
@@ -938,11 +937,11 @@ The `binOpCmp` operation returns `-1`, `0`, or `+1` (the behaviour of Rust's `st
938937
rule cmpBool(X, Y) => 0 requires X ==Bool Y
939938
rule cmpBool(X, Y) => 1 requires X andBool notBool Y
940939
941-
rule #applyBinOp(binOpCmp, typedValue(Integer(VAL1, WIDTH, SIGN), TY, _), typedValue(Integer(VAL2, WIDTH, SIGN), TY, _), _)
940+
rule #applyBinOp(binOpCmp, typedValue(Integer(VAL1, WIDTH, SIGN), _, _), typedValue(Integer(VAL2, WIDTH, SIGN), _, _), _)
942941
=>
943942
typedValue(Integer(cmpInt(VAL1, VAL2), 8, true), TyUnknown, mutabilityNot)
944943
945-
rule #applyBinOp(binOpCmp, typedValue(BoolVal(VAL1), TY, _), typedValue(BoolVal(VAL2), TY, _), _)
944+
rule #applyBinOp(binOpCmp, typedValue(BoolVal(VAL1), _, _), typedValue(BoolVal(VAL2), _, _), _)
946945
=>
947946
typedValue(Integer(cmpBool(VAL1, VAL2), 8, true), TyUnknown, mutabilityNot)
948947
```

0 commit comments

Comments
 (0)