e.g. in a C file. This means we don't accidentally treat things as empty, since previously we just defined these as empty types, but that broke coverage checking. Fixes #240
Unified · Split
| @@ -4,7 +4,7 @@ module Data.IORef · 3 unmodified lines | |||
| 4 | 4 | ||
| 5 | -- Implemented externally | 5 | -- Implemented externally |
| 6 | -- e.g., in Scheme, passed around as a box | 6 | -- e.g., in Scheme, passed around as a box |
| 7 | data Mut : Type -> Type | 7 | data Mut : Type -> Type where [external] |
| 8 | 8 | ||
| 9 | %extern prim__newIORef : forall a . a -> (1 x : %World) -> IORes (Mut a) | 9 | %extern prim__newIORef : forall a . a -> (1 x : %World) -> IORes (Mut a) |
| 10 | %extern prim__readIORef : forall a . Mut a -> (1 x : %World) -> IORes a | 10 | %extern prim__readIORef : forall a . Mut a -> (1 x : %World) -> IORes a |
| @@ -44,14 +44,14 @@ io_bind (MkIO fn) · 43 unmodified lines | |||
| 44 | -- The parameter is a phantom type, to help differentiate between | 44 | -- The parameter is a phantom type, to help differentiate between |
| 45 | -- different pointer types | 45 | -- different pointer types |
| 46 | public export | 46 | public export |
| 47 | data Ptr : Type -> Type where | 47 | data Ptr : Type -> Type where [external] |
| 48 | 48 | ||
| 49 | -- A pointer to any type (representing a void* in foreign calls) | 49 | -- A pointer to any type (representing a void* in foreign calls) |
| 50 | public export | 50 | public export |
| 51 | data AnyPtr : Type where | 51 | data AnyPtr : Type where [external] |
| 52 | 52 | ||
| 53 | public export | 53 | public export |
| 54 | data ThreadID : Type where | 54 | data ThreadID : Type where [external] |
| 55 | 55 | ||
| 56 | public export | 56 | public export |
| 57 | data FArgList : Type where | 57 | data FArgList : Type where |
| @@ -27,7 +27,7 @@ import Data.Buffer · 26 unmodified lines | |||
| 27 | -- TTC files can only be compatible if the version number is the same | 27 | -- TTC files can only be compatible if the version number is the same |
| 28 | export | 28 | export |
| 29 | ttcVersion : Int | 29 | ttcVersion : Int |
| 30 | ttcVersion = 19 | 30 | ttcVersion = 20 |
| 31 | 31 | ||
| 32 | export | 32 | export |
| 33 | checkTTCVersion : String -> Int -> Int -> Core () | 33 | checkTTCVersion : String -> Int -> Int -> Core () |
| @@ -36,6 +36,16 @@ export · 35 unmodified lines | |||
| 36 | defaultPI : PMDefInfo | 36 | defaultPI : PMDefInfo |
| 37 | defaultPI = MkPMDefInfo NotHole False | 37 | defaultPI = MkPMDefInfo NotHole False |
| 38 | 38 | ||
| 39 | public export | ||
| 40 | record TypeFlags where | ||
| 41 | constructor MkTypeFlags | ||
| 42 | uniqueAuto : Bool -- should 'auto' implicits check for uniqueness | ||
| 43 | external : Bool -- defined externally (e.g. in a C or Scheme library) | ||
| 44 | |||
| 45 | export | ||
| 46 | defaultFlags : TypeFlags | ||
| 47 | defaultFlags = MkTypeFlags False False | ||
| 48 | |||
| 39 | public export | 49 | public export |
| 40 | data Def : Type where | 50 | data Def : Type where |
| 41 | None : Def -- Not yet defined | 51 | None : Def -- Not yet defined |
| @@ -61,8 +71,7 @@ data Def : Type where · 19 unmodified lines | |||
| 61 | TCon : (tag : Int) -> (arity : Nat) -> | 71 | TCon : (tag : Int) -> (arity : Nat) -> |
| 62 | (parampos : List Nat) -> -- parameters | 72 | (parampos : List Nat) -> -- parameters |
| 63 | (detpos : List Nat) -> -- determining arguments | 73 | (detpos : List Nat) -> -- determining arguments |
| 64 | (uniqueAuto : Bool) -> -- should 'auto' implicits check | 74 | (flags : TypeFlags) -> -- should 'auto' implicits check |
| 65 | -- for uniqueness | ||
| 66 | (mutwith : List Name) -> | 75 | (mutwith : List Name) -> |
| 67 | (datacons : List Name) -> | 76 | (datacons : List Name) -> |
| 68 | (detagabbleBy : Maybe (List Nat)) -> | 77 | (detagabbleBy : Maybe (List Nat)) -> |
| @@ -1286,7 +1295,7 @@ getSearchData fc defaults target · 1217 unmodified lines | |||
| 1286 | pure (MkSearchData dets (filter (isCons . snd) | 1295 | pure (MkSearchData dets (filter (isCons . snd) |
| 1287 | [(False, opens), | 1296 | [(False, opens), |
| 1288 | (False, autos), | 1297 | (False, autos), |
| 1289 | (not u, tyhs), | 1298 | (not (uniqueAuto u), tyhs), |
| 1290 | (True, chasers)])) | 1299 | (True, chasers)])) |
| 1291 | where | 1300 | where |
| 1292 | isDefault : (Name, Bool) -> Bool | 1301 | isDefault : (Name, Bool) -> Bool |
| @@ -1362,9 +1371,22 @@ setUniqueSearch fc tyn u · 69 unmodified lines | |||
| 1362 | = do defs <- get Ctxt | 1371 | = do defs <- get Ctxt |
| 1363 | Just g <- lookupCtxtExact tyn (gamma defs) | 1372 | Just g <- lookupCtxtExact tyn (gamma defs) |
| 1364 | | _ => throw (UndefinedName fc tyn) | 1373 | | _ => throw (UndefinedName fc tyn) |
| 1365 | let TCon t a ps ds _ cons ms det = definition g | 1374 | let TCon t a ps ds fl cons ms det = definition g |
| 1375 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]")) | ||
| 1376 | let fl' = record { uniqueAuto = u } fl | ||
| 1377 | updateDef tyn (const (Just (TCon t a ps ds fl' cons ms det))) | ||
| 1378 | |||
| 1379 | export | ||
| 1380 | setExternal : {auto c : Ref Ctxt Defs} -> | ||
| 1381 | FC -> Name -> Bool -> Core () | ||
| 1382 | setExternal fc tyn u | ||
| 1383 | = do defs <- get Ctxt | ||
| 1384 | Just g <- lookupCtxtExact tyn (gamma defs) | ||
| 1385 | | _ => throw (UndefinedName fc tyn) | ||
| 1386 | let TCon t a ps ds fl cons ms det = definition g | ||
| 1366 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]")) | 1387 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]")) |
| 1367 | updateDef tyn (const (Just (TCon t a ps ds u cons ms det))) | 1388 | let fl' = record { external = u } fl |
| 1389 | updateDef tyn (const (Just (TCon t a ps ds fl' cons ms det))) | ||
| 1368 | 1390 | ||
| 1369 | export | 1391 | export |
| 1370 | addHintFor : {auto c : Ref Ctxt Defs} -> | 1392 | addHintFor : {auto c : Ref Ctxt Defs} -> |
| @@ -1598,7 +1620,7 @@ addData vars vis tidx (MkData (MkCon dfc tyn arity tycon) datacons) · 227 unmodified lines | |||
| 1598 | (TCon tag arity | 1620 | (TCon tag arity |
| 1599 | (paramPos (Resolved tidx) (map type datacons)) | 1621 | (paramPos (Resolved tidx) (map type datacons)) |
| 1600 | (allDet arity) | 1622 | (allDet arity) |
| 1601 | False [] (map name datacons) Nothing) | 1623 | defaultFlags [] (map name datacons) Nothing) |
| 1602 | (idx, gam') <- addCtxt tyn tydef (gamma defs) | 1624 | (idx, gam') <- addCtxt tyn tydef (gamma defs) |
| 1603 | gam'' <- addDataConstructors 0 datacons gam' | 1625 | gam'' <- addDataConstructors 0 datacons gam' |
| 1604 | put Ctxt (record { gamma = gam'' } defs) | 1626 | put Ctxt (record { gamma = gam'' } defs) |
| @@ -51,8 +51,10 @@ export · 50 unmodified lines | |||
| 51 | isEmpty : Defs -> NF vars -> Core Bool | 51 | isEmpty : Defs -> NF vars -> Core Bool |
| 52 | isEmpty defs (NTCon fc n t a args) | 52 | isEmpty defs (NTCon fc n t a args) |
| 53 | = case !(lookupDefExact n (gamma defs)) of | 53 | = case !(lookupDefExact n (gamma defs)) of |
| 54 | Just (TCon _ _ _ _ _ _ cons _) | 54 | Just (TCon _ _ _ _ flags _ cons _) |
| 55 | => allM (conflict defs (NTCon fc n t a args)) cons | 55 | => if not (external flags) |
| 56 | then allM (conflict defs (NTCon fc n t a args)) cons | ||
| 57 | else pure False | ||
| 56 | _ => pure False | 58 | _ => pure False |
| 57 | isEmpty defs _ = pure False | 59 | isEmpty defs _ = pure False |
| 58 | 60 | ||
| @@ -777,6 +777,16 @@ TTC PMDefInfo where · 776 unmodified lines | |||
| 777 | r <- fromBuf b | 777 | r <- fromBuf b |
| 778 | pure (MkPMDefInfo h r) | 778 | pure (MkPMDefInfo h r) |
| 779 | 779 | ||
| 780 | export | ||
| 781 | TTC TypeFlags where | ||
| 782 | toBuf b l | ||
| 783 | = do toBuf b (uniqueAuto l) | ||
| 784 | toBuf b (external l) | ||
| 785 | fromBuf b | ||
| 786 | = do u <- fromBuf b | ||
| 787 | e <- fromBuf b | ||
| 788 | pure (MkTypeFlags u e) | ||
| 789 | |||
| 780 | export | 790 | export |
| 781 | TTC Def where | 791 | TTC Def where |
| 782 | toBuf b None = tag 0 | 792 | toBuf b None = tag 0 |
| @@ -894,6 +894,8 @@ dataOpt · 893 unmodified lines | |||
| 894 | <|> do exactIdent "search" | 894 | <|> do exactIdent "search" |
| 895 | ns <- some name | 895 | ns <- some name |
| 896 | pure (SearchBy ns) | 896 | pure (SearchBy ns) |
| 897 | <|> do exactIdent "external" | ||
| 898 | pure External | ||
| 897 | 899 | ||
| 898 | dataBody : FileName -> Int -> FilePos -> Name -> IndentInfo -> PTerm -> | 900 | dataBody : FileName -> Int -> FilePos -> Name -> IndentInfo -> PTerm -> |
| 899 | EmptyRule PDataDecl | 901 | EmptyRule PDataDecl |
| @@ -27,6 +27,8 @@ processDataOpt fc ndef (SearchBy dets) · 26 unmodified lines | |||
| 27 | = setDetermining fc ndef dets | 27 | = setDetermining fc ndef dets |
| 28 | processDataOpt fc ndef UniqueSearch | 28 | processDataOpt fc ndef UniqueSearch |
| 29 | = setUniqueSearch fc ndef True | 29 | = setUniqueSearch fc ndef True |
| 30 | processDataOpt fc ndef External | ||
| 31 | = setExternal fc ndef True | ||
| 30 | 32 | ||
| 31 | checkRetType : {auto c : Ref Ctxt Defs} -> | 33 | checkRetType : {auto c : Ref Ctxt Defs} -> |
| 32 | Env Term vars -> NF vars -> | 34 | Env Term vars -> NF vars -> |
| @@ -253,7 +255,7 @@ processData {vars} eopts nest env fc vis (MkImpLater dfc n_in ty_raw) · 220 unmodified lines | |||
| 253 | 255 | ||
| 254 | -- Add the type constructor as a placeholder | 256 | -- Add the type constructor as a placeholder |
| 255 | tidx <- addDef n (newDef fc n Rig1 vars fullty vis | 257 | tidx <- addDef n (newDef fc n Rig1 vars fullty vis |
| 256 | (TCon 0 arity [] [] False [] [] Nothing)) | 258 | (TCon 0 arity [] [] defaultFlags [] [] Nothing)) |
| 257 | addMutData (Resolved tidx) | 259 | addMutData (Resolved tidx) |
| 258 | defs <- get Ctxt | 260 | defs <- get Ctxt |
| 259 | traverse_ (\n => setMutWith fc n (mutData defs)) (mutData defs) | 261 | traverse_ (\n => setMutWith fc n (mutData defs)) (mutData defs) |
| @@ -306,7 +308,7 @@ processData {vars} eopts nest env fc vis (MkImpData dfc n_in ty_raw opts cons_ra · 46 unmodified lines | |||
| 306 | -- Add the type constructor as a placeholder while checking | 308 | -- Add the type constructor as a placeholder while checking |
| 307 | -- data constructors | 309 | -- data constructors |
| 308 | tidx <- addDef n (newDef fc n Rig1 vars fullty vis | 310 | tidx <- addDef n (newDef fc n Rig1 vars fullty vis |
| 309 | (TCon 0 arity [] [] False [] [] Nothing)) | 311 | (TCon 0 arity [] [] defaultFlags [] [] Nothing)) |
| 310 | case vis of | 312 | case vis of |
| 311 | Private => pure () | 313 | Private => pure () |
| 312 | _ => do addHash n | 314 | _ => do addHash n |
| @@ -231,12 +231,14 @@ mutual · 230 unmodified lines | |||
| 231 | SearchBy : List Name -> DataOpt -- determining arguments | 231 | SearchBy : List Name -> DataOpt -- determining arguments |
| 232 | NoHints : DataOpt -- Don't generate search hints for constructors | 232 | NoHints : DataOpt -- Don't generate search hints for constructors |
| 233 | UniqueSearch : DataOpt -- auto implicit search must check result is unique | 233 | UniqueSearch : DataOpt -- auto implicit search must check result is unique |
| 234 | External : DataOpt -- implemented externally | ||
| 234 | 235 | ||
| 235 | export | 236 | export |
| 236 | Eq DataOpt where | 237 | Eq DataOpt where |
| 237 | (==) (SearchBy xs) (SearchBy ys) = xs == ys | 238 | (==) (SearchBy xs) (SearchBy ys) = xs == ys |
| 238 | (==) NoHints NoHints = True | 239 | (==) NoHints NoHints = True |
| 239 | (==) UniqueSearch UniqueSearch = True | 240 | (==) UniqueSearch UniqueSearch = True |
| 241 | (==) External External = True | ||
| 240 | (==) _ _ = False | 242 | (==) _ _ = False |
| 241 | 243 | ||
| 242 | public export | 244 | public export |
| @@ -812,6 +814,7 @@ mutual · 569 unmodified lines | |||
| 812 | = do tag 0; toBuf b ns | 814 | = do tag 0; toBuf b ns |
| 813 | toBuf b NoHints = tag 1 | 815 | toBuf b NoHints = tag 1 |
| 814 | toBuf b UniqueSearch = tag 2 | 816 | toBuf b UniqueSearch = tag 2 |
| 817 | toBuf b External = tag 3 | ||
| 815 | 818 | ||
| 816 | fromBuf b | 819 | fromBuf b |
| 817 | = case !getTag of | 820 | = case !getTag of |
| @@ -819,6 +822,7 @@ mutual · 1 unmodified line | |||
| 819 | pure (SearchBy ns) | 822 | pure (SearchBy ns) |
| 820 | 1 => pure NoHints | 823 | 1 => pure NoHints |
| 821 | 2 => pure UniqueSearch | 824 | 2 => pure UniqueSearch |
| 825 | 3 => pure External | ||
| 822 | _ => corrupt "DataOpt" | 826 | _ => corrupt "DataOpt" |
| 823 | 827 | ||
| 824 | export | 828 | export |
| @@ -81,6 +81,7 @@ idrisTests · 80 unmodified lines | |||
| 81 | -- Miscellaneous regressions | 81 | -- Miscellaneous regressions |
| 82 | "reg001", "reg002", "reg003", "reg004", "reg005", "reg006", "reg007", | 82 | "reg001", "reg002", "reg003", "reg004", "reg005", "reg006", "reg007", |
| 83 | "reg008", "reg009", "reg010", "reg011", "reg012", "reg013", "reg014", | 83 | "reg008", "reg009", "reg010", "reg011", "reg012", "reg013", "reg014", |
| 84 | "reg015", | ||
| 84 | -- Totality checking | 85 | -- Totality checking |
| 85 | "total001", "total002", "total003", "total004", "total005", | 86 | "total001", "total002", "total003", "total004", "total005", |
| 86 | "total006", | 87 | "total006", |
| @@ -0,0 +1,21 @@ | |||
| 1 | data SimpleData = PtrAndSize AnyPtr Int | ||
| 2 | |||
| 3 | record Complicated where | ||
| 4 | constructor MkComplicated | ||
| 5 | simple : SimpleData | ||
| 6 | |||
| 7 | record MoreComplicated where | ||
| 8 | constructor MkMoreComplicated | ||
| 9 | something : Complicated | ||
| 10 | |||
| 11 | record EvenMoreComplicated where | ||
| 12 | constructor MkEvenMoreComplicated | ||
| 13 | somethingEven : MoreComplicated | ||
| 14 | |||
| 15 | data TooComplicatedToBeTrue : (something : EvenMoreComplicated) -> Type where | ||
| 16 | SomethingVeryComplicatedIs : | ||
| 17 | TooComplicatedToBeTrue | ||
| 18 | (MkEvenMoreComplicated (MkMoreComplicated (MkComplicated (PtrAndSize addr len)))) | ||
| 19 | |||
| 20 | showing : (something : EvenMoreComplicated) -> (TooComplicatedToBeTrue something) -> Void | ||
| 21 | showing _ SomethingVeryComplicatedIs impossible | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | 1/1: Building anyfail (anyfail.idr) | ||
| 2 | anyfail.idr:21:1--22:1:showing (MkEvenMoreComplicated (MkMoreComplicated (MkComplicated (PtrAndSize addr len)))) SomethingVeryComplicatedIs is not a valid impossible case | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | $1 anyfail.idr --check | ||
| 2 | |||
| 3 | rm -rf build | ||