@@ -4,12 +4,12 @@
44module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC, normaliseAll,
55 rt_simplify, simplify, specialise, hnf, convEq, convEq',
66 Def(..), CaseInfo(..), CaseDefs(..),
7− Accessibility(..), Totality(..), PReason(..),
7+ Accessibility(..), Totality(..), PReason(..), MetaInformation(..),
88 Context, initContext, ctxtAlist, uconstraints, next_tvar,
9− addToCtxt, setAccess, setTotal, addCtxtDef, addTyDecl,
9+ addToCtxt, setAccess, setTotal, setMetaInformation, addCtxtDef, addTyDecl,
1010 addDatatype, addCasedef, simplifyCasedef, addOperator,
1111 lookupNames, lookupTy, lookupP, lookupDef, lookupDefAcc, lookupVal,
12− lookupTotal, lookupNameTotal, lookupTyEnv, isDConName, isTConName, isConName, isFnName,
12+ lookupTotal, lookupNameTotal, lookupMetaInformation, lookupTyEnv, isDConName, isTConName, isConName, isFnName,
1313 Value(..), Quote(..), initEval) where
1414
1515import Debug.Trace
@@ -678,12 +678,18 @@ deriving instance Binary Totality
678678deriving instance Binary PReason
679679!-}
680680
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
685+ deriving (Eq, Show)
686+
681687-- | Contexts used for global definitions and for proof state. They contain
682688-- universe constraints and existing definitions.
683689data Context = MkContext {
684− uconstraints :: [UConstraint],
685− next_tvar :: Int,
686− definitions :: Ctxt (Def, Accessibility, Totality)
690+ uconstraints :: [UConstraint],
691+ next_tvar :: Int,
692+ definitions :: Ctxt (Def, Accessibility, Totality, MetaInformation)
687693 } deriving Show
688694
689695-- | The initial empty context
@@ -691,37 +697,43 @@ initContext = MkContext [] 0 emptyContext
691697
692698-- | Get the definitions from a context
693699ctxtAlist :: 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)
695701
696702veval ctxt env t = evalState (eval False ctxt [] env t []) initEval
697703
698704addToCtxt :: Name -> Term -> Type -> Context -> Context
699705addToCtxt n tm ty uctxt
700706 = 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
702708 uctxt { definitions = ctxt' }
703709
704710setAccess :: Name -> Accessibility -> Context -> Context
705711setAccess n a uctxt
706712 = 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
708714 uctxt { definitions = ctxt' }
709715
710716setTotal :: Name -> Totality -> Context -> Context
711717setTotal n t uctxt
712718 = 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' }
721+
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
714726 uctxt { definitions = ctxt' }
715727
716728addCtxtDef :: Name -> Def -> Context -> Context
717729addCtxtDef 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
719731 c { definitions = ctxt' }
720732
721733addTyDecl :: Name -> NameType -> Type -> Context -> Context
722734addTyDecl n nt ty uctxt
723735 = 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
725737 uctxt { definitions = ctxt' }
726738
727739addDatatype :: Datatype Name -> Context -> Context
@@ -729,14 +741,14 @@ addDatatype (Data n tag ty cons) uctxt
729741 = let ctxt = definitions uctxt
730742 ty' = normalise uctxt [] ty
731743 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
733745 uctxt { definitions = ctxt' }
734746 where
735747 addCons tag [] ctxt = ctxt
736748 addCons tag ((n, ty) : cons) ctxt
737749 = let ty' = normalise uctxt [] ty in
738750 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)
740752
741753-- FIXME: Too many arguments! Refactor all these Bools.
742754addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
@@ -770,7 +782,7 @@ addCasedef n ci@(CaseInfo alwaysInline tcdict)
770782 (args_rt, sc_rt) in
771783 addDef n (CaseOp (ci { case_inlinable = inlc })
772784 ty ps_in ps_tot cdef,
773− access, Unchecked) ctxt in
785+ access, Unchecked, EmptyMI) ctxt in
774786 uctxt { definitions = ctxt' }
775787
776788-- simplify a definition for totality checking
@@ -778,16 +790,16 @@ simplifyCasedef :: Name -> Context -> Context
778790simplifyCasedef n uctxt
779791 = let ctxt = definitions uctxt
780792 ctxt' = case lookupCtxt n ctxt of
781− [(CaseOp ci ty [] ps _, acc, tot)] ->
793+ [(CaseOp ci ty [] ps _, acc, tot, metainf)] ->
782794 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)] ->
784796 let ps_in' = map simpl ps_in
785797 pdef = map debind ps_in' in
786798 case simpleCase False True False CompileTime emptyFC pdef of
787799 OK (CaseDef args sc _) ->
788800 addDef n (CaseOp ci
789801 ty ps_in' ps (cd { cases_totcheck = (args, sc) }),
790− acc, tot) ctxt
802+ acc, tot, metainf) ctxt
791803 Error err -> error (show err)
792804 _ -> ctxt in
793805 uctxt { definitions = ctxt' }
@@ -807,10 +819,10 @@ addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) ->
807819 Context -> Context
808820addOperator n ty a op uctxt
809821 = 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
811823 uctxt { definitions = ctxt' }
812824
813−tfst (a, _, _) = a
825+tfst (a, _, _, _) = a
814826
815827lookupNames :: Name -> Context -> [Name]
816828lookupNames n ctxt
@@ -856,10 +868,10 @@ lookupP :: Name -> Context -> [Term]
856868lookupP n ctxt
857869 = do def <- lookupCtxt n (definitions ctxt)
858870 p <- case def of
859− (Function ty tm, a, _) -> return (P Ref n ty, a)
860− (TyDecl nt ty, a, _) -> return (P nt n ty, a)
861− (CaseOp _ ty _ _ _, a, _) -> return (P Ref n ty, a)
862− (Operator ty _ _, a, _) -> return (P Ref n ty, a)
871+ (Function ty tm, a, _, _) -> return (P Ref n ty, a)
872+ (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
873+ (CaseOp _ ty _ _ _, a, _, _) -> return (P Ref n ty, a)
874+ (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
863875 case snd p of
864876 Hidden -> []
865877 _ -> return (fst p)
@@ -872,15 +884,19 @@ lookupDefAcc :: Name -> Bool -> Context ->
872884lookupDefAcc n mkpublic ctxt
873885 = map mkp $ lookupCtxt n (definitions ctxt)
874886 -- io_bind a special case for REPL prettiness
875− where mkp (d, a, _) = if mkpublic && (not (n == UN "io_bind" || n == UN "io_return"))
876− then (d, Public) else (d, a)
887+ where mkp (d, a, _, _) = if mkpublic && (not (n == UN "io_bind" || n == UN "io_return"))
888+ then (d, Public) else (d, a)
877889
878890lookupTotal :: Name -> Context -> [Totality]
879891lookupTotal n ctxt = map mkt $ lookupCtxt n (definitions ctxt)
880− where mkt (d, a, t) = t
892+ where mkt (d, a, t, m) = t
893+
894+lookupMetaInformation :: Name -> Context -> [MetaInformation]
895+lookupMetaInformation n ctxt = map mkm $ lookupCtxt n (definitions ctxt)
896+ where mkm (d, a, t, m) = m
881897
882898lookupNameTotal :: 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
884900
885901
886902lookupVal :: Name -> Context -> [Value]