Change the defaulting rules for Literal constraints.

Instead of defaulting to `[n]` for some `n`, prefer instead
to default to `Integer` or `Rational` depending on the
other required constraints.
This commit is contained in:
Rob Dockins 2020-06-19 14:27:53 -07:00
parent 233830243a
commit 709dc939ed
28 changed files with 88 additions and 85 deletions

View File

@ -4,7 +4,7 @@ import qualified Data.Set as Set
import qualified Data.Map as Map
import Data.Maybe(mapMaybe)
import Data.List((\\),nub)
import Control.Monad(guard)
import Control.Monad(guard,mzero)
import Cryptol.TypeCheck.Type
import Cryptol.TypeCheck.SimpType(tMax,tWidth)
@ -17,16 +17,22 @@ import Cryptol.Utils.Panic(panic)
--------------------------------------------------------------------------------
-- | We default constraints of the form @Literal t a@ to @a := [width t]@
-- | We default constraints of the form @Literal t a@ to @a := Integer@
defaultLiterals :: [TVar] -> [Goal] -> ([TVar], Subst, [Warning])
defaultLiterals as gs = let (binds,warns) = unzip (mapMaybe tryDefVar as)
in (as \\ map fst binds, listSubst binds, warns)
where
gSet = goalsFromList gs
allProps = saturatedPropSet gSet
tryDefVar a =
do gt <- Map.lookup a (literalGoals gSet)
do _gt <- Map.lookup a (literalGoals gSet)
defT <- if Set.member (pLogic (TVar a)) allProps then
mzero
else if Set.member (pField (TVar a)) allProps then
pure tRational
else
pure tInteger
let d = tvInfo a
defT = tWord (tWidth (goal gt))
w = DefaultingTo d defT
guard (not (Set.member a (fvs defT))) -- Currently shouldn't happen
-- but future proofing.
@ -35,9 +41,6 @@ defaultLiterals as gs = let (binds,warns) = unzip (mapMaybe tryDefVar as)
return ((a,defT),w)
--------------------------------------------------------------------------------
-- This is what we use to avoid ambiguity when generalizing.

View File

@ -2,7 +2,7 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at issue323.cry:2:53--2:61:
Defaulting type argument 'a' of 'infFrom' to [0]
Defaulting type argument 'a' of 'infFrom' to Integer
[error] at issue323.cry:2:1--3:51:
Failed to validate user-specified signature.

View File

@ -1,10 +1,10 @@
Loading module Cryptol
[warning] at <interactive>:1:17--1:28:
Defaulting type argument 'e' of '(^^)' to [0]
Defaulting type argument 'e' of '(^^)' to Integer
Q.E.D.
[warning] at <interactive>:1:17--1:28:
Defaulting type argument 'e' of '(^^)' to [1]
Defaulting type argument 'e' of '(^^)' to Integer
Q.E.D.
[warning] at <interactive>:1:17--1:44:
Defaulting type argument 'e' of '(^^)' to [3]
Defaulting type argument 'e' of '(^^)' to Integer
Q.E.D.

View File

@ -1,5 +1,5 @@
Loading module Cryptol
[warning] at <interactive>:1:5--1:18:
Defaulting the type of '<interactive>::y' to [1]
0x0
0x1
Defaulting the type of '<interactive>::y' to Integer
0
1

View File

@ -2,8 +2,8 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at unary-2.cry:3:11--3:14:
Defaulting type argument 'a' of 'min' to [2]
[warning] at unary-2.cry:2:11--2:14:
Defaulting type argument 'a' of 'min' to [2]
True
Defaulting type argument 'a' of 'min' to Integer
Showing a specific instance of polymorphic result:
* Using '[2]' for type argument 'a' of 'Cryptol::min'
True
False

View File

@ -2,15 +2,15 @@ Loading module Cryptol
Loading module Cryptol
Loading module AES
[warning] at AES.cry:147:60--147:63:
Defaulting type argument 'rep' of 'number' to [4]
Defaulting type argument 'rep' of 'number' to Integer
[warning] at AES.cry:147:36--147:51:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at AES.cry:127:26--127:33:
Defaulting type argument 'rep' of 'number' to [3]
Defaulting type argument 'rep' of 'number' to Integer
[warning] at AES.cry:92:61--92:69:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at AES.cry:87:58--87:66:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
True
True
True

View File

@ -2,6 +2,6 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check01.cry:2:20--2:27:
Defaulting type of sequence member to [5]
Defaulting type of sequence member to Integer
[0x00000007, 0x00000014]
True

View File

@ -2,9 +2,9 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check02.cry:3:10--3:25:
Defaulting 1st type argument of 'Main::ones' to [1]
Defaulting 1st type argument of 'Main::ones' to Integer
[warning] at <interactive>:1:9--1:18:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for 1st type argument of 'Main::ones'
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

