Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support literal 0 and 1 at type Bit. #914

Merged
merged 3 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions tests/issues/issue913.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
or [0,1,0,1]
and [1,0,1,1]
[0,1,0,1,1,0,1,1:Bit]
:t number`{rep=Bit}
2 : Bit
13 changes: 13 additions & 0 deletions tests/issues/issue913.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Loading module Cryptol
True
False
0x5b
number`{rep = Bit} : {n} (1 >= n) => Bit

[error] at <interactive>:1:1--1:2:
Unsolvable constraints:
• 1 >= 2
arising from
use of literal or demoted expression
at <interactive>:1:1--1:2
• Reason: It is not the case that 1 >= 2
4 changes: 4 additions & 0 deletions tests/regression/instance.cry
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ signedCmpRecord = (<$)
////////////////////////////////////////////////////////////////////////////////
// Literal

/** instance (1 >= val) => Literal val Bit */
literalBit : {val} (1 >= val) => Bit
literalBit = `val

/** instance (fin val) => Literal val Integer */
literalInteger : {val} (fin val) => Integer
literalInteger = `val
Expand Down
Loading