Skip to content

Commit

Permalink
Support literals 0 and 1 at type Bit (#913).
Browse files Browse the repository at this point in the history
This adds the instance rule `(1 >= n) => Literal n Bit` to the
type checker.
  • Loading branch information
Brian Huffman committed Sep 29, 2020
1 parent f048368 commit 2550a57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Cryptol/Eval/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import Cryptol.Utils.RecordMap
mkLit :: Backend sym => sym -> TValue -> Integer -> SEval sym (GenValue sym)
mkLit sym ty i =
case ty of
TVBit -> pure $ VBit (bitLit sym (i > 0))
TVInteger -> VInteger <$> integerLit sym i
TVIntMod m
| m == 0 -> evalPanic "mkLit" ["0 modulus not allowed"]
Expand Down
3 changes: 3 additions & 0 deletions src/Cryptol/TypeCheck/Solver/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ solveLiteralInst val ty
-- Literal n Error -> fails
TCon (TError _ e) _ -> Unsolvable e

-- (1 >= val) => Literal val Bit
TCon (TC TCBit) [] -> SolvedIf [ tOne >== val ]

-- (fin val) => Literal val Integer
TCon (TC TCInteger) [] -> SolvedIf [ pFin val ]

Expand Down

0 comments on commit 2550a57

Please sign in to comment.