View File

@ -2,12 +2,12 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at <interactive>:1:11--1:22:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
[0x00000000, 0x00000001, 0x00000002, 0x00000003, 0x00000004,
0x00000005, 0x00000006, 0x00000007, 0x00000008, 0x00000009,
0x0000000a]
[warning] at <interactive>:1:12--1:23:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
[0x0000000b, 0x0000000c, 0x0000000d, 0x0000000e, 0x0000000f,
0x00000010, 0x00000011, 0x00000012, 0x00000013, 0x00000014,
0x00000015]

View File

@ -2,11 +2,11 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check04.cry:4:33--4:45:
Defaulting type of sequence member to [2]
Defaulting type of sequence member to Integer
[warning] at check04.cry:4:21--4:29:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at <interactive>:1:12--1:21:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for 1st type argument of 'Main::onetwos'
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]

View File

@ -2,11 +2,11 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check05.cry:4:33--4:45:
Defaulting type of sequence member to [2]
Defaulting type of sequence member to Integer
[warning] at check05.cry:4:21--4:29:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at <interactive>:1:12--1:21:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for 1st type argument of 'Main::twoones'
[2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]

View File

@ -2,11 +2,11 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check06.cry:5:62--5:68:
Defaulting type of sequence member to [2]
Defaulting type of sequence member to Integer
[warning] at check06.cry:5:24--5:32:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at <interactive>:1:15--1:24:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for 1st type argument of 'Main::onesytwosy'
[[1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1],

View File

@ -2,23 +2,23 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check07.cry:9:46--9:57:
Defaulting type argument 'a' of 'fromTo' to [6]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:7:43--7:54:
Defaulting type argument 'a' of 'fromTo' to [6]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:13:11--13:22:
Defaulting type argument 'n' of '(<<)' to 1
[warning] at check07.cry:11:39--11:51:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:5:37--5:49:
Defaulting type argument 'a' of 'fromTo' to [7]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:4:37--4:48:
Defaulting type argument 'a' of 'fromTo' to [6]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:3:37--3:65:
Defaulting type argument 'a' of 'fromTo' to [32]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:2:37--2:49:
Defaulting type argument 'a' of 'fromTo' to [7]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check07.cry:1:37--1:48:
Defaulting type argument 'a' of 'fromTo' to [6]
Defaulting type argument 'a' of 'fromTo' to Integer
[0b00010010001101000101011001111000,
0b00100100011010001010110011110000,
0b01001000110100010101100111100000,

View File

@ -2,11 +2,11 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check08.cry:9:25--9:33:
Defaulting type argument 'a' of 'fromTo' to [3]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check08.cry:7:16--7:24:
Defaulting type argument 'a' of 'fromTo' to [3]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at <interactive>:1:7--1:15:
Defaulting type argument 'a' of 'fromTo' to [3]
Defaulting type argument 'a' of 'fromTo' to Integer
[0x00000001, 0x00000002, 0x00000005, 0x0000000c, 0x0000001b]
True
Q.E.D.

View File

@ -14,16 +14,16 @@ Loading module Main
This binding for `ss` shadows the existing binding at
check09.cry:5:1--5:3
[warning] at check09.cry:17:18--17:28:
Defaulting type argument 'a' of 'fromTo' to [3]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check09.cry:14:18--14:26:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check09.cry:13:18--13:26:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at <interactive>:1:7--1:15:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[0x00000008, 0x00004080, 0x00068c00, 0x00a22800]
[warning] at <interactive>:1:7--1:15:
Defaulting type argument 'a' of 'fromTo' to [2]
Defaulting type argument 'a' of 'fromTo' to Integer
[0x00000800, 0x00005080, 0x00072d00, 0x00b08200]
[0x00000008, 0x131b638b, 0x4fdd24a2, 0xb9094711, 0xa9cc106f,
0x52c445fb, 0xec66ea8b]

View File

@ -2,7 +2,7 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check11.cry:5:16--5:25:
Defaulting type argument 'a' of 'fromTo' to [7]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check11.cry:3:10--3:19:
Defaulting type argument 'a' of 'fromTo' to [7]
Defaulting type argument 'a' of 'fromTo' to Integer
True

View File

@ -2,7 +2,7 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check14.cry:5:63--5:75:
Defaulting type of sequence member to [3]
Defaulting type of sequence member to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for type of sequence member
[[3, 2, 1, 0], [7, 6, 5, 4]]

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check16-tab.cry:1:11--1:17:
Defaulting type argument 'b' of 'length' to [4]
Defaulting type argument 'b' of 'length' to Integer
True

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check16.cry:1:11--1:17:
Defaulting type argument 'b' of 'length' to [4]
Defaulting type argument 'b' of 'length' to Integer
True

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check20.cry:3:25--3:35:
Defaulting type of sequence member to [4]
Defaulting type of sequence member to Integer
True

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check21.cry:4:21--4:27:
Defaulting type argument 'b' of 'length' to [4]
Defaulting type argument 'b' of 'length' to Integer
True

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check22.cry:3:21--3:27:
Defaulting type argument 'b' of 'length' to [4]
Defaulting type argument 'b' of 'length' to Integer
True

View File

@ -5,7 +5,7 @@ Loading module check25
This binding for `tz` shadows the existing binding at
check25.cry:3:1--3:3
[warning] at check25.cry:8:11--8:19:
Defaulting 1st type argument of 'check25::tx' to [4]
Defaulting 1st type argument of 'check25::tx' to Integer
[warning] at check25.cry:5:6--6:16:
Defaulting the type of 'check25::tz' to [5]
Defaulting the type of 'check25::tz' to Integer
True

View File

@ -2,31 +2,31 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check26.cry:11:42--11:45:
Defaulting 2nd type argument of 'Main::xys' to [4]
Defaulting 2nd type argument of 'Main::xys' to Integer
[warning] at check26.cry:9:41--9:51:
Defaulting type argument 'a' of 'fromTo' to [3]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check26.cry:9:23--9:34:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
[warning] at check26.cry:8:31--8:34:
Defaulting 2nd type argument of 'Main::xys' to [3]
Defaulting 2nd type argument of 'Main::xys' to Integer
[warning] at check26.cry:5:35--5:37:
Defaulting 2nd type argument of 'Main::xy' to [5]
Defaulting 2nd type argument of 'Main::xy' to Integer
[warning] at check26.cry:5:35--5:37:
Defaulting 1st type argument of 'Main::xy' to [4]
Defaulting 1st type argument of 'Main::xy' to Integer
[warning] at check26.cry:5:17--5:19:
Defaulting 2nd type argument of 'Main::xy' to [5]
Defaulting 2nd type argument of 'Main::xy' to Integer
[warning] at check26.cry:5:17--5:19:
Defaulting 1st type argument of 'Main::xy' to [4]
Defaulting 1st type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:43--4:45:
Defaulting 1st type argument of 'Main::xy' to [4]
Defaulting 1st type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:37--4:39:
Defaulting 2nd type argument of 'Main::xy' to [5]
Defaulting 2nd type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:37--4:39:
Defaulting 1st type argument of 'Main::xy' to [4]
Defaulting 1st type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:23--4:25:
Defaulting 2nd type argument of 'Main::xy' to [5]
Defaulting 2nd type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:17--4:19:
Defaulting 2nd type argument of 'Main::xy' to [5]
Defaulting 2nd type argument of 'Main::xy' to Integer
[warning] at check26.cry:4:17--4:19:
Defaulting 1st type argument of 'Main::xy' to [4]
Defaulting 1st type argument of 'Main::xy' to Integer
True

View File

@ -2,5 +2,5 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at check28.cry:2:23--2:24:
Defaulting the type of 'Main::y' to [3]
Defaulting the type of 'Main::y' to Integer
True

View File

@ -10,12 +10,12 @@ Showing a specific instance of polymorphic result:
* Using 'Integer' for the type of '<interactive>::y'
{x = 1, y = 2}
[warning] at <interactive>:1:1--1:22:
Defaulting the type of '<interactive>::y' to [2]
Defaulting the type of '<interactive>::y' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for the type of '<interactive>::x'
1
[warning] at <interactive>:1:1--1:46:
Defaulting the type of '<interactive>::y' to [5]
Defaulting the type of '<interactive>::y' to Integer
Showing a specific instance of polymorphic result:
* Using 'Integer' for the type of '<interactive>::x'
10

View File

@ -2,14 +2,14 @@ Loading module Cryptol
Loading module Cryptol
Loading module Main
[warning] at <interactive>:1:11--1:19:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
True
[warning] at <interactive>:1:11--1:20:
Defaulting type argument 'a' of 'fromTo' to [4]
Defaulting type argument 'a' of 'fromTo' to Integer
False
[warning] at <interactive>:1:11--1:25:
Defaulting type argument 'a' of 'fromThenTo' to [7]
Defaulting type argument 'a' of 'fromThenTo' to Integer
False
[warning] at <interactive>:1:11--1:24:
Defaulting type argument 'a' of 'fromThenTo' to [7]
Defaulting type argument 'a' of 'fromThenTo' to Integer
True

View File

@ -3,5 +3,5 @@ Showing a specific instance of polymorphic result:
* Using 'Integer' for type argument 'a' of 'Cryptol::fromThenTo'
[11, 11, 11, 11, 11, 11, 11, 11, 11, 11]
[warning] at <interactive>:1:28--1:68:
Defaulting type of sequence member to [4]
Defaulting type of sequence member to Integer
True