@@ -1015,10 +1015,9 @@ The `getTyOf` helper applies the projections from the `Place` to determine the `
10151015 syntax Evaluation ::= #discriminant ( Evaluation , MaybeTy ) [strict(1)]
10161016 // ----------------------------------------------------------------
10171017 rule <k> #discriminant(Aggregate(IDX, _), TY:Ty)
1018- => Integer(#lookupDiscriminant(lookupTy(TY), IDX), #discriminantSize(lookupTy(TY)) , false)
1018+ => Integer(#lookupDiscriminant(lookupTy(TY), IDX), 0 , false) // HACK: bit width 0 means "flexible"
10191019 ...
10201020 </k>
1021- requires #discriminantSize(lookupTy(TY)) =/=Int 0
10221021
10231022 syntax Int ::= #lookupDiscriminant ( TypeInfo , VariantIdx ) [function, total]
10241023 | #lookupDiscrAux ( Discriminants , Int ) [function]
@@ -1029,27 +1028,6 @@ The `getTyOf` helper applies the projections from the `Place` to determine the `
10291028 // --------------------------------------------------------------------
10301029 rule #lookupDiscrAux( discriminant(RESULT) _ , IDX) => RESULT requires IDX ==Int 0
10311030 rule #lookupDiscrAux( _:Discriminant MORE:Discriminants, IDX) => #lookupDiscrAux(MORE, IDX -Int 1) requires 0 <Int IDX [owise]
1032-
1033- syntax Int ::= #discriminantSize ( TypeInfo ) [function, total]
1034- | #discriminantSize ( LayoutShape ) [function, total]
1035- | #discriminantSize ( Scalar ) [function, total]
1036- | #intLength (IntegerLength) [function, total]
1037- // ------------------------------------------------------------
1038- rule #discriminantSize(typeInfoEnumType(_, _, _, _, someLayoutShape(LAYOUT))) => #discriminantSize(LAYOUT)
1039- rule #discriminantSize(_OTHER_TYPE:TypeInfo) => 0 [owise]
1040-
1041- rule #discriminantSize(layoutShape(_, variantsShapeMultiple(mk(TAG, _, _, _)), _, _, _)) => #discriminantSize(TAG)
1042- rule #discriminantSize(_OTHER:LayoutShape) => 0 [owise]
1043-
1044- rule #discriminantSize(scalarInitialized(mk(primitiveInt(mk(INTLENGTH, _SIGNED)), _VALIDRANGE))) => #intLength(INTLENGTH)
1045- rule #discriminantSize(scalarInitialized(mk(primitivePointer(_) , _VALIDRANGE))) => 64 // pointer size assumed 64 bit
1046- rule #discriminantSize(_OTHER:Scalar) => 0 [owise]
1047-
1048- rule #intLength(integerLengthI8) => 8
1049- rule #intLength(integerLengthI16) => 16
1050- rule #intLength(integerLengthI32) => 32
1051- rule #intLength(integerLengthI64) => 64
1052- rule #intLength(integerLengthI128) => 128
10531031```
10541032
10551033``` k
@@ -1422,7 +1400,7 @@ If none of the `enum` variants has any fields, the `Transmute` of a number to th
14221400 rule <k> #discriminant(
14231401 thunk(#cast (Integer(DATA, _, false), castKindTransmute, _, TY)),
14241402 TY
1425- ) => Integer(DATA, #discriminantSize(lookupTy(TY)) , false)
1403+ ) => Integer(DATA, 0 , false) // HACK: bit width 0 means "flexible"
14261404 ...
14271405 </k>
14281406 requires #isEnumWithoutFields(lookupTy(TY))
@@ -1705,14 +1683,27 @@ The argument types must be the same for all comparison operations, however this
17051683 rule #applyBinOp(OP, Integer(VAL1, WIDTH, SIGN), Integer(VAL2, WIDTH, SIGN), _)
17061684 =>
17071685 BoolVal(cmpOpInt(OP, VAL1, VAL2))
1686+ requires isComparison(OP)
1687+ andBool WIDTH =/=Int 0
1688+ [preserves-definedness] // OP known to be a comparison
1689+
1690+ // HACK: accept bit width 0 in comparisons (coming from discriminants)
1691+ rule #applyBinOp(OP, Integer(VAL1, 0, false), Integer(VAL2, _WIDTH, _SIGN), _)
1692+ =>
1693+ BoolVal(cmpOpInt(OP, VAL1, VAL2))
1694+ requires isComparison(OP)
1695+ [priority(55), preserves-definedness] // OP known to be a comparison
1696+ rule #applyBinOp(OP, Integer(VAL1, _WIDTH, _SIGN_), Integer(VAL2, 0, false), _)
1697+ =>
1698+ BoolVal(cmpOpInt(OP, VAL1, VAL2))
17081699 requires isComparison(OP)
17091700 [preserves-definedness] // OP known to be a comparison
17101701
17111702 rule #applyBinOp(OP, BoolVal(VAL1), BoolVal(VAL2), _)
17121703 =>
17131704 BoolVal(cmpOpBool(OP, VAL1, VAL2))
17141705 requires isComparison(OP)
1715- [preserves-definedness] // OP known to be a comparison
1706+ [priority(60), preserves-definedness] // OP known to be a comparison
17161707```
17171708
17181709The ` binOpCmp ` operation returns ` -1 ` , ` 0 ` , or ` +1 ` (the behaviour of Rust's ` std::cmp::Ordering as i8 ` ), indicating ` LE ` , ` EQ ` , or ` GT ` .
0 commit comments