History

Allow flagging types as externally defined

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

Edwin Brady committed 6 years ago

Commit 69a76401 parent 0daece113 files · +84 −15Browse files

Unified · Split

13 files
  1. libs/base/Data/IORef.idr +1 −1
  2. libs/prelude/PrimIO.idr +3 −3
  3. src/Core/Binary.idr +1 −1
  4. src/Core/Context.idr +28 −6
  5. src/Core/Coverage.idr +4 −2
  6. src/Core/TTC.idr +10 −0
  7. src/Idris/Parser.idr +2 −0
  8. src/TTImp/ProcessData.idr +4 −2
  9. src/TTImp/TTImp.idr +4 −0
  10. tests/Main.idr +1 −0
  11. tests/idris2/reg015/anyfail.idr +21 −0
  12. tests/idris2/reg015/expected +2 −0
  13. tests/idris2/reg015/run +3 −0
libs/base/Data/IORef.idr+1−1
@@ -4,7 +4,7 @@ module Data.IORef · 3 unmodified lines
4 4
5-- Implemented externally5-- Implemented externally
6-- e.g., in Scheme, passed around as a box6-- e.g., in Scheme, passed around as a box
7data Mut : Type -> Type7data 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 a10%extern prim__readIORef : forall a . Mut a -> (1 x : %World) -> IORes a
libs/prelude/PrimIO.idr+3−3
@@ -44,14 +44,14 @@ io_bind (MkIO fn) · 43 unmodified lines
44-- The parameter is a phantom type, to help differentiate between44-- The parameter is a phantom type, to help differentiate between
45-- different pointer types45-- different pointer types
46public export46public export
47data Ptr : Type -> Type where47data 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)
50public export50public export
51data AnyPtr : Type where51data AnyPtr : Type where [external]
52 52
53public export53public export
54data ThreadID : Type where54data ThreadID : Type where [external]
55 55
56public export56public export
57data FArgList : Type where57data FArgList : Type where
src/Core/Binary.idr+1−1
@@ -27,7 +27,7 @@ import Data.Buffer · 26 unmodified lines
27-- TTC files can only be compatible if the version number is the same27-- TTC files can only be compatible if the version number is the same
28export28export
29ttcVersion : Int29ttcVersion : Int
30ttcVersion = 1930ttcVersion = 20
31 31
32export32export
33checkTTCVersion : String -> Int -> Int -> Core ()33checkTTCVersion : String -> Int -> Int -> Core ()
src/Core/Context.idr+28−6
@@ -36,6 +36,16 @@ export · 35 unmodified lines
36defaultPI : PMDefInfo36defaultPI : PMDefInfo
37defaultPI = MkPMDefInfo NotHole False37defaultPI = MkPMDefInfo NotHole False
38 38
39public export
40record 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
45export
46defaultFlags : TypeFlags
47defaultFlags = MkTypeFlags False False
48
39public export49public export
40data Def : Type where50data Def : Type where
41 None : Def -- Not yet defined51 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) -> -- parameters72 (parampos : List Nat) -> -- parameters
63 (detpos : List Nat) -> -- determining arguments73 (detpos : List Nat) -> -- determining arguments
64 (uniqueAuto : Bool) -> -- should 'auto' implicits check74 (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 where1300 where
1292 isDefault : (Name, Bool) -> Bool1301 isDefault : (Name, Bool) -> Bool
@@ -1362,9 +1371,22 @@ setUniqueSearch fc tyn u · 69 unmodified lines
1362 = do defs <- get Ctxt1371 = 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 g1374 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
1379export
1380setExternal : {auto c : Ref Ctxt Defs} ->
1381 FC -> Name -> Bool -> Core ()
1382setExternal 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
1369export1391export
1370addHintFor : {auto c : Ref Ctxt Defs} ->1392addHintFor : {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 arity1620 (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)
src/Core/Coverage.idr+4−2
@@ -51,8 +51,10 @@ export · 50 unmodified lines
51isEmpty : Defs -> NF vars -> Core Bool51isEmpty : Defs -> NF vars -> Core Bool
52isEmpty defs (NTCon fc n t a args)52isEmpty defs (NTCon fc n t a args)
53 = case !(lookupDefExact n (gamma defs)) of53 = 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)) cons55 => if not (external flags)
56 then allM (conflict defs (NTCon fc n t a args)) cons
57 else pure False
56 _ => pure False58 _ => pure False
57isEmpty defs _ = pure False59isEmpty defs _ = pure False
58 60
src/Core/TTC.idr+10−0
@@ -777,6 +777,16 @@ TTC PMDefInfo where · 776 unmodified lines
777 r <- fromBuf b777 r <- fromBuf b
778 pure (MkPMDefInfo h r)778 pure (MkPMDefInfo h r)
779 779
780export
781TTC 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
780export790export
781TTC Def where791TTC Def where
782 toBuf b None = tag 0792 toBuf b None = tag 0
src/Idris/Parser.idr+2−0
@@ -894,6 +894,8 @@ dataOpt · 893 unmodified lines
894 <|> do exactIdent "search"894 <|> do exactIdent "search"
895 ns <- some name895 ns <- some name
896 pure (SearchBy ns)896 pure (SearchBy ns)
897 <|> do exactIdent "external"
898 pure External
897 899
898dataBody : FileName -> Int -> FilePos -> Name -> IndentInfo -> PTerm ->900dataBody : FileName -> Int -> FilePos -> Name -> IndentInfo -> PTerm ->
899 EmptyRule PDataDecl901 EmptyRule PDataDecl
src/TTImp/ProcessData.idr+4−2
@@ -27,6 +27,8 @@ processDataOpt fc ndef (SearchBy dets) · 26 unmodified lines
27 = setDetermining fc ndef dets27 = setDetermining fc ndef dets
28processDataOpt fc ndef UniqueSearch28processDataOpt fc ndef UniqueSearch
29 = setUniqueSearch fc ndef True29 = setUniqueSearch fc ndef True
30processDataOpt fc ndef External
31 = setExternal fc ndef True
30 32
31checkRetType : {auto c : Ref Ctxt Defs} ->33checkRetType : {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 placeholder256 -- Add the type constructor as a placeholder
255 tidx <- addDef n (newDef fc n Rig1 vars fullty vis257 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 Ctxt260 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 checking308 -- Add the type constructor as a placeholder while checking
307 -- data constructors309 -- data constructors
308 tidx <- addDef n (newDef fc n Rig1 vars fullty vis310 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 of312 case vis of
311 Private => pure ()313 Private => pure ()
312 _ => do addHash n314 _ => do addHash n
src/TTImp/TTImp.idr+4−0
@@ -231,12 +231,14 @@ mutual · 230 unmodified lines
231 SearchBy : List Name -> DataOpt -- determining arguments231 SearchBy : List Name -> DataOpt -- determining arguments
232 NoHints : DataOpt -- Don't generate search hints for constructors232 NoHints : DataOpt -- Don't generate search hints for constructors
233 UniqueSearch : DataOpt -- auto implicit search must check result is unique233 UniqueSearch : DataOpt -- auto implicit search must check result is unique
234 External : DataOpt -- implemented externally
234 235
235 export236 export
236 Eq DataOpt where237 Eq DataOpt where
237 (==) (SearchBy xs) (SearchBy ys) = xs == ys238 (==) (SearchBy xs) (SearchBy ys) = xs == ys
238 (==) NoHints NoHints = True239 (==) NoHints NoHints = True
239 (==) UniqueSearch UniqueSearch = True240 (==) UniqueSearch UniqueSearch = True
241 (==) External External = True
240 (==) _ _ = False242 (==) _ _ = False
241 243
242 public export244 public export
@@ -812,6 +814,7 @@ mutual · 569 unmodified lines
812 = do tag 0; toBuf b ns814 = do tag 0; toBuf b ns
813 toBuf b NoHints = tag 1815 toBuf b NoHints = tag 1
814 toBuf b UniqueSearch = tag 2816 toBuf b UniqueSearch = tag 2
817 toBuf b External = tag 3
815 818
816 fromBuf b819 fromBuf b
817 = case !getTag of820 = case !getTag of
@@ -819,6 +822,7 @@ mutual · 1 unmodified line
819 pure (SearchBy ns)822 pure (SearchBy ns)
820 1 => pure NoHints823 1 => pure NoHints
821 2 => pure UniqueSearch824 2 => pure UniqueSearch
825 3 => pure External
822 _ => corrupt "DataOpt"826 _ => corrupt "DataOpt"
823 827
824 export828 export
tests/Main.idr+1−0
@@ -81,6 +81,7 @@ idrisTests · 80 unmodified lines
81 -- Miscellaneous regressions81 -- 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 checking85 -- Totality checking
85 "total001", "total002", "total003", "total004", "total005",86 "total001", "total002", "total003", "total004", "total005",
86 "total006",87 "total006",
tests/idris2/reg015/anyfail.idr+21−0
@@ -0,0 +1,21 @@
1data SimpleData = PtrAndSize AnyPtr Int
2
3record Complicated where
4 constructor MkComplicated
5 simple : SimpleData
6
7record MoreComplicated where
8 constructor MkMoreComplicated
9 something : Complicated
10
11record EvenMoreComplicated where
12 constructor MkEvenMoreComplicated
13 somethingEven : MoreComplicated
14
15data TooComplicatedToBeTrue : (something : EvenMoreComplicated) -> Type where
16 SomethingVeryComplicatedIs :
17 TooComplicatedToBeTrue
18 (MkEvenMoreComplicated (MkMoreComplicated (MkComplicated (PtrAndSize addr len))))
19
20showing : (something : EvenMoreComplicated) -> (TooComplicatedToBeTrue something) -> Void
21showing _ SomethingVeryComplicatedIs impossible
tests/idris2/reg015/expected+2−0
@@ -0,0 +1,2 @@
11/1: Building anyfail (anyfail.idr)
2anyfail.idr:21:1--22:1:showing (MkEvenMoreComplicated (MkMoreComplicated (MkComplicated (PtrAndSize addr len)))) SomethingVeryComplicatedIs is not a valid impossible case
tests/idris2/reg015/run+3−0
@@ -0,0 +1,3 @@
1$1 anyfail.idr --check
2
3rm -rf build

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t