@@ -746,7 +746,8 @@ These operations only read a single operand.
746
746
747
747
#### Arithmetic
748
748
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.
750
751
751
752
| ` BinOp ` | | Operands can be |
752
753
| -------------------| --------------------------------------- | -----------------| -------------------------------------- |
@@ -788,21 +789,20 @@ The arithmetic operations require operands of the same numeric type.
788
789
// operation undefined otherwise
789
790
790
791
// error cases for isArithmetic(BOP):
791
- // * arguments must have the same type (TY match)
792
792
// * arguments must be Numbers
793
793
794
794
// Checked operations return a pair of the truncated value and an overflow flag
795
795
// signed numbers: must check for wrap-around (operation specific)
796
796
rule #applyBinOp(
797
797
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), _ , _),
800
800
true) // checked
801
801
=>
802
802
typedValue(
803
803
Aggregate(
804
804
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))
806
806
ListItem(
807
807
typedValue(
808
808
BoolVal(
@@ -823,14 +823,14 @@ The arithmetic operations require operands of the same numeric type.
823
823
// unsigned numbers: simple overflow check using a bit mask
824
824
rule #applyBinOp(
825
825
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), _ , _),
828
828
true) // checked
829
829
=>
830
830
typedValue(
831
831
Aggregate(
832
832
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))
834
834
ListItem(
835
835
typedValue(
836
836
BoolVal(
@@ -852,10 +852,10 @@ The arithmetic operations require operands of the same numeric type.
852
852
853
853
rule #applyBinOp(
854
854
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), _ , _),
857
857
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)
859
859
requires isArithmetic(BOP)
860
860
// infinite precision result must equal truncated result
861
861
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.
864
864
// unsigned numbers: simple overflow check using a bit mask
865
865
rule #applyBinOp(
866
866
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), _ , _),
869
869
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)
871
871
requires isArithmetic(BOP)
872
872
// infinite precision result must equal truncated result
873
873
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.
878
878
879
879
Comparison operations can be applied to all integral types and to boolean values (where ` false < true ` ).
880
880
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 .
882
882
883
883
``` k
884
884
syntax Bool ::= isComparison(BinOp) [function, total]
@@ -909,16 +909,15 @@ The argument types must be the same for all comparison operations.
909
909
rule cmpOpBool(binOpGt, X, Y) => cmpOpBool(binOpLt, Y, X)
910
910
911
911
// error cases for isComparison and binOpCmp:
912
- // * arguments must have the same type
913
912
// * arguments must be numbers or Bool
914
913
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), _ , _), _)
916
915
=>
917
916
typedValue(BoolVal(cmpOpInt(OP, VAL1, VAL2)), TyUnknown, mutabilityNot)
918
917
requires isComparison(OP)
919
918
[preserves-definedness] // OP known to be a comparison
920
919
921
- rule #applyBinOp(OP, typedValue(BoolVal(VAL1), TY , _), typedValue(BoolVal(VAL2), TY , _), _)
920
+ rule #applyBinOp(OP, typedValue(BoolVal(VAL1), _ , _), typedValue(BoolVal(VAL2), _ , _), _)
922
921
=>
923
922
typedValue(BoolVal(cmpOpBool(OP, VAL1, VAL2)), TyUnknown, mutabilityNot)
924
923
requires isComparison(OP)
@@ -938,11 +937,11 @@ The `binOpCmp` operation returns `-1`, `0`, or `+1` (the behaviour of Rust's `st
938
937
rule cmpBool(X, Y) => 0 requires X ==Bool Y
939
938
rule cmpBool(X, Y) => 1 requires X andBool notBool Y
940
939
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), _ , _), _)
942
941
=>
943
942
typedValue(Integer(cmpInt(VAL1, VAL2), 8, true), TyUnknown, mutabilityNot)
944
943
945
- rule #applyBinOp(binOpCmp, typedValue(BoolVal(VAL1), TY , _), typedValue(BoolVal(VAL2), TY , _), _)
944
+ rule #applyBinOp(binOpCmp, typedValue(BoolVal(VAL1), _ , _), typedValue(BoolVal(VAL2), _ , _), _)
946
945
=>
947
946
typedValue(Integer(cmpBool(VAL1, VAL2), 8, true), TyUnknown, mutabilityNot)
948
947
```
0 commit comments