@@ -6,7 +6,8 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
8{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
8{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
9− DeriveDataTypeable, TypeSynonymInstances, PatternGuards #-}
9+ DeriveDataTypeable, DeriveGeneric, TypeSynonymInstances,
11module Idris.AbsSyntaxTree where
12module Idris.AbsSyntaxTree where
@@ -47,6 +48,7 @@ import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
47import Data.Traversable (Traversable)
48import Data.Traversable (Traversable)
48import Data.Typeable
49import Data.Typeable
49import Data.Foldable (Foldable)
50import Data.Foldable (Foldable)
51+import GHC.Generics (Generic)
51import Debug.Trace
53import Debug.Trace
@@ -112,7 +114,7 @@ data IOption = IOption {
112 , opt_evaltypes :: Bool -- ^ normalise types in `:t`
114 , opt_evaltypes :: Bool -- ^ normalise types in `:t`
113 , opt_desugarnats :: Bool
115 , opt_desugarnats :: Bool
114 , opt_autoimpls :: Bool
116 , opt_autoimpls :: Bool
115− } deriving (Show, Eq)
117+ } deriving (Show, Eq, Generic)
117defaultOpts = IOption { opt_logLevel = 0
119defaultOpts = IOption { opt_logLevel = 0
118 , opt_logcats = []
120 , opt_logcats = []
@@ -150,7 +152,7 @@ data PPOption = PPOption {
150 } deriving (Show)
152 } deriving (Show)
152data Optimisation = PETransform -- ^ partial eval and associated transforms
154data Optimisation = PETransform -- ^ partial eval and associated transforms
153− deriving (Show, Eq)
155+ deriving (Show, Eq, Generic)
155defaultOptimise = [PETransform]
157defaultOptimise = [PETransform]
@@ -185,7 +187,8 @@ ppOption opt = PPOption {
185ppOptionIst :: IState -> PPOption
187ppOptionIst :: IState -> PPOption
186ppOptionIst = ppOption . idris_options
188ppOptionIst = ppOption . idris_options
188−data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
190+data LanguageExt = TypeProviders | ErrorReflection
191+ deriving (Show, Eq, Read, Ord, Generic)
190-- | The output mode in use
193-- | The output mode in use
191data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
194data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
@@ -196,13 +199,13 @@ data OutputMode = RawOutput Handle -- ^ Print user output directly to the
196data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
199data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
197 | ColsWide Int -- ^ Manually specified - must be positive
200 | ColsWide Int -- ^ Manually specified - must be positive
198 | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
201 | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
199− deriving (Show, Eq)
202+ deriving (Show, Eq, Generic)
201-- | If a function has no totality annotation, what do we assume?
204-- | If a function has no totality annotation, what do we assume?
202data DefaultTotality = DefaultCheckingTotal -- ^ Total
205data DefaultTotality = DefaultCheckingTotal -- ^ Total
203 | DefaultCheckingPartial -- ^ Partial
206 | DefaultCheckingPartial -- ^ Partial
204 | DefaultCheckingCovering -- ^Total coverage, but may diverge
207 | DefaultCheckingCovering -- ^Total coverage, but may diverge
205− deriving (Show, Eq)
208+ deriving (Show, Eq, Generic)
207-- | The global state used in the Idris monad
210-- | The global state used in the Idris monad
208data IState = IState {
211data IState = IState {
@@ -305,13 +308,14 @@ data IState = IState {
305 , idris_ttstats :: M.Map Term (Int, Term)
308 , idris_ttstats :: M.Map Term (Int, Term)
306 , idris_fragile :: Ctxt String -- ^ Fragile names and explanation.
309 , idris_fragile :: Ctxt String -- ^ Fragile names and explanation.
309-- Required for parsers library, and therefore trifecta
313-- Required for parsers library, and therefore trifecta
310instance Show IState where
314instance Show IState where
311 show = const "{internal state}"
315 show = const "{internal state}"
313data SizeChange = Smaller | Same | Bigger | Unknown
317data SizeChange = Smaller | Same | Bigger | Unknown
314− deriving (Show, Eq)
318+ deriving (Show, Eq, Generic)
316deriving instance Binary SizeChange
320deriving instance Binary SizeChange
317deriving instance NFData SizeChange
321deriving instance NFData SizeChange
@@ -324,7 +328,7 @@ data CGInfo = CGInfo {
324 calls :: [Name]
328 calls :: [Name]
325 , scg :: [SCGEntry]
329 , scg :: [SCGEntry]
326 , usedpos :: [(Int, [UsageReason])]
330 , usedpos :: [(Int, [UsageReason])]
327− } deriving Show
331+ } deriving (Show, Generic)
329deriving instance Binary CGInfo
333deriving instance Binary CGInfo
330deriving instance NFData CGInfo
334deriving instance NFData CGInfo
@@ -384,7 +388,7 @@ data IBCWrite = IBCFix FixDecl
384 | IBCDeprecate Name String
388 | IBCDeprecate Name String
385 | IBCFragile Name String
389 | IBCFragile Name String
386 | IBCConstraint FC UConstraint
390 | IBCConstraint FC UConstraint
387− deriving Show
391+ deriving (Show, Generic)
389-- | The initial state for the compiler
393-- | The initial state for the compiler
390idrisInit :: IState
394idrisInit :: IState
@@ -420,12 +424,12 @@ throwError = Trans.lift . throwE
421data Codegen = Via IRFormat String
425data Codegen = Via IRFormat String
422 | Bytecode
426 | Bytecode
423− deriving (Show, Eq)
427+ deriving (Show, Eq, Generic)
425deriving instance NFData Codegen
429deriving instance NFData Codegen
428−data IRFormat = IBCFormat | JSONFormat deriving (Show, Eq)
432+data IRFormat = IBCFormat | JSONFormat deriving (Show, Eq, Generic)
430data HowMuchDocs = FullDocs | OverviewDocs
434data HowMuchDocs = FullDocs | OverviewDocs
@@ -511,7 +515,7 @@ data LogCat = IParse
511 | IErasure
515 | IErasure
512 | ICoverage
516 | ICoverage
514− deriving (Show, Eq, Ord)
518+ deriving (Show, Eq, Ord, Generic)
516strLogCat :: LogCat -> String
520strLogCat :: LogCat -> String
517strLogCat IParse = "parser"
521strLogCat IParse = "parser"
@@ -606,7 +610,7 @@ data Opt = Filename String
606 | DesugarNats
610 | DesugarNats
607 | NoElimDeprecationWarnings -- ^ Don't show deprecation warnings for %elim
611 | NoElimDeprecationWarnings -- ^ Don't show deprecation warnings for %elim
608 | NoOldTacticDeprecationWarnings -- ^ Don't show deprecation warnings for old-style tactics
612 | NoOldTacticDeprecationWarnings -- ^ Don't show deprecation warnings for old-style tactics
609− deriving (Show, Eq)
613+ deriving (Show, Eq, Generic)
611data ElabShellCmd = EQED
615data ElabShellCmd = EQED
612 | EAbandon
616 | EAbandon
@@ -625,7 +629,7 @@ data Fixity = Infixl { prec :: Int }
625 | Infixr { prec :: Int }
629 | Infixr { prec :: Int }
626 | InfixN { prec :: Int }
630 | InfixN { prec :: Int }
627 | PrefixN { prec :: Int }
631 | PrefixN { prec :: Int }
628− deriving Eq
632+ deriving (Eq, Generic)
630deriving instance Binary Fixity
634deriving instance Binary Fixity
631deriving instance NFData Fixity
635deriving instance NFData Fixity
@@ -638,7 +642,7 @@ instance Show Fixity where
638 show (PrefixN i) = "prefix " ++ show i
642 show (PrefixN i) = "prefix " ++ show i
640data FixDecl = Fix Fixity String
644data FixDecl = Fix Fixity String
641− deriving Eq
645+ deriving (Eq, Generic)
643instance Show FixDecl where
647instance Show FixDecl where
644 show (Fix f s) = show f ++ " " ++ s
648 show (Fix f s) = show f ++ " " ++ s
@@ -653,7 +657,7 @@ instance Ord FixDecl where
655data Static = Static | Dynamic
659data Static = Static | Dynamic
656− deriving (Show, Eq, Data, Typeable)
660+ deriving (Show, Eq, Data, Generic, Typeable)
658deriving instance Binary Static
662deriving instance Binary Static
659deriving instance NFData Static
663deriving instance NFData Static
@@ -677,7 +681,7 @@ data Plicity = Imp { pargopts :: [ArgOpt]
677 , pstatic :: Static
681 , pstatic :: Static
678 , pscript :: PTerm
682 , pscript :: PTerm
680− deriving (Show, Eq, Data, Typeable)
684+ deriving (Show, Eq, Data, Generic, Typeable)
683deriving instance Binary Plicity
687deriving instance Binary Plicity
@@ -721,7 +725,7 @@ data FnOpt = Inlinable -- ^ always evaluate when simplifying
721 | Constructor -- ^ Data constructor type
725 | Constructor -- ^ Data constructor type
722 | AutoHint -- ^ use in auto implicit search
726 | AutoHint -- ^ use in auto implicit search
723 | PEGenerated -- ^ generated by partial evaluator
727 | PEGenerated -- ^ generated by partial evaluator
724− deriving (Show, Eq)
728+ deriving (Show, Eq, Generic)
726deriving instance Binary FnOpt
730deriving instance Binary FnOpt
727deriving instance NFData FnOpt
731deriving instance NFData FnOpt
@@ -739,7 +743,7 @@ dictionary = elem Dictionary
739-- | Type provider - what to provide
743-- | Type provider - what to provide
740data ProvideWhat' t = ProvTerm t t -- ^ the first is the goal type, the second is the term
744data ProvideWhat' t = ProvTerm t t -- ^ the first is the goal type, the second is the term
741 | ProvPostulate t -- ^ goal type must be Type, so only term
745 | ProvPostulate t -- ^ goal type must be Type, so only term
742− deriving (Show, Eq, Functor)
746+ deriving (Show, Eq, Functor, Generic)
744type ProvideWhat = ProvideWhat' PTerm
748type ProvideWhat = ProvideWhat' PTerm
@@ -824,7 +828,7 @@ data PDecl' t
824 -- | FC is decl-level, for errors, and Strings represent the
828 -- | FC is decl-level, for errors, and Strings represent the
825 -- namespace
829 -- namespace
826 | PRunElabDecl FC t [String]
830 | PRunElabDecl FC t [String]
827− deriving Functor
831+ deriving (Functor, Generic)
829deriving instance Binary PDecl'
833deriving instance Binary PDecl'
830deriving instance NFData PDecl'
834deriving instance NFData PDecl'
@@ -851,6 +855,7 @@ data Directive = DLib Codegen String
851 | DFragile Name String
855 | DFragile Name String
852 | DAutoImplicits Bool
856 | DAutoImplicits Bool
853 | DUsed FC Name Name
857 | DUsed FC Name Name
855-- | A set of instructions for things that need to happen in IState
860-- | A set of instructions for things that need to happen in IState
856-- after a term elaboration when there's been reflected elaboration.
861-- after a term elaboration when there's been reflected elaboration.
@@ -895,7 +900,7 @@ data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A
895 | PWith FC Name t [t] t (Maybe (Name, FC)) [PDecl' t]
900 | PWith FC Name t [t] t (Maybe (Name, FC)) [PDecl' t]
896 | PClauseR FC [t] t [PDecl' t]
901 | PClauseR FC [t] t [PDecl' t]
897 | PWithR FC [t] t (Maybe (Name, FC)) [PDecl' t]
902 | PWithR FC [t] t (Maybe (Name, FC)) [PDecl' t]
898− deriving Functor
903+ deriving (Functor, Generic)
900deriving instance Binary PClause'
905deriving instance Binary PClause'
901deriving instance NFData PClause'
906deriving instance NFData PClause'
@@ -913,7 +918,7 @@ data PData' t =
913 | PLaterdecl { d_name :: Name
918 | PLaterdecl { d_name :: Name
914 , d_name_fc :: FC
919 , d_name_fc :: FC
915 , d_tcon :: t
920 , d_tcon :: t
916− } deriving Functor
921+ } deriving (Functor, Generic)
918-- | Transform the FCs in a PData and its associated terms. The first
923-- | Transform the FCs in a PData and its associated terms. The first
919-- function transforms the general-purpose FCs, and the second
924-- function transforms the general-purpose FCs, and the second
@@ -1103,7 +1108,7 @@ updateNs ns t = mapPT updateRef t
1103data PunInfo = IsType
1108data PunInfo = IsType
1104 | IsTerm
1109 | IsTerm
1105 | TypeOrTerm
1110 | TypeOrTerm
1106− deriving (Eq, Show, Data, Typeable)
1111+ deriving (Eq, Show, Data, Typeable, Generic)
1108-- | High level language terms
1113-- | High level language terms
1109data PTerm = PQuote Raw -- ^ Inclusion of a core term into the
1114data PTerm = PQuote Raw -- ^ Inclusion of a core term into the
@@ -1170,12 +1175,12 @@ data PTerm = PQuote Raw -- ^ Inclusion of a core term into the
1170 | PConstSugar FC PTerm
1175 | PConstSugar FC PTerm
1171 -- ^ A desugared constant. The FC is a precise source
1176 -- ^ A desugared constant. The FC is a precise source
1172 -- location that will be used to highlight it later.
1177 -- location that will be used to highlight it later.
1173− deriving (Eq, Data, Typeable)
1178+ deriving (Eq, Data, Typeable, Generic)
1175data PAltType = ExactlyOne Bool -- ^ flag sets whether delay is allowed
1180data PAltType = ExactlyOne Bool -- ^ flag sets whether delay is allowed
1176 | FirstSuccess
1181 | FirstSuccess
1177 | TryImplicit
1182 | TryImplicit
1178− deriving (Eq, Data, Typeable)
1183+ deriving (Eq, Data, Generic, Typeable)
1180-- | Transform the FCs in a PTerm. The first function transforms the
1185-- | Transform the FCs in a PTerm. The first function transforms the
1181-- general-purpose FCs, and the second transforms those that are used
1186-- general-purpose FCs, and the second transforms those that are used
@@ -1296,7 +1301,7 @@ data PTactic' t = Intro [Name] | Intros | Focus Name
1296 | TFail [ErrorReportPart]
1301 | TFail [ErrorReportPart]
1297 | Qed | Abandon
1302 | Qed | Abandon
1298 | SourceFC
1303 | SourceFC
1299− deriving (Show, Eq, Functor, Foldable, Traversable, Data, Typeable)
1304+ deriving (Show, Eq, Functor, Foldable, Traversable, Data, Generic, Typeable)
1301deriving instance Binary PTactic'
1306deriving instance Binary PTactic'
1302deriving instance NFData PTactic'
1307deriving instance NFData PTactic'
@@ -1343,7 +1348,7 @@ data PDo' t = DoExp FC t
1343 | DoBindP FC t t [(t,t)]
1348 | DoBindP FC t t [(t,t)]
1344 | DoLet FC Name FC t t -- ^ second FC is precise name location
1349 | DoLet FC Name FC t t -- ^ second FC is precise name location
1345 | DoLetP FC t t
1350 | DoLetP FC t t
1346− deriving (Eq, Functor, Data, Typeable)
1351+ deriving (Eq, Functor, Data, Generic, Typeable)
1348deriving instance Binary PDo'
1353deriving instance Binary PDo'
1349deriving instance NFData PDo'
1354deriving instance NFData PDo'
@@ -1384,13 +1389,13 @@ data PArg' t = PImp { priority :: Int
1384 , getScript :: t
1389 , getScript :: t
1385 , getTm :: t
1390 , getTm :: t
1387− deriving (Show, Eq, Functor, Data, Typeable)
1392+ deriving (Show, Eq, Functor, Data, Generic, Typeable)
1389data ArgOpt = AlwaysShow
1394data ArgOpt = AlwaysShow
1390 | HideDisplay
1395 | HideDisplay
1391 | InaccessibleArg
1396 | InaccessibleArg
1392 | UnknownImp
1397 | UnknownImp
1393− deriving (Show, Eq, Data, Typeable)
1398+ deriving (Show, Eq, Data, Generic, Typeable)
1395instance Sized a => Sized (PArg' a) where
1400instance Sized a => Sized (PArg' a) where
1396 size (PImp p _ l nm trm) = 1 + size nm + size trm
1401 size (PImp p _ l nm trm) = 1 + size nm + size trm
@@ -1480,7 +1485,7 @@ data ClassInfo = CI {
1480 , class_params :: [Name]
1485 , class_params :: [Name]
1481 , class_instances :: [(Name, Bool)] -- ^ the Bool is whether to include in instance search, so named instances are excluded
1486 , class_instances :: [(Name, Bool)] -- ^ the Bool is whether to include in instance search, so named instances are excluded
1482 , class_determiners :: [Int]
1487 , class_determiners :: [Int]
1483− } deriving Show
1488+ } deriving (Show, Generic)
1485deriving instance Binary ClassInfo
1490deriving instance Binary ClassInfo
1486deriving instance NFData ClassInfo
1491deriving instance NFData ClassInfo
@@ -1491,17 +1496,17 @@ data RecordInfo = RI {
1491 record_parameters :: [(Name,PTerm)]
1496 record_parameters :: [(Name,PTerm)]
1492 , record_constructor :: Name
1497 , record_constructor :: Name
1493 , record_projections :: [Name]
1498 , record_projections :: [Name]
1494− } deriving Show
1499+ } deriving (Show, Generic)
1496-- Type inference data
1501-- Type inference data
1498data TIData = TIPartial -- ^ a function with a partially defined type
1503data TIData = TIPartial -- ^ a function with a partially defined type
1499 | TISolution [Term] -- ^ possible solutions to a metavariable in a type
1504 | TISolution [Term] -- ^ possible solutions to a metavariable in a type
1500− deriving Show
1505+ deriving (Show, Generic)
1502-- | Miscellaneous information about functions
1507-- | Miscellaneous information about functions
1503data FnInfo = FnInfo { fn_params :: [Int] }
1508data FnInfo = FnInfo { fn_params :: [Int] }
1504− deriving Show
1509+ deriving (Show, Generic)
1506deriving instance Binary FnInfo
1511deriving instance Binary FnInfo
1507deriving instance NFData FnInfo
1512deriving instance NFData FnInfo
@@ -1510,7 +1515,7 @@ deriving instance NFData FnInfo
1510data OptInfo = Optimise {
1515data OptInfo = Optimise {
1511 inaccessible :: [(Int,Name)] -- includes names for error reporting
1516 inaccessible :: [(Int,Name)] -- includes names for error reporting
1512 , detaggable :: Bool
1517 , detaggable :: Bool
1513− } deriving Show
1518+ } deriving (Show, Generic)
1515deriving instance Binary OptInfo
1520deriving instance Binary OptInfo
1516deriving instance NFData OptInfo
1521deriving instance NFData OptInfo
@@ -1528,7 +1533,7 @@ data DSL' t = DSL {
1528 , dsl_lambda :: Maybe t
1533 , dsl_lambda :: Maybe t
1529 , dsl_let :: Maybe t
1534 , dsl_let :: Maybe t
1530 , dsl_pi :: Maybe t
1535 , dsl_pi :: Maybe t
1531− } deriving (Show, Functor)
1536+ } deriving (Show, Functor, Generic)
1533deriving instance Binary DSL'
1538deriving instance Binary DSL'
1534deriving instance NFData DSL'
1539deriving instance NFData DSL'
@@ -1539,7 +1544,7 @@ type DSL = DSL' PTerm
1539data SynContext = PatternSyntax
1544data SynContext = PatternSyntax
1540 | TermSyntax
1545 | TermSyntax
1541 | AnySyntax
1546 | AnySyntax
1542− deriving Show
1547+ deriving (Show, Generic)
1544deriving instance Binary SynContext
1549deriving instance Binary SynContext
1545deriving instance NFData SynContext
1550deriving instance NFData SynContext
@@ -1547,7 +1552,7 @@ deriving instance NFData SynContext
1548data Syntax = Rule [SSymbol] PTerm SynContext
1553data Syntax = Rule [SSymbol] PTerm SynContext
1549 | DeclRule [SSymbol] [PDecl]
1554 | DeclRule [SSymbol] [PDecl]
1550− deriving Show
1555+ deriving (Show, Generic)
1552syntaxNames :: Syntax -> [Name]
1557syntaxNames :: Syntax -> [Name]
1553syntaxNames (Rule syms _ _) = mapMaybe ename syms
1558syntaxNames (Rule syms _ _) = mapMaybe ename syms
@@ -1570,7 +1575,7 @@ data SSymbol = Keyword Name
1570 | Binding Name
1575 | Binding Name
1571 | Expr Name
1576 | Expr Name
1572 | SimpleExpr Name
1577 | SimpleExpr Name
1573− deriving (Show, Eq)
1578+ deriving (Show, Eq, Generic)
@@ -1579,6 +1584,7 @@ deriving instance NFData SSymbol
1581newtype SyntaxRules = SyntaxRules { syntaxRulesList :: [Syntax] }
1586newtype SyntaxRules = SyntaxRules { syntaxRulesList :: [Syntax] }
1583emptySyntaxRules :: SyntaxRules
1589emptySyntaxRules :: SyntaxRules
1584emptySyntaxRules = SyntaxRules []
1590emptySyntaxRules = SyntaxRules []
@@ -1632,7 +1638,7 @@ initDSL = DSL (PRef f [] (sUN ">>="))
1633data Using = UImplicit Name PTerm
1639data Using = UImplicit Name PTerm
1634 | UConstraint Name [Name]
1640 | UConstraint Name [Name]
1635− deriving (Show, Eq, Data, Typeable)
1641+ deriving (Show, Eq, Data, Generic, Typeable)
1637deriving instance Binary Using
1643deriving instance Binary Using
1638deriving instance NFData Using
1644deriving instance NFData Using
@@ -1656,7 +1662,7 @@ data SyntaxInfo = Syn {
1656 , syn_in_quasiquote :: Int
1662 , syn_in_quasiquote :: Int
1657 , syn_toplevel :: Bool
1663 , syn_toplevel :: Bool
1658 , withAppAllowed :: Bool
1664 , withAppAllowed :: Bool
1659− } deriving Show
1665+ } deriving (Show, Generic)
1661deriving instance NFData SyntaxInfo
1667deriving instance NFData SyntaxInfo
1662deriving instance Binary SyntaxInfo
1668deriving instance Binary SyntaxInfo