@@ -4,12 +4,12 @@
4module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC, normaliseAll,
4module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC, normaliseAll,
5 rt_simplify, simplify, specialise, hnf, convEq, convEq',
5 rt_simplify, simplify, specialise, hnf, convEq, convEq',
6 Def(..), CaseInfo(..), CaseDefs(..),
6 Def(..), CaseInfo(..), CaseDefs(..),
7− Accessibility(..), Totality(..), PReason(..),
7+ Accessibility(..), Totality(..), PReason(..), MetaInformation(..),
8 Context, initContext, ctxtAlist, uconstraints, next_tvar,
8 Context, initContext, ctxtAlist, uconstraints, next_tvar,
9− addToCtxt, setAccess, setTotal, addCtxtDef, addTyDecl,
9+ addToCtxt, setAccess, setTotal, setMetaInformation, addCtxtDef, addTyDecl,
10 addDatatype, addCasedef, simplifyCasedef, addOperator,
10 addDatatype, addCasedef, simplifyCasedef, addOperator,
11 lookupNames, lookupTy, lookupP, lookupDef, lookupDefAcc, lookupVal,
11 lookupNames, lookupTy, lookupP, lookupDef, lookupDefAcc, lookupVal,
12− lookupTotal, lookupNameTotal, lookupTyEnv, isDConName, isTConName, isConName, isFnName,
12+ lookupTotal, lookupNameTotal, lookupMetaInformation, lookupTyEnv, isDConName, isTConName, isConName, isFnName,
13 Value(..), Quote(..), initEval) where
13 Value(..), Quote(..), initEval) where
15import Debug.Trace
15import Debug.Trace
@@ -678,12 +678,18 @@ deriving instance Binary Totality
678deriving instance Binary PReason
678deriving instance Binary PReason
681+-- Possible attached meta-information for a definition in context
682+data MetaInformation =
683+ EmptyMI -- ^ No meta-information
684+ | DataMI [Int] -- ^ Meta information for a data declaration with position of parameters
681-- | Contexts used for global definitions and for proof state. They contain
687-- | Contexts used for global definitions and for proof state. They contain
682-- universe constraints and existing definitions.
688-- universe constraints and existing definitions.
683data Context = MkContext {
689data Context = MkContext {
684− uconstraints :: [UConstraint],
690+ uconstraints :: [UConstraint],
685− next_tvar :: Int,
691+ next_tvar :: Int,
686− definitions :: Ctxt (Def, Accessibility, Totality)
692+ definitions :: Ctxt (Def, Accessibility, Totality, MetaInformation)
687 } deriving Show
693 } deriving Show
689-- | The initial empty context
695-- | The initial empty context
@@ -691,37 +697,43 @@ initContext = MkContext [] 0 emptyContext
692-- | Get the definitions from a context
698-- | Get the definitions from a context
693ctxtAlist :: Context -> [(Name, Def)]
699ctxtAlist :: Context -> [(Name, Def)]
694−ctxtAlist ctxt = map (\(n, (d, a, t)) -> (n, d)) $ toAlist (definitions ctxt)
700+ctxtAlist ctxt = map (\(n, (d, a, t, m)) -> (n, d)) $ toAlist (definitions ctxt)
696veval ctxt env t = evalState (eval False ctxt [] env t []) initEval
702veval ctxt env t = evalState (eval False ctxt [] env t []) initEval
698addToCtxt :: Name -> Term -> Type -> Context -> Context
704addToCtxt :: Name -> Term -> Type -> Context -> Context
699addToCtxt n tm ty uctxt
705addToCtxt n tm ty uctxt
700 = let ctxt = definitions uctxt
706 = let ctxt = definitions uctxt
701− ctxt' = addDef n (Function ty tm, Public, Unchecked) ctxt in
707+ ctxt' = addDef n (Function ty tm, Public, Unchecked, EmptyMI) ctxt in
702 uctxt { definitions = ctxt' }
708 uctxt { definitions = ctxt' }
704setAccess :: Name -> Accessibility -> Context -> Context
710setAccess :: Name -> Accessibility -> Context -> Context
705setAccess n a uctxt
711setAccess n a uctxt
706 = let ctxt = definitions uctxt
712 = let ctxt = definitions uctxt
707− ctxt' = updateDef n (\ (d, _, t) -> (d, a, t)) ctxt in
713+ ctxt' = updateDef n (\ (d, _, t, m) -> (d, a, t, m)) ctxt in
708 uctxt { definitions = ctxt' }
714 uctxt { definitions = ctxt' }
710setTotal :: Name -> Totality -> Context -> Context
716setTotal :: Name -> Totality -> Context -> Context
711setTotal n t uctxt
717setTotal n t uctxt
712 = let ctxt = definitions uctxt
718 = let ctxt = definitions uctxt
713− ctxt' = updateDef n (\ (d, a, _) -> (d, a, t)) ctxt in
719+ ctxt' = updateDef n (\ (d, a, _, m) -> (d, a, t, m)) ctxt in
720+ uctxt { definitions = ctxt' }
722+setMetaInformation :: Name -> MetaInformation -> Context -> Context
723+setMetaInformation n m uctxt
724+ = let ctxt = definitions uctxt
725+ ctxt' = updateDef n (\ (d, a, t, _) -> (d, a, t, m)) ctxt in
714 uctxt { definitions = ctxt' }
726 uctxt { definitions = ctxt' }
716addCtxtDef :: Name -> Def -> Context -> Context
728addCtxtDef :: Name -> Def -> Context -> Context
717addCtxtDef n d c = let ctxt = definitions c
729addCtxtDef n d c = let ctxt = definitions c
718− ctxt' = addDef n (d, Public, Unchecked) $! ctxt in
730+ ctxt' = addDef n (d, Public, Unchecked, EmptyMI) $! ctxt in
719 c { definitions = ctxt' }
731 c { definitions = ctxt' }
721addTyDecl :: Name -> NameType -> Type -> Context -> Context
733addTyDecl :: Name -> NameType -> Type -> Context -> Context
722addTyDecl n nt ty uctxt
734addTyDecl n nt ty uctxt
723 = let ctxt = definitions uctxt
735 = let ctxt = definitions uctxt
724− ctxt' = addDef n (TyDecl nt ty, Public, Unchecked) ctxt in
736+ ctxt' = addDef n (TyDecl nt ty, Public, Unchecked, EmptyMI) ctxt in
725 uctxt { definitions = ctxt' }
737 uctxt { definitions = ctxt' }
727addDatatype :: Datatype Name -> Context -> Context
739addDatatype :: Datatype Name -> Context -> Context
@@ -729,14 +741,14 @@ addDatatype (Data n tag ty cons) uctxt
729 = let ctxt = definitions uctxt
741 = let ctxt = definitions uctxt
730 ty' = normalise uctxt [] ty
742 ty' = normalise uctxt [] ty
731 ctxt' = addCons 0 cons (addDef n
743 ctxt' = addCons 0 cons (addDef n
732− (TyDecl (TCon tag (arity ty')) ty, Public, Unchecked) ctxt) in
744+ (TyDecl (TCon tag (arity ty')) ty, Public, Unchecked, EmptyMI) ctxt) in
733 uctxt { definitions = ctxt' }
745 uctxt { definitions = ctxt' }
735 addCons tag [] ctxt = ctxt
747 addCons tag [] ctxt = ctxt
736 addCons tag ((n, ty) : cons) ctxt
748 addCons tag ((n, ty) : cons) ctxt
737 = let ty' = normalise uctxt [] ty in
749 = let ty' = normalise uctxt [] ty in
738 addCons (tag+1) cons (addDef n
750 addCons (tag+1) cons (addDef n
739− (TyDecl (DCon tag (arity ty')) ty, Public, Unchecked) ctxt)
751+ (TyDecl (DCon tag (arity ty')) ty, Public, Unchecked, EmptyMI) ctxt)
741-- FIXME: Too many arguments! Refactor all these Bools.
753-- FIXME: Too many arguments! Refactor all these Bools.
742addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
754addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
@@ -770,7 +782,7 @@ addCasedef n ci@(CaseInfo alwaysInline tcdict)
770 (args_rt, sc_rt) in
782 (args_rt, sc_rt) in
771 addDef n (CaseOp (ci { case_inlinable = inlc })
783 addDef n (CaseOp (ci { case_inlinable = inlc })
772 ty ps_in ps_tot cdef,
784 ty ps_in ps_tot cdef,
773− access, Unchecked) ctxt in
785+ access, Unchecked, EmptyMI) ctxt in
774 uctxt { definitions = ctxt' }
786 uctxt { definitions = ctxt' }
776-- simplify a definition for totality checking
788-- simplify a definition for totality checking
@@ -778,16 +790,16 @@ simplifyCasedef :: Name -> Context -> Context
778simplifyCasedef n uctxt
790simplifyCasedef n uctxt
779 = let ctxt = definitions uctxt
791 = let ctxt = definitions uctxt
780 ctxt' = case lookupCtxt n ctxt of
792 ctxt' = case lookupCtxt n ctxt of
781− [(CaseOp ci ty [] ps _, acc, tot)] ->
793+ [(CaseOp ci ty [] ps _, acc, tot, metainf)] ->
782 ctxt -- nothing to simplify (or already done...)
794 ctxt -- nothing to simplify (or already done...)
783− [(CaseOp ci ty ps_in ps cd, acc, tot)] ->
795+ [(CaseOp ci ty ps_in ps cd, acc, tot, metainf)] ->
784 let ps_in' = map simpl ps_in
796 let ps_in' = map simpl ps_in
785 pdef = map debind ps_in' in
797 pdef = map debind ps_in' in
786 case simpleCase False True False CompileTime emptyFC pdef of
798 case simpleCase False True False CompileTime emptyFC pdef of
787 OK (CaseDef args sc _) ->
799 OK (CaseDef args sc _) ->
788 addDef n (CaseOp ci
800 addDef n (CaseOp ci
789 ty ps_in' ps (cd { cases_totcheck = (args, sc) }),
801 ty ps_in' ps (cd { cases_totcheck = (args, sc) }),
790− acc, tot) ctxt
802+ acc, tot, metainf) ctxt
791 Error err -> error (show err)
803 Error err -> error (show err)
792 _ -> ctxt in
804 _ -> ctxt in
793 uctxt { definitions = ctxt' }
805 uctxt { definitions = ctxt' }
@@ -807,10 +819,10 @@ addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) ->
807 Context -> Context
819 Context -> Context
808addOperator n ty a op uctxt
820addOperator n ty a op uctxt
809 = let ctxt = definitions uctxt
821 = let ctxt = definitions uctxt
810− ctxt' = addDef n (Operator ty a op, Public, Unchecked) ctxt in
822+ ctxt' = addDef n (Operator ty a op, Public, Unchecked, EmptyMI) ctxt in
811 uctxt { definitions = ctxt' }
823 uctxt { definitions = ctxt' }
813−tfst (a, _, _) = a
825+tfst (a, _, _, _) = a
815lookupNames :: Name -> Context -> [Name]
827lookupNames :: Name -> Context -> [Name]
816lookupNames n ctxt
828lookupNames n ctxt
@@ -856,10 +868,10 @@ lookupP :: Name -> Context -> [Term]
856lookupP n ctxt
868lookupP n ctxt
857 = do def <- lookupCtxt n (definitions ctxt)
869 = do def <- lookupCtxt n (definitions ctxt)
858 p <- case def of
870 p <- case def of
859− (Function ty tm, a, _) -> return (P Ref n ty, a)
871+ (Function ty tm, a, _, _) -> return (P Ref n ty, a)
860− (TyDecl nt ty, a, _) -> return (P nt n ty, a)
872+ (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
861− (CaseOp _ ty _ _ _, a, _) -> return (P Ref n ty, a)
873+ (CaseOp _ ty _ _ _, a, _, _) -> return (P Ref n ty, a)
862− (Operator ty _ _, a, _) -> return (P Ref n ty, a)
874+ (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
863 case snd p of
875 case snd p of
864 Hidden -> []
876 Hidden -> []
865 _ -> return (fst p)
877 _ -> return (fst p)
@@ -872,15 +884,19 @@ lookupDefAcc :: Name -> Bool -> Context ->
872lookupDefAcc n mkpublic ctxt
884lookupDefAcc n mkpublic ctxt
873 = map mkp $ lookupCtxt n (definitions ctxt)
885 = map mkp $ lookupCtxt n (definitions ctxt)
874 -- io_bind a special case for REPL prettiness
886 -- io_bind a special case for REPL prettiness
875− where mkp (d, a, _) = if mkpublic && (not (n == UN "io_bind" || n == UN "io_return"))
887+ where mkp (d, a, _, _) = if mkpublic && (not (n == UN "io_bind" || n == UN "io_return"))
876− then (d, Public) else (d, a)
888+ then (d, Public) else (d, a)
878lookupTotal :: Name -> Context -> [Totality]
890lookupTotal :: Name -> Context -> [Totality]
879lookupTotal n ctxt = map mkt $ lookupCtxt n (definitions ctxt)
891lookupTotal n ctxt = map mkt $ lookupCtxt n (definitions ctxt)
880− where mkt (d, a, t) = t
892+ where mkt (d, a, t, m) = t
894+lookupMetaInformation :: Name -> Context -> [MetaInformation]
895+lookupMetaInformation n ctxt = map mkm $ lookupCtxt n (definitions ctxt)
896+ where mkm (d, a, t, m) = m
882lookupNameTotal :: Name -> Context -> [(Name, Totality)]
898lookupNameTotal :: Name -> Context -> [(Name, Totality)]
883−lookupNameTotal n = map (\(n, (_, _, t)) -> (n, t)) . lookupCtxtName n . definitions
899+lookupNameTotal n = map (\(n, (_, _, t, _)) -> (n, t)) . lookupCtxtName n . definitions
886lookupVal :: Name -> Context -> [Value]
902lookupVal :: Name -> Context -> [Value]