on master help sign in
Propagate default totality to instances
1d97fa7Edwin Brady
libs/prelude/Prelude/File.idr+2
@@ -44,6 +44,8 @@ getFileError = do MkRaw err <- foreign FFI_C "idris_mkFileError"
44 return err
44 return err
45
45
46Show FileError where
46Show FileError where
47+ show FileReadError = "File Read Error"
48+ show FileWriteError = "File Write Error"
47 show FileNotFound = "File Not Found"
49 show FileNotFound = "File Not Found"
48 show PermissionDenied = "Permission Denied"
50 show PermissionDenied = "Permission Denied"
49 show (GenericFileError errno) = strError errno
51 show (GenericFileError errno) = strError errno
libs/prelude/Prelude/Nat.idr+3
@@ -341,9 +341,12 @@ partial
341divCeil : Nat -> Nat -> Nat
341divCeil : Nat -> Nat -> Nat
342divCeil x (S y) = divCeilNZ x (S y) SIsNotZ
342divCeil x (S y) = divCeilNZ x (S y) SIsNotZ
343
343
344+-- TMP HACK until it's possible to set flags on instances
345+%default partial
344Integral Nat where
346Integral Nat where
345 div = divNat
347 div = divNat
346 mod = modNat
348 mod = modNat
349+%default total
347
350
348log2NZ : (x: Nat) -> Not (x = Z) -> Nat
351log2NZ : (x: Nat) -> Not (x = Z) -> Nat
349log2NZ Z p = void (p Refl)
352log2NZ Z p = void (p Refl)
src/Idris/Elab/Clause.hs+1−1
@@ -581,7 +581,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
581-- let lhs = mkLHSapp $
581-- let lhs = mkLHSapp $
582-- propagateParams i params fn_ty (addImplPat i lhs_in)
582-- propagateParams i params fn_ty (addImplPat i lhs_in)
583 logElab 10 (show (params, fn_ty) ++ " " ++ showTmImpls (addImplPat i lhs_in))
583 logElab 10 (show (params, fn_ty) ++ " " ++ showTmImpls (addImplPat i lhs_in))
584− logElab 5 ("LHS: " ++ show fc ++ " " ++ showTmImpls lhs)
584+ logElab 5 ("LHS: " ++ show opts ++ "\n" ++ show fc ++ " " ++ showTmImpls lhs)
585 logElab 4 ("Fixed parameters: " ++ show params ++ " from " ++ show lhs_in ++
585 logElab 4 ("Fixed parameters: " ++ show params ++ " from " ++ show lhs_in ++
586 "\n" ++ show (fn_ty, fn_is))
586 "\n" ++ show (fn_ty, fn_is))
587
587
src/Idris/Elab/Instance.hs+13−10
@@ -63,24 +63,27 @@ elabInstance :: ElabInfo -> SyntaxInfo ->
63 Maybe Name -> -- explicit name
63 Maybe Name -> -- explicit name
64 [PDecl] -> Idris ()
64 [PDecl] -> Idris ()
65elabInstance info syn doc argDocs what fc cs acc n nfc ps t expn ds = do
65elabInstance info syn doc argDocs what fc cs acc n nfc ps t expn ds = do
66− i <- getIState
66+ ist <- getIState
67− (n, ci) <- case lookupCtxtName n (idris_classes i) of
67+ (n, ci) <- case lookupCtxtName n (idris_classes ist) of
68 [c] -> return c
68 [c] -> return c
69 [] -> ifail $ show fc ++ ":" ++ show n ++ " is not a type class"
69 [] -> ifail $ show fc ++ ":" ++ show n ++ " is not a type class"
70 cs -> tclift $ tfail $ At fc
70 cs -> tclift $ tfail $ At fc
71 (CantResolveAlts (map fst cs))
71 (CantResolveAlts (map fst cs))
72 let constraint = PApp fc (PRef fc [] n) (map pexp ps)
72 let constraint = PApp fc (PRef fc [] n) (map pexp ps)
73 let iname = mkiname n (namespace info) ps expn
73 let iname = mkiname n (namespace info) ps expn
74− putIState (i { hide_list = addDef iname acc (hide_list i) })
74+ putIState (ist { hide_list = addDef iname acc (hide_list ist) })
75− i <- getIState
75+ ist <- getIState
76+
77+ let totopts = if default_total ist then [TotalFn, Dictionary]
78+ else [Dictionary]
76
79
77 let emptyclass = null (class_methods ci)
80 let emptyclass = null (class_methods ci)
78 when (what /= EDefns) $ do
81 when (what /= EDefns) $ do
79− nty <- elabType' True info syn doc argDocs fc [] iname NoFC t
82+ nty <- elabType' True info syn doc argDocs fc totopts iname NoFC t
80 -- if the instance type matches any of the instances we have already,
83 -- if the instance type matches any of the instances we have already,
81 -- and it's not a named instance, then it's overlapping, so report an error
84 -- and it's not a named instance, then it's overlapping, so report an error
82 case expn of
85 case expn of
83− Nothing -> do mapM_ (maybe (return ()) overlapping . findOverlapping i (class_determiners ci) (delab i nty))
86+ Nothing -> do mapM_ (maybe (return ()) overlapping . findOverlapping ist (class_determiners ci) (delab ist nty))
84 (map fst $ class_instances ci)
87 (map fst $ class_instances ci)
85 addInstance intInst True n iname
88 addInstance intInst True n iname
86 Just _ -> addInstance intInst False n iname
89 Just _ -> addInstance intInst False n iname
@@ -99,7 +102,7 @@ elabInstance info syn doc argDocs what fc cs acc n nfc ps t expn ds = do
99 let pnames = nub $ map pname (concat (nub wparams)) ++
102 let pnames = nub $ map pname (concat (nub wparams)) ++
100 concatMap (namesIn [] ist) ps
103 concatMap (namesIn [] ist) ps
101 let superclassInstances = map (substInstance ips pnames) (class_default_superclasses ci)
104 let superclassInstances = map (substInstance ips pnames) (class_default_superclasses ci)
102− undefinedSuperclassInstances <- filterM (fmap not . isOverlapping i) superclassInstances
105+ undefinedSuperclassInstances <- filterM (fmap not . isOverlapping ist) superclassInstances
103 mapM_ (rec_elabDecl info EAll info) undefinedSuperclassInstances
106 mapM_ (rec_elabDecl info EAll info) undefinedSuperclassInstances
104 let all_meths = map (nsroot . fst) (class_methods ci)
107 let all_meths = map (nsroot . fst) (class_methods ci)
105 let mtys = map (\ (n, (op, t)) ->
108 let mtys = map (\ (n, (op, t)) ->
@@ -112,7 +115,7 @@ elabInstance info syn doc argDocs what fc cs acc n nfc ps t expn ds = do
112 (class_methods ci)
115 (class_methods ci)
113 logElab 3 (show (mtys, ips))
116 logElab 3 (show (mtys, ips))
114 logElab 5 ("Before defaults: " ++ show ds ++ "\n" ++ show (map fst (class_methods ci)))
117 logElab 5 ("Before defaults: " ++ show ds ++ "\n" ++ show (map fst (class_methods ci)))
115− let ds_defs = insertDefaults i iname (class_defaults ci) ns ds
118+ let ds_defs = insertDefaults ist iname (class_defaults ci) ns ds
116 logElab 3 ("After defaults: " ++ show ds_defs ++ "\n")
119 logElab 3 ("After defaults: " ++ show ds_defs ++ "\n")
117 let ds' = reorderDefs (map fst (class_methods ci)) $ ds_defs
120 let ds' = reorderDefs (map fst (class_methods ci)) $ ds_defs
118 logElab 1 ("Reordered: " ++ show ds' ++ "\n")
121 logElab 1 ("Reordered: " ++ show ds' ++ "\n")
@@ -138,10 +141,10 @@ elabInstance info syn doc argDocs what fc cs acc n nfc ps t expn ds = do
138 let rhs = PApp fc (PRef fc [] (instanceCtorName ci))
141 let rhs = PApp fc (PRef fc [] (instanceCtorName ci))
139 (map (pexp . mkMethApp) mtys)
142 (map (pexp . mkMethApp) mtys)
140
143
141− logElab 5 $ "Instance LHS " ++ show lhs ++ " " ++ show headVars
144+ logElab 5 $ "Instance LHS " ++ show totopts ++ "\n" ++ show lhs ++ " " ++ show headVars
142 logElab 5 $ "Instance RHS " ++ show rhs
145 logElab 5 $ "Instance RHS " ++ show rhs
143
146
144− let idecls = [PClauses fc [Dictionary] iname
147+ let idecls = [PClauses fc totopts iname
145 [PClause fc iname lhs [] rhs wb]]
148 [PClause fc iname lhs [] rhs wb]]
146 logElab 1 (show idecls)
149 logElab 1 (show idecls)
147 push_estack iname True
150 push_estack iname True