on da45e7d help sign in
Idris-dev/src/Idris/AbsSyntaxTree.hs
1672 lines 66 kB history raw
1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
6import Idris.Core.TT
7import Idris.Core.Evaluate
8import Idris.Core.Elaborate hiding (Tactic(..))
9import Idris.Core.Typecheck
10import Idris.Docstrings
11import IRTS.Lang
12import IRTS.CodegenCommon
13import Util.Pretty
14import Util.DynamicLinker
16import Idris.Colours
18import Paths_idris
20import System.Console.Haskeline
21import System.IO
23import Control.Monad.Trans.State.Strict
24import Control.Monad.Trans.Error
26import Data.List hiding (group)
27import Data.Char
28import qualified Data.Map as M
29import qualified Data.Text as T
30import qualified Data.Map as M
31import Data.Either
32import qualified Data.Set as S
33import Data.Word (Word)
34import Data.Maybe (fromMaybe)
36import Debug.Trace
38import Text.PrettyPrint.Annotated.Leijen
40-- Data to pass to recursively called elaborators; e.g. for where blocks,
41-- paramaterised declarations, etc.
43data ElabInfo = EInfo { params :: [(Name, PTerm)],
44 inblock :: Ctxt [Name], -- names in the block, and their params
45 liftname :: Name -> Name,
46 namespace :: Maybe [String] }
48toplevel = EInfo [] emptyContext id Nothing
50eInfoNames :: ElabInfo -> [Name]
51eInfoNames info = map fst (params info) ++ M.keys (inblock info)
53data IOption = IOption { opt_logLevel :: Int,
54 opt_typecase :: Bool,
55 opt_typeintype :: Bool,
56 opt_coverage :: Bool,
57 opt_showimp :: Bool, -- ^^ show implicits
58 opt_errContext :: Bool,
59 opt_repl :: Bool,
60 opt_verbose :: Bool,
61 opt_nobanner :: Bool,
62 opt_quiet :: Bool,
63 opt_codegen :: Codegen,
64 opt_outputTy :: OutputType,
65 opt_ibcsubdir :: FilePath,
66 opt_importdirs :: [FilePath],
67 opt_triple :: String,
68 opt_cpu :: String,
69 opt_optLevel :: Word,
70 opt_cmdline :: [Opt], -- remember whole command line
71 opt_origerr :: Bool,
72 opt_autoSolve :: Bool -- ^ automatically apply "solve" tactic in prover
73 }
74 deriving (Show, Eq)
76defaultOpts = IOption { opt_logLevel = 0
77 , opt_typecase = False
78 , opt_typeintype = False
79 , opt_coverage = True
80 , opt_showimp = False
81 , opt_errContext = False
82 , opt_repl = True
83 , opt_verbose = True
84 , opt_nobanner = False
85 , opt_quiet = False
86 , opt_codegen = ViaC
87 , opt_outputTy = Executable
88 , opt_ibcsubdir = ""
89 , opt_importdirs = []
90 , opt_triple = ""
91 , opt_cpu = ""
92 , opt_optLevel = 2
93 , opt_cmdline = []
94 , opt_origerr = False
95 , opt_autoSolve = True
96 }
98data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
100-- | The output mode in use
101data OutputMode = RawOutput | IdeSlave Integer deriving Show
103-- | How wide is the console?
104data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
105 | ColsWide Int -- ^ Manually specified - must be positive
106 | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
108-- | The global state used in the Idris monad
109data IState = IState {
110 tt_ctxt :: Context, -- ^ All the currently defined names and their terms
111 idris_constraints :: [(UConstraint, FC)],
112 -- ^ A list of universe constraints and their corresponding source locations
113 idris_infixes :: [FixDecl], -- ^ Currently defined infix operators
114 idris_implicits :: Ctxt [PArg],
115 idris_statics :: Ctxt [Bool],
116 idris_classes :: Ctxt ClassInfo,
117 idris_dsls :: Ctxt DSL,
118 idris_optimisation :: Ctxt OptInfo,
119 idris_datatypes :: Ctxt TypeInfo,
120 idris_namehints :: Ctxt [Name],
121 idris_patdefs :: Ctxt ([([Name], Term, Term)], [PTerm]), -- not exported
122 -- ^ list of lhs/rhs, and a list of missing clauses
123 idris_flags :: Ctxt [FnOpt],
124 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
125 idris_calledgraph :: Ctxt [Name],
126 idris_docstrings :: Ctxt (Docstring, [(Name, Docstring)]),
127 idris_tyinfodata :: Ctxt TIData,
128 idris_totcheck :: [(FC, Name)], -- names to check totality on
129 idris_defertotcheck :: [(FC, Name)], -- names to check at the end
130 idris_options :: IOption,
131 idris_name :: Int,
132 idris_lineapps :: [((FilePath, Int), PTerm)],
133 -- ^ Full application LHS on source line
134 idris_metavars :: [(Name, (Maybe Name, Int, Bool))], -- ^ The currently defined but not proven metavariables
135 idris_coercions :: [Name],
136 idris_transforms :: [(Term, Term)],
137 idris_errRev :: [(Term, Term)],
138 syntax_rules :: [Syntax],
139 syntax_keywords :: [String],
140 imported :: [FilePath], -- ^ The imported modules
141 idris_scprims :: [(Name, (Int, PrimFn))],
142 idris_objs :: [(Codegen, FilePath)],
143 idris_libs :: [(Codegen, String)],
144 idris_cgflags :: [(Codegen, String)],
145 idris_hdrs :: [(Codegen, String)],
146 idris_imported :: [FilePath], -- ^ Imported ibc file names
147 proof_list :: [(Name, [String])],
148 errSpan :: Maybe FC,
149 parserWarnings :: [(FC, Err)],
150 lastParse :: Maybe Name,
151 indent_stack :: [Int],
152 brace_stack :: [Maybe Int],
153 lastTokenSpan :: Maybe FC, -- ^ What was the span of the latest token parsed?
154 hide_list :: [(Name, Maybe Accessibility)],
155 default_access :: Accessibility,
156 default_total :: Bool,
157 ibc_write :: [IBCWrite],
158 compiled_so :: Maybe String,
159 idris_dynamic_libs :: [DynamicLib],
160 idris_language_extensions :: [LanguageExt],
161 idris_outputmode :: OutputMode,
162 idris_colourRepl :: Bool,
163 idris_colourTheme :: ColourTheme,
164 idris_outh :: Handle,
165 idris_errorhandlers :: [Name], -- ^ Global error handlers
166 idris_nameIdx :: (Int, Ctxt (Int, Name)),
167 idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)), -- ^ Specific error handlers
168 module_aliases :: M.Map [T.Text] [T.Text],
169 idris_consolewidth :: ConsoleWidth, -- ^ How many chars wide is the console?
170 idris_postulates :: S.Set Name,
171 idris_whocalls :: Maybe (M.Map Name [Name]),
172 idris_callswho :: Maybe (M.Map Name [Name])
173 }
175data SizeChange = Smaller | Same | Bigger | Unknown
176 deriving (Show, Eq)
177{-!
178deriving instance Binary SizeChange
179deriving instance NFData SizeChange
180!-}
182type SCGEntry = (Name, [Maybe (Int, SizeChange)])
183type UsageReason = (Name, Int) -- fn_name, its_arg_number
185data CGInfo = CGInfo { argsdef :: [Name],
186 calls :: [(Name, [[Name]])],
187 scg :: [SCGEntry],
188 argsused :: [Name],
189 usedpos :: [(Int, [UsageReason])] }
190 deriving Show
191{-!
192deriving instance Binary CGInfo
193deriving instance NFData CGInfo
194!-}
196primDefs = [sUN "unsafePerformPrimIO",
197 sUN "mkLazyForeignPrim",
198 sUN "mkForeignPrim",
199 sUN "FalseElim"]
201-- information that needs writing for the current module's .ibc file
202data IBCWrite = IBCFix FixDecl
203 | IBCImp Name
204 | IBCStatic Name
205 | IBCClass Name
206 | IBCInstance Bool Name Name
207 | IBCDSL Name
208 | IBCData Name
209 | IBCOpt Name
210 | IBCMetavar Name
211 | IBCSyntax Syntax
212 | IBCKeyword String
213 | IBCImport FilePath
214 | IBCObj Codegen FilePath
215 | IBCLib Codegen String
216 | IBCCGFlag Codegen String
217 | IBCDyLib String
218 | IBCHeader Codegen String
219 | IBCAccess Name Accessibility
220 | IBCMetaInformation Name MetaInformation
221 | IBCTotal Name Totality
222 | IBCFlags Name [FnOpt]
223 | IBCTrans (Term, Term)
224 | IBCErrRev (Term, Term)
225 | IBCCG Name
226 | IBCDoc Name
227 | IBCCoercion Name
228 | IBCDef Name -- i.e. main context
229 | IBCNameHint (Name, Name)
230 | IBCLineApp FilePath Int PTerm
231 | IBCErrorHandler Name
232 | IBCFunctionErrorHandler Name Name Name
233 | IBCPostulate Name
234 deriving Show
236-- | The initial state for the compiler
237idrisInit :: IState
238idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
239 emptyContext emptyContext emptyContext emptyContext
240 emptyContext emptyContext emptyContext emptyContext
241 emptyContext emptyContext
242 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
243 [] [] Nothing [] Nothing [] [] Nothing [] Hidden False [] Nothing [] [] RawOutput
244 True defaultTheme stdout [] (0, emptyContext) emptyContext M.empty
245 AutomaticWidth S.empty Nothing Nothing
247-- | The monad for the main REPL - reading and processing files and updating
248-- global state (hence the IO inner monad).
249--type Idris = WriterT [Either String (IO ())] (State IState a))
250type Idris = StateT IState (ErrorT Err IO)
252-- Commands in the REPL
254data Codegen = ViaC
255 | ViaJava
256 | ViaNode
257 | ViaJavaScript
258 | ViaLLVM
259 | Bytecode
260 deriving (Show, Eq)
262-- | REPL commands
263data Command = Quit
264 | Help
265 | Eval PTerm
266 | Check PTerm
267 | DocStr Name
268 | TotCheck Name
269 | Reload
270 | Load FilePath
271 | ChangeDirectory FilePath
272 | ModImport String
273 | Edit
274 | Compile Codegen String
275 | Execute
276 | ExecVal PTerm
277 | Metavars
278 | Prove Name
279 | AddProof (Maybe Name)
280 | RmProof Name
281 | ShowProof Name
282 | Proofs
283 | Universes
284 | LogLvl Int
285 | Spec PTerm
286 | HNF PTerm
287 | TestInline PTerm
288 | Defn Name
289 | Missing Name
290 | DynamicLink FilePath
291 | ListDynamic
292 | Pattelab PTerm
293 | DebugInfo Name
294 | Search PTerm
295 | CaseSplitAt Bool Int Name
296 | AddClauseFrom Bool Int Name
297 | AddProofClauseFrom Bool Int Name
298 | AddMissing Bool Int Name
299 | MakeWith Bool Int Name
300 | DoProofSearch Bool -- ^ update
301 Bool -- ^ recursive (i.e. do arguments too)
302 Int Name [Name]
303 | SetOpt Opt
304 | UnsetOpt Opt
305 | NOP
306 | SetColour ColourType IdrisColour
307 | ColourOn
308 | ColourOff
309 | ListErrorHandlers
310 | SetConsoleWidth ConsoleWidth
311 | Apropos String
312 | WhoCalls Name
313 | CallsWho Name
314 | MakeDoc String -- IdrisDoc
317data Opt = Filename String
318 | Ver
319 | Usage
320 | Quiet
321 | NoBanner
322 | ColourREPL Bool
323 | Ideslave
324 | ShowLibs
325 | ShowLibdir
326 | ShowIncs
327 | NoBasePkgs
328 | NoPrelude
329 | NoBuiltins -- only for the really primitive stuff!
330 | NoREPL
331 | OLogging Int
332 | Output String
333 | TypeCase
334 | TypeInType
335 | DefaultTotal
336 | DefaultPartial
337 | WarnPartial
338 | WarnReach
339 | NoCoverage
340 | ErrContext
341 | ShowImpl
342 | Verbose
343 | IBCSubDir String
344 | ImportDir String
345 | PkgBuild String
346 | PkgInstall String
347 | PkgClean String
348 | PkgCheck String
349 | PkgREPL String
350 | PkgMkDoc String -- IdrisDoc
351 | WarnOnly
352 | Pkg String
353 | BCAsm String
354 | DumpDefun String
355 | DumpCases String
356 | UseCodegen Codegen
357 | OutputTy OutputType
358 | Extension LanguageExt
359 | InterpretScript String
360 | EvalExpr String
361 | TargetTriple String
362 | TargetCPU String
363 | OptLevel Word
364 | Client String
365 | ShowOrigErr
366 | AutoWidth -- ^ Automatically adjust terminal width
367 | AutoSolve -- ^ Automatically issue "solve" tactic in interactive prover
368 deriving (Show, Eq)
370-- Parsed declarations
372data Fixity = Infixl { prec :: Int }
373 | Infixr { prec :: Int }
374 | InfixN { prec :: Int }
375 | PrefixN { prec :: Int }
376 deriving Eq
377{-!
378deriving instance Binary Fixity
379deriving instance NFData Fixity
380!-}
382instance Show Fixity where
383 show (Infixl i) = "infixl " ++ show i
384 show (Infixr i) = "infixr " ++ show i
385 show (InfixN i) = "infix " ++ show i
386 show (PrefixN i) = "prefix " ++ show i
388data FixDecl = Fix Fixity String
389 deriving Eq
391instance Show FixDecl where
392 show (Fix f s) = show f ++ " " ++ s
394{-!
395deriving instance Binary FixDecl
396deriving instance NFData FixDecl
397!-}
399instance Ord FixDecl where
400 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
403data Static = Static | Dynamic
404 deriving (Show, Eq)
405{-!
406deriving instance Binary Static
407deriving instance NFData Static
408!-}
410-- Mark bindings with their explicitness, and laziness
411data Plicity = Imp { pargopts :: [ArgOpt],
412 pstatic :: Static,
413 pparam :: Bool }
414 | Exp { pargopts :: [ArgOpt],
415 pstatic :: Static,
416 pparam :: Bool } -- this is a param (rather than index)
417 | Constraint { pargopts :: [ArgOpt],
418 pstatic :: Static }
419 | TacImp { pargopts :: [ArgOpt],
420 pstatic :: Static,
421 pscript :: PTerm }
422 deriving (Show, Eq)
424{-!
425deriving instance Binary Plicity
426deriving instance NFData Plicity
427!-}
429impl = Imp [] Dynamic False
430expl = Exp [] Dynamic False
431expl_param = Exp [] Dynamic True
432constraint = Constraint [] Dynamic
433tacimpl t = TacImp [] Dynamic t
435data FnOpt = Inlinable -- always evaluate when simplifying
436 | TotalFn | PartialFn | CoveringFn
437 | Coinductive | AssertTotal
438 | Dictionary -- type class dictionary, eval only when
439 -- a function argument, and further evaluation resutls
440 | Implicit -- implicit coercion
441 | CExport String -- export, with a C name
442 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
443 | ErrorReverse -- ^^ attempt to reverse normalise before showing in error
444 | Reflection -- a reflecting function, compile-time only
445 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
446 deriving (Show, Eq)
447{-!
448deriving instance Binary FnOpt
449deriving instance NFData FnOpt
450!-}
452type FnOpts = [FnOpt]
454inlinable :: FnOpts -> Bool
455inlinable = elem Inlinable
457dictionary :: FnOpts -> Bool
458dictionary = elem Dictionary
461-- | Data declaration options
462data DataOpt = Codata -- Set if the the data-type is coinductive
463 | DefaultEliminator -- Set if an eliminator should be generated for data type
464 | DataErrRev
465 deriving (Show, Eq)
467type DataOpts = [DataOpt]
469-- | Type provider - what to provide
470data ProvideWhat = ProvTerm -- ^ only allow providing terms
471 | ProvPostulate -- ^ only allow postulates
472 | ProvAny -- ^ either is ok
473 deriving (Show, Eq)
475-- | Top-level declarations such as compiler directives, definitions,
476-- datatypes and typeclasses.
477data PDecl' t
478 = PFix FC Fixity [String] -- ^ Fixity declaration
479 | PTy Docstring [(Name, Docstring)] SyntaxInfo FC FnOpts Name t -- ^ Type declaration
480 | PPostulate Docstring SyntaxInfo FC FnOpts Name t -- ^ Postulate
481 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
482 | PCAF FC Name t -- ^ Top level constant
483 | PData Docstring [(Name, Docstring)] SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
484 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
485 | PNamespace String [PDecl' t] -- ^ New namespace
486 | PRecord Docstring SyntaxInfo FC Name t DataOpts Docstring Name t -- ^ Record declaration
487 | PClass Docstring SyntaxInfo FC
488 [t] -- constraints
489 Name
490 [(Name, t)] -- parameters
491 [(Name, Docstring)] -- parameter docstrings
492 [PDecl' t] -- declarations
493 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
494 -- class name, parameters, method declarations
495 | PInstance SyntaxInfo FC [t] -- constraints
496 Name -- class
497 [t] -- parameters
498 t -- full instance type
499 (Maybe Name) -- explicit name
500 [PDecl' t]
501 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
502 -- class name, parameters, full instance type, optional explicit name, and definitions
503 | PDSL Name (DSL' t) -- ^ DSL declaration
504 | PSyntax FC Syntax -- ^ Syntax definition
505 | PMutual FC [PDecl' t] -- ^ Mutual block
506 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
507 | PProvider SyntaxInfo FC ProvideWhat Name t t -- ^ Type provider. The first t is the type, the second is the term
508 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
509 -- bool is True, lhs and rhs must be convertible
510 deriving Functor
511{-!
512deriving instance Binary PDecl'
513deriving instance NFData PDecl'
514!-}
516-- For elaborator state
517type ElabD a = Elab' [PDecl] a
519-- | One clause of a top-level definition. Term arguments to constructors are:
520--
521-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
522--
523-- 2. The list of extra 'with' patterns
524--
525-- 3. The right-hand side
526--
527-- 4. The where block (PDecl' t)
529data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
530 | PWith FC Name t [t] t [PDecl' t]
531 | PClauseR FC [t] t [PDecl' t]
532 | PWithR FC [t] t [PDecl' t]
533 deriving Functor
534{-!
535deriving instance Binary PClause'
536deriving instance NFData PClause'
537!-}
539-- | Data declaration
540data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
541 d_tcon :: t, -- ^ Type constructor
542 d_cons :: [(Docstring, [(Name, Docstring)], Name, t, FC, [Name])] -- ^ Constructors
543 }
544 -- ^ Data declaration
545 | PLaterdecl { d_name :: Name, d_tcon :: t }
546 -- ^ "Placeholder" for data whose constructors are defined later
547 deriving Functor
548{-!
549deriving instance Binary PData'
550deriving instance NFData PData'
551!-}
553-- Handy to get a free function for applying PTerm -> PTerm functions
554-- across a program, by deriving Functor
556type PDecl = PDecl' PTerm
557type PData = PData' PTerm
558type PClause = PClause' PTerm
560-- get all the names declared in a decl
562declared :: PDecl -> [Name]
563declared (PFix _ _ _) = []
564declared (PTy _ _ _ _ _ n t) = [n]
565declared (PPostulate _ _ _ _ n t) = [n]
566declared (PClauses _ _ n _) = [] -- not a declaration
567declared (PCAF _ n _) = [n]
568declared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
569 where fstt (_, _, a, _, _, _) = a
570declared (PData _ _ _ _ _ (PLaterdecl n _)) = [n]
571declared (PParams _ _ ds) = concatMap declared ds
572declared (PNamespace _ ds) = concatMap declared ds
573declared (PRecord _ _ _ n _ _ _ c _) = [n, c]
574declared (PClass _ _ _ _ n _ _ ms) = n : concatMap declared ms
575declared (PInstance _ _ _ _ _ _ _ _) = []
576declared (PDSL n _) = [n]
577declared (PSyntax _ _) = []
578declared (PMutual _ ds) = concatMap declared ds
579declared (PDirective _) = []
581-- get the names declared, not counting nested parameter blocks
582tldeclared :: PDecl -> [Name]
583tldeclared (PFix _ _ _) = []
584tldeclared (PTy _ _ _ _ _ n t) = [n]
585tldeclared (PPostulate _ _ _ _ n t) = [n]
586tldeclared (PClauses _ _ n _) = [] -- not a declaration
587tldeclared (PRecord _ _ _ n _ _ _ c _) = [n, c]
588tldeclared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
589 where fstt (_, _, a, _, _, _) = a
590tldeclared (PParams _ _ ds) = []
591tldeclared (PMutual _ ds) = concatMap tldeclared ds
592tldeclared (PNamespace _ ds) = concatMap tldeclared ds
593tldeclared (PClass _ _ _ _ n _ _ ms) = concatMap tldeclared ms
594tldeclared (PInstance _ _ _ _ _ _ _ _) = []
595tldeclared _ = []
597defined :: PDecl -> [Name]
598defined (PFix _ _ _) = []
599defined (PTy _ _ _ _ _ n t) = []
600defined (PPostulate _ _ _ _ n t) = []
601defined (PClauses _ _ n _) = [n] -- not a declaration
602defined (PCAF _ n _) = [n]
603defined (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
604 where fstt (_, _, a, _, _, _) = a
605defined (PData _ _ _ _ _ (PLaterdecl n _)) = []
606defined (PParams _ _ ds) = concatMap defined ds
607defined (PNamespace _ ds) = concatMap defined ds
608defined (PRecord _ _ _ n _ _ _ c _) = [n, c]
609defined (PClass _ _ _ _ n _ _ ms) = n : concatMap defined ms
610defined (PInstance _ _ _ _ _ _ _ _) = []
611defined (PDSL n _) = [n]
612defined (PSyntax _ _) = []
613defined (PMutual _ ds) = concatMap defined ds
614defined (PDirective _) = []
615--defined _ = []
617updateN :: [(Name, Name)] -> Name -> Name
618updateN ns n | Just n' <- lookup n ns = n'
619updateN _ n = n
621updateNs :: [(Name, Name)] -> PTerm -> PTerm
622updateNs [] t = t
623updateNs ns t = mapPT updateRef t
624 where updateRef (PRef fc f) = PRef fc (updateN ns f)
625 updateRef t = t
627-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
628-- updateDNs [] t = t
629-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
630-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
631-- where updateCNs ns (PClause n l ts r ds)
632-- = PClause (updateN ns n) (fmap (updateNs ns) l)
633-- (map (fmap (updateNs ns)) ts)
634-- (fmap (updateNs ns) r)
635-- (map (updateDNs ns) ds)
636-- updateDNs ns c = c
638data PunInfo = IsType | IsTerm | TypeOrTerm deriving (Eq, Show)
640-- | High level language terms
641data PTerm = PQuote Raw
642 | PRef FC Name
643 | PInferRef FC Name -- ^ A name to be defined later
644 | PPatvar FC Name
645 | PLam Name PTerm PTerm
646 | PPi Plicity Name PTerm PTerm -- ^ (n : t1) -> t2
647 | PLet Name PTerm PTerm PTerm
648 | PTyped PTerm PTerm -- ^ Term with explicit type
649 | PApp FC PTerm [PArg] -- ^ e.g. IO (), List Char, length x
650 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
651 | PMatchApp FC Name -- ^ Make an application by type matching
652 | PCase FC PTerm [(PTerm, PTerm)]
653 | PTrue FC PunInfo -- ^ Unit type..?
654 | PFalse FC -- ^ _|_
655 | PRefl FC PTerm
656 | PResolveTC FC
657 | PEq FC PTerm PTerm -- ^ Equality type: A = B
658 | PRewrite FC PTerm PTerm (Maybe PTerm)
659 | PPair FC PunInfo PTerm PTerm
660 | PDPair FC PunInfo PTerm PTerm PTerm
661 | PAlternative Bool [PTerm] -- True if only one may work
662 | PHidden PTerm -- ^ Irrelevant or hidden pattern
663 | PType -- ^ 'Type' type
664 | PGoal FC PTerm Name PTerm
665 | PConstant Const -- ^ Builtin types
666 | Placeholder
667 | PDoBlock [PDo]
668 | PIdiom FC PTerm
669 | PReturn FC
670 | PMetavar Name
671 | PProof [PTactic] -- ^ Proof script
672 | PTactics [PTactic] -- ^ As PProof, but no auto solving
673 | PElabError Err -- ^ Error to report on elaboration
674 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
675 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
676 | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
677 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
678 | PNoImplicits PTerm -- ^ never run implicit converions on the term
679 deriving Eq
682{-!
683deriving instance Binary PTerm
684deriving instance NFData PTerm
685!-}
687mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
688mapPT f t = f (mpt t) where
689 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
690 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
691 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
692 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
693 (fmap (mapPT f) g)
694 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
695 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
696 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
697 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
698 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
699 mpt (PPair fc p l r) = PPair fc p (mapPT f l) (mapPT f r)
700 mpt (PDPair fc p l t r) = PDPair fc p (mapPT f l) (mapPT f t) (mapPT f r)
701 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
702 mpt (PHidden t) = PHidden (mapPT f t)
703 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
704 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
705 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
706 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
707 mpt (PDisamb ns tm) = PDisamb ns (mapPT f tm)
708 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
709 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
710 mpt x = x
713data PTactic' t = Intro [Name] | Intros | Focus Name
714 | Refine Name [Bool] | Rewrite t | DoUnify
715 | Induction Name
716 | Equiv t
717 | MatchRefine Name
718 | LetTac Name t | LetTacTy Name t t
719 | Exact t | Compute | Trivial | TCInstance
720 | ProofSearch Bool -- ^ recursive
721 (Maybe Name) [Name]
722 | Solve
723 | Attack
724 | ProofState | ProofTerm | Undo
725 | Try (PTactic' t) (PTactic' t)
726 | TSeq (PTactic' t) (PTactic' t)
727 | ApplyTactic t -- see Language.Reflection module
728 | ByReflection t
729 | Reflect t
730 | Fill t
731 | GoalType String (PTactic' t)
732 | TCheck t
733 | TEval t
734 | Qed | Abandon
735 deriving (Show, Eq, Functor)
736{-!
737deriving instance Binary PTactic'
738deriving instance NFData PTactic'
739!-}
740instance Sized a => Sized (PTactic' a) where
741 size (Intro nms) = 1 + size nms
742 size Intros = 1
743 size (Focus nm) = 1 + size nm
744 size (Refine nm bs) = 1 + size nm + length bs
745 size (Rewrite t) = 1 + size t
746 size (Induction t) = 1 + size t
747 size (LetTac nm t) = 1 + size nm + size t
748 size (Exact t) = 1 + size t
749 size Compute = 1
750 size Trivial = 1
751 size Solve = 1
752 size Attack = 1
753 size ProofState = 1
754 size ProofTerm = 1
755 size Undo = 1
756 size (Try l r) = 1 + size l + size r
757 size (TSeq l r) = 1 + size l + size r
758 size (ApplyTactic t) = 1 + size t
759 size (Reflect t) = 1 + size t
760 size (Fill t) = 1 + size t
761 size Qed = 1
762 size Abandon = 1
764type PTactic = PTactic' PTerm
766data PDo' t = DoExp FC t
767 | DoBind FC Name t
768 | DoBindP FC t t [(t,t)]
769 | DoLet FC Name t t
770 | DoLetP FC t t
771 deriving (Eq, Functor)
772{-!
773deriving instance Binary PDo'
774deriving instance NFData PDo'
775!-}
777instance Sized a => Sized (PDo' a) where
778 size (DoExp fc t) = 1 + size fc + size t
779 size (DoBind fc nm t) = 1 + size fc + size nm + size t
780 size (DoBindP fc l r alts) = 1 + size fc + size l + size r + size alts
781 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
782 size (DoLetP fc l r) = 1 + size fc + size l + size r
784type PDo = PDo' PTerm
786-- The priority gives a hint as to elaboration order. Best to elaborate
787-- things early which will help give a more concrete type to other
788-- variables, e.g. a before (interpTy a).
790data PArg' t = PImp { priority :: Int,
791 machine_inf :: Bool, -- true if the machine inferred it
792 argopts :: [ArgOpt],
793 pname :: Name, getTm :: t }
794 | PExp { priority :: Int,
795 argopts :: [ArgOpt],
796 pname :: Name,
797 getTm :: t }
798 | PConstraint { priority :: Int,
799 argopts :: [ArgOpt],
800 pname :: Name,
801 getTm :: t }
802 | PTacImplicit { priority :: Int,
803 argopts :: [ArgOpt],
804 pname :: Name,
805 getScript :: t,
806 getTm :: t }
807 deriving (Show, Eq, Functor)
809data ArgOpt = HideDisplay | InaccessibleArg
810 deriving (Show, Eq)
812instance Sized a => Sized (PArg' a) where
813 size (PImp p _ l nm trm) = 1 + size nm + size trm
814 size (PExp p l nm trm) = 1 + size nm + size trm
815 size (PConstraint p l nm trm) = 1 + size nm +size nm + size trm
816 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
818{-!
819deriving instance Binary PArg'
820deriving instance NFData PArg'
821!-}
823pimp n t mach = PImp 1 mach [] n t
824pexp t = PExp 1 [] (sMN 0 "arg") t
825pconst t = PConstraint 1 [] (sMN 0 "carg") t
826ptacimp n s t = PTacImplicit 2 [] n s t
828type PArg = PArg' PTerm
830-- Type class data
832data ClassInfo = CI { instanceName :: Name,
833 class_methods :: [(Name, (FnOpts, PTerm))],
834 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
835 class_default_superclasses :: [PDecl],
836 class_params :: [Name],
837 class_instances :: [Name] }
838 deriving Show
839{-!
840deriving instance Binary ClassInfo
841deriving instance NFData ClassInfo
842!-}
844-- Type inference data
846data TIData = TIPartial -- ^ a function with a partially defined type
847 | TISolution [Term] -- ^ possible solutions to a metavariable in a type
848 deriving Show
850data OptInfo = Optimise { inaccessible :: [(Int,Name)], -- includes names for error reporting
851 detaggable :: Bool }
852 deriving Show
853{-!
854deriving instance Binary OptInfo
855deriving instance NFData OptInfo
856!-}
859data TypeInfo = TI { con_names :: [Name],
860 codata :: Bool,
861 data_opts :: DataOpts,
862 param_pos :: [Int] }
863 deriving Show
864{-!
865deriving instance Binary TypeInfo
866deriving instance NFData TypeInfo
867!-}
869-- Syntactic sugar info
871data DSL' t = DSL { dsl_bind :: t,
872 dsl_return :: t,
873 dsl_apply :: t,
874 dsl_pure :: t,
875 dsl_var :: Maybe t,
876 index_first :: Maybe t,
877 index_next :: Maybe t,
878 dsl_lambda :: Maybe t,
879 dsl_let :: Maybe t
880 }
881 deriving (Show, Functor)
882{-!
883deriving instance Binary DSL'
884deriving instance NFData DSL'
885!-}
887type DSL = DSL' PTerm
889data SynContext = PatternSyntax | TermSyntax | AnySyntax
890 deriving Show
891{-!
892deriving instance Binary SynContext
893deriving instance NFData SynContext
894!-}
896data Syntax = Rule [SSymbol] PTerm SynContext
897 deriving Show
898{-!
899deriving instance Binary Syntax
900deriving instance NFData Syntax
901!-}
903data SSymbol = Keyword Name
904 | Symbol String
905 | Binding Name
906 | Expr Name
907 | SimpleExpr Name
908 deriving Show
909{-!
910deriving instance Binary SSymbol
911deriving instance NFData SSymbol
912!-}
914initDSL = DSL (PRef f (sUN ">>="))
915 (PRef f (sUN "return"))
916 (PRef f (sUN "<$>"))
917 (PRef f (sUN "pure"))
918 Nothing
919 Nothing
920 Nothing
921 Nothing
922 Nothing
923 where f = fileFC "(builtin)"
925data Using = UImplicit Name PTerm
926 | UConstraint Name [Name]
927 deriving (Show, Eq)
928{-!
929deriving instance Binary Using
930deriving instance NFData Using
931!-}
933data SyntaxInfo = Syn { using :: [Using],
934 syn_params :: [(Name, PTerm)],
935 syn_namespace :: [String],
936 no_imp :: [Name],
937 decoration :: Name -> Name,
938 inPattern :: Bool,
939 implicitAllowed :: Bool,
940 dsl_info :: DSL }
941 deriving Show
942{-!
943deriving instance NFData SyntaxInfo
944deriving instance Binary SyntaxInfo
945!-}
947defaultSyntax = Syn [] [] [] [] id False False initDSL
949expandNS :: SyntaxInfo -> Name -> Name
950expandNS syn n@(NS _ _) = n
951expandNS syn n = case syn_namespace syn of
952 [] -> n
953 xs -> sNS n xs
956-- For inferring types of things
958bi = fileFC "builtin"
960inferTy = sMN 0 "__Infer"
961inferCon = sMN 0 "__infer"
962inferDecl = PDatadecl inferTy
963 PType
964 [(emptyDocstring, [], inferCon, PPi impl (sMN 0 "iType") PType (
965 PPi expl (sMN 0 "ival") (PRef bi (sMN 0 "iType"))
966 (PRef bi inferTy)), bi, [])]
967inferOpts = []
969infTerm t = PApp bi (PRef bi inferCon) [pimp (sMN 0 "iType") Placeholder True, pexp t]
970infP = P (TCon 6 0) inferTy (TType (UVal 0))
972getInferTerm, getInferType :: Term -> Term
973getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
974getInferTerm (App (App _ _) tm) = tm
975getInferTerm tm = tm -- error ("getInferTerm " ++ show tm)
977getInferType (Bind n b sc) = Bind n (toTy b) $ getInferType sc
978 where toTy (Lam t) = Pi t
979 toTy (PVar t) = PVTy t
980 toTy b = b
981getInferType (App (App _ ty) _) = ty
985-- Handy primitives: Unit, False, Pair, MkPair, =, mkForeign, Elim type class
987primNames = [unitTy, unitCon,
988 falseTy, pairTy, pairCon,
989 eqTy, eqCon, inferTy, inferCon]
991unitDoc = parseDocstring . T.pack $ "The canonical single-element type, also known as the trivially true proposition."
992unitTy = sMN 0 "__Unit"
993unitCon = sMN 0 "__II"
994unitDecl = PDatadecl unitTy PType
995 [(parseDocstring . T.pack $ "The trivial constructor for `()`. ", [], unitCon, PRef bi unitTy, bi, [])]
996unitOpts = [DefaultEliminator]
998falseDoc = parseDocstring . T.pack $
999 "The empty type, also known as the trivially false proposition." ++
1000 "\n\n" ++
1001 "Use `FalseElim` or `absurd` to prove anything if you have a variable " ++
1002 "of type `_|_` in scope."
1003falseTy = sMN 0 "__False"
1004falseDecl = PDatadecl falseTy PType []
1005falseOpts = []
1007pairDoc = parseDocstring . T.pack $ "The non-dependent pair type, also known as conjunction."
1008pairTy = sMN 0 "__Pair"
1009pairCon = sMN 0 "__MkPair"
1010pairDecl = PDatadecl pairTy (piBind [(n "A", PType), (n "B", PType)] PType)
1011 [(pairConDoc, pairConParamDoc,
1012 pairCon, PPi impl (n "A") PType (
1013 PPi impl (n "B") PType (
1014 PPi expl (n "a") (PRef bi (n "A")) (
1015 PPi expl (n "b") (PRef bi (n "B"))
1016 (PApp bi (PRef bi pairTy) [pexp (PRef bi (n "A")),
1017 pexp (PRef bi (n "B"))])))), bi, [])]
1018 where n a = sMN 0 a
1019 pairConDoc = parseDocstring . T.pack $ "A pair of elements"
1020 pairConParamDoc = [(n "a", parseDocstring . T.pack $ "the left element of the pair"),
1021 (n "b", parseDocstring . T.pack $ "the right element of the pair")]
1022pairOpts = []
1023pairParamDoc = [(n "A", parseDocstring . T.pack $ "the type of the left elements in the pair"),
1024 (n "B", parseDocstring . T.pack $ "the type of the left elements in the pair")]
1025 where n a = sMN 0 a
1027eqTy = sUN "="
1028eqCon = sUN "refl"
1029eqDoc = parseDocstring . T.pack $
1030 "The propositional equality type. A proof that `x` = `y`." ++
1031 "\n\n" ++
1032 "To use such a proof, pattern-match on it, and the two equal things will " ++
1033 "then need to be the _same_ pattern." ++
1034 "\n\n" ++
1035 "**Note**: Idris's equality type is _heterogeneous_, which means that it " ++
1036 "is possible to state equalities between values of potentially different " ++
1037 "types. This is sometimes referred to in the literature as \"John Major\" " ++
1038 "equality." ++
1039 "\n\n" ++
1040 "Thus, if Idris can't infer the type of one side of the equality, then " ++
1041 "you may need to annotate it. See the function `the`."
1043eqDecl = PDatadecl eqTy (piBind [(n "A", PType), (n "B", PType),
1044 (n "x", PRef bi (n "A")), (n "y", PRef bi (n "B"))]
1045 PType)
1046 [(reflDoc, reflParamDoc,
1047 eqCon, PPi impl (n "A") PType (
1048 PPi impl (n "x") (PRef bi (n "A"))
1049 (PApp bi (PRef bi eqTy) [pimp (n "A") Placeholder False,
1050 pimp (n "B") Placeholder False,
1051 pexp (PRef bi (n "x")),
1052 pexp (PRef bi (n "x"))])), bi, [])]
1053 where n a = sMN 0 a
1054 reflDoc = parseDocstring . T.pack $
1055 "A proof that `x` in fact equals `x`. To construct this, you must have already " ++
1056 "shown that both sides are in fact equal."
1057 reflParamDoc = [(n "A", parseDocstring . T.pack $ "the type at which the equality is proven"),
1058 (n "x", parseDocstring . T.pack $ "the element shown to be equal to itself.")]
1060eqParamDoc = [(n "A", parseDocstring . T.pack $ "the type of the left side of the equality"),
1061 (n "B", parseDocstring . T.pack $ "the type of the right side of the equality")
1063 where n a = sMN 0 a
1065eqOpts = []
1067elimName = sUN "__Elim"
1068elimMethElimTy = sUN "__elimTy"
1069elimMethElim = sUN "elim"
1070elimDecl = PClass (parseDocstring . T.pack $ "Type class for eliminators") defaultSyntax bi [] elimName [(sUN "scrutineeType", PType)] []
1071 [PTy emptyDocstring [] defaultSyntax bi [TotalFn] elimMethElimTy PType,
1072 PTy emptyDocstring [] defaultSyntax bi [TotalFn] elimMethElim (PRef bi elimMethElimTy)]
1074-- Defined in builtins.idr
1075sigmaTy = sUN "Exists"
1076existsCon = sUN "Ex_intro"
1078piBind :: [(Name, PTerm)] -> PTerm -> PTerm
1079piBind = piBindp expl
1081piBindp :: Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
1082piBindp p [] t = t
1083piBindp p ((n, ty):ns) t = PPi p n ty (piBindp p ns t)
1086-- Pretty-printing declarations and terms
1088-- These "show" instances render to an absurdly wide screen because inserted line breaks
1089-- could interfere with interactive editing, which calls "show".
1091instance Show PTerm where
1092 showsPrec _ tm = (displayS . renderPretty 1.0 10000000 . prettyImp False) tm
1094instance Show PDecl where
1095 showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDeclImp False) d
1097instance Show PClause where
1098 showsPrec _ c = (displayS . renderPretty 1.0 10000000 . showCImp True) c
1100instance Show PData where
1101 showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDImp False) d
1103instance Pretty PTerm OutputAnnotation where
1104 pretty = prettyImp False
1106-- | Colourise annotations according to an Idris state. It ignores the names
1107-- in the annotation, as there's no good way to show extended information on a
1108-- terminal.
1109consoleDecorate :: IState -> OutputAnnotation -> String -> String
1110consoleDecorate ist _ | not (idris_colourRepl ist) = id
1111consoleDecorate ist AnnConstData = let theme = idris_colourTheme ist
1112 in colouriseData theme
1113consoleDecorate ist AnnConstType = let theme = idris_colourTheme ist
1114 in colouriseType theme
1115consoleDecorate ist (AnnBoundName _ True) = colouriseImplicit (idris_colourTheme ist)
1116consoleDecorate ist (AnnBoundName _ False) = colouriseBound (idris_colourTheme ist)
1117consoleDecorate ist AnnKeyword = colouriseKeyword (idris_colourTheme ist)
1118consoleDecorate ist (AnnName n _ _ _) = let ctxt = tt_ctxt ist
1119 theme = idris_colourTheme ist
1120 in case () of
1121 _ | isDConName n ctxt -> colouriseData theme
1122 _ | isFnName n ctxt -> colouriseFun theme
1123 _ | isTConName n ctxt -> colouriseType theme
1124 _ | otherwise -> id -- don't colourise unknown names
1125consoleDecorate ist (AnnFC _) = id
1126consoleDecorate ist (AnnTextFmt fmt) = Idris.Colours.colourise (colour fmt)
1127 where colour BoldText = IdrisColour Nothing True False True False
1128 colour UnderlineText = IdrisColour Nothing True True False False
1129 colour ItalicText = IdrisColour Nothing True False False True
1131-- | Pretty-print a high-level closed Idris term with no information about precedence/associativity
1132prettyImp :: Bool -- ^^ whether to show implicits
1133 -> PTerm -- ^^ the term to pretty-print
1134 -> Doc OutputAnnotation
1135prettyImp impl = pprintPTerm impl [] [] []
1137-- | Do the right thing for rendering a term in an IState
1138prettyIst :: IState -> PTerm -> Doc OutputAnnotation
1139prettyIst ist = pprintPTerm (opt_showimp (idris_options ist)) [] [] (idris_infixes ist)
1141-- | Pretty-print a high-level Idris term in some bindings context with infix info
1142pprintPTerm :: Bool -- ^^ whether to show implicits
1143 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1144 -> [Name] -- ^^ names to always show in pi, even if not used
1145 -> [FixDecl] -- ^^ Fixity declarations
1146 -> PTerm -- ^^ the term to pretty-print
1147 -> Doc OutputAnnotation
1148pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1149 where
1150 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1151 prettySe p bnd (PQuote r) =
1152 text "![" <> pretty r <> text "]"
1153 prettySe p bnd (PPatvar fc n) = pretty n
1154 prettySe p bnd e
1155 | Just str <- slist p bnd e = str
1156 | Just n <- snat p e = annotate AnnConstData (text (show n))
1157 prettySe p bnd (PRef fc n) = prettyName impl bnd n
1158 prettySe p bnd (PLam n ty sc) =
1159 bracket p 2 . group . align . hang 2 $
1160 text "\\" <> bindingOf n False <+> text "=>" <$>
1161 prettySe 10 ((n, False):bnd) sc
1162 prettySe p bnd (PLet n ty v sc) =
1163 bracket p 2 $
1164 kwd "let" <+> bindingOf n False <+> text "=" </>
1165 prettySe 10 bnd v <+> kwd "in" </>
1166 prettySe 10 ((n, False):bnd) sc
1167 prettySe p bnd (PPi (Exp l s _) n ty sc)
1168 | n `elem` allNamesIn sc || impl || n `elem` docArgs =
1169 bracket p 2 . group $
1170 enclose lparen rparen (group . align $ bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1171 st <> text "->" <$> prettySe 10 ((n, False):bnd) sc
1172 | otherwise =
1173 bracket p 2 . group $
1174 group (prettySe 0 bnd ty <+> st) <> text "->" <$> group (prettySe 10 ((n, False):bnd) sc)
1175 where
1176 st =
1177 case s of
1178 Static -> text "[static]" <> space
1179 _ -> empty
1180 prettySe p bnd (PPi (Imp l s _) n ty sc)
1181 | impl =
1182 bracket p 2 $
1183 lbrace <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1184 st <> text "->" </> prettySe 10 ((n, True):bnd) sc
1185 | otherwise = prettySe 10 ((n, True):bnd) sc
1186 where
1187 st =
1188 case s of
1189 Static -> text "[static]" <> space
1190 _ -> empty
1191 prettySe p bnd (PPi (Constraint _ _) n ty sc) =
1192 bracket p 2 $
1193 prettySe 10 bnd ty <+> text "=>" </> prettySe 10 ((n, True):bnd) sc
1194 prettySe p bnd (PPi (TacImp _ _ s) n ty sc) =
1195 bracket p 2 $
1196 lbrace <> kwd "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1197 rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
1198 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1199 | UN nm <- basename f
1200 , not impl && null (getExps args) = if isAlpha (thead nm)
1201 then prettyName impl bnd f
1202 else enclose lparen rparen $
1203 prettyName impl bnd f
1204 prettySe p bnd (PAppBind _ (PRef _ f) [])
1205 | not impl = text "!" <> prettyName impl bnd f
1206 prettySe p bnd (PApp _ (PRef _ op) args)
1207 | UN nm <- basename op
1208 , not (tnull nm) &&
1209 (not impl) && (not $ isAlpha (thead nm)) =
1210 case getExps args of
1211 [] -> enclose lparen rparen opName
1212 [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1213 [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
1214 in bracket p precedence $ inFix l r
1215 (l:r:rest) -> bracket p 1 $
1216 enclose lparen rparen (inFix l r) <+>
1217 align (group (vsep (map (prettyArgSe bnd) rest)))
1218 where opName = prettyName impl bnd op
1219 f = getFixity (opStr op)
1220 left l = case f of
1221 Nothing -> prettySe (-1) bnd l
1222 Just (Infixl p') -> prettySe p' bnd l
1223 Just f' -> prettySe (prec f'-1) bnd l
1224 right r = case f of
1225 Nothing -> prettySe (-1) bnd r
1226 Just (Infixr p') -> prettySe p' bnd r
1227 Just f' -> prettySe (prec f'-1) bnd r
1228 inFix l r = align . group $
1229 (left l <+> opName) <$> group (right r)
1230 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
1231 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1232 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
1233 prettySe p bnd (PApp _ f as) =
1234 let args = getExps as
1235 fp = prettySe 1 bnd f
1236 in
1237 bracket p 1 . group $
1238 if impl
1239 then if null as
1240 then fp
1241 else fp <+> align (vsep (map (prettyArgS bnd) as))
1242 else if null args
1243 then fp
1244 else fp <+> align (vsep (map (prettyArgSe bnd) args))
1245 prettySe p bnd (PCase _ scr opts) =
1246 kwd "case" <+> prettySe 10 bnd scr <+> kwd "of" <> prettyBody
1247 where
1248 prettyBody = foldr (<>) empty $ intersperse (text "|") $ map sc opts
1250 sc (l, r) = nest nestingSize $ prettySe 10 bnd l <+> text "=>" <+> prettySe 10 bnd r
1251 prettySe p bnd (PHidden tm) = text "." <> prettySe 0 bnd tm
1252 prettySe p bnd (PRefl _ _) = annName eqCon $ text "refl"
1253 prettySe p bnd (PResolveTC _) = text "resolvetc"
1254 prettySe p bnd (PTrue _ IsType) = annName unitTy $ text "()"
1255 prettySe p bnd (PTrue _ IsTerm) = annName unitCon $ text "()"
1256 prettySe p bnd (PTrue _ TypeOrTerm) = text "()"
1257 prettySe p bnd (PFalse _) = annName falseTy $ text "_|_"
1258 prettySe p bnd (PEq _ l r) =
1259 bracket p 2 . align . group $
1260 prettySe 10 bnd l <+> eq <$> group (prettySe 10 bnd r)
1261 where eq = annName eqTy (text "=")
1262 prettySe p bnd (PRewrite _ l r _) =
1263 bracket p 2 $
1264 text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1265 prettySe p bnd (PTyped l r) =
1266 lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
1267 prettySe p bnd pair@(PPair _ pun _ _) -- flatten tuples to the right, like parser
1268 | Just elts <- pairElts pair = enclose (ann lparen) (ann rparen) .
1269 align . group . vsep . punctuate (ann comma) $
1270 map (prettySe 10 bnd) elts
1271 where ann = case pun of
1272 TypeOrTerm -> id
1273 IsType -> annName pairTy
1274 IsTerm -> annName pairCon
1275 prettySe p bnd (PDPair _ TypeOrTerm l t r) =
1276 lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1277 prettySe p bnd (PDPair _ IsType (PRef _ n) t r) =
1278 annName sigmaTy lparen <>
1279 bindingOf n False <+>
1280 annName sigmaTy (text "**") <+>
1281 prettySe 10 ((n, False):bnd) r <>
1282 annName sigmaTy rparen
1283 prettySe p bnd (PDPair _ IsType l t r) =
1284 annName sigmaTy lparen <>
1285 prettySe 10 bnd l <+>
1286 annName sigmaTy (text "**") <+>
1287 prettySe 10 bnd r <>
1288 annName sigmaTy rparen
1289 prettySe p bnd (PDPair _ IsTerm l t r) =
1290 annName existsCon lparen <>
1291 prettySe 10 bnd l <+>
1292 annName existsCon (text "**") <+>
1293 prettySe 10 bnd r <>
1294 annName existsCon rparen
1295 prettySe p bnd (PAlternative a as) =
1296 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1297 where
1298 prettyAs =
1299 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10 bnd) as
1300 prettySe p bnd PType = annotate AnnConstType $ text "Type"
1301 prettySe p bnd (PConstant c) = annotate (annot c) (text (show c))
1302 where annot (AType _) = AnnConstType
1303 annot StrType = AnnConstType
1304 annot PtrType = AnnConstType
1305 annot VoidType = AnnConstType
1306 annot _ = AnnConstData
1307 -- XXX: add pretty for tactics
1308 prettySe p bnd (PProof ts) =
1309 text "proof" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1310 prettySe p bnd (PTactics ts) =
1311 text "tactics" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1312 prettySe p bnd (PMetavar n) = text "?" <> pretty n
1313 prettySe p bnd (PReturn f) = kwd "return"
1314 prettySe p bnd PImpossible = kwd "impossible"
1315 prettySe p bnd Placeholder = text "_"
1316 prettySe p bnd (PDoBlock _) = text "do block pretty not implemented"
1317 prettySe p bnd (PElabError s) = pretty s
1319 prettySe p bnd _ = text "test"
1321 prettyArgS bnd (PImp _ _ _ n tm) = prettyArgSi bnd (n, tm)
1322 prettyArgS bnd (PExp _ _ _ tm) = prettyArgSe bnd tm
1323 prettyArgS bnd (PConstraint _ _ _ tm) = prettyArgSc bnd tm
1324 prettyArgS bnd (PTacImplicit _ _ n _ tm) = prettyArgSti bnd (n, tm)
1326 prettyArgSe bnd arg = prettySe 0 bnd arg
1327 prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1328 prettyArgSc bnd val = lbrace <> lbrace <> prettySe 10 bnd val <> rbrace <> rbrace
1329 prettyArgSti bnd (n, val) = lbrace <> kwd "auto" <+> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1331 annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
1332 annName n = annotate (AnnName n Nothing Nothing Nothing)
1334 opStr :: Name -> String
1335 opStr (NS n _) = opStr n
1336 opStr (UN n) = T.unpack n
1338 basename :: Name -> Name
1339 basename (NS n _) = basename n
1340 basename n = n
1342 slist' p bnd (PApp _ (PRef _ nil) _)
1343 | not impl && nsroot nil == sUN "Nil" = Just []
1344 slist' p bnd (PRef _ nil)
1345 | not impl && nsroot nil == sUN "Nil" = Just []
1346 slist' p bnd (PApp _ (PRef _ cons) args)
1347 | nsroot cons == sUN "::",
1348 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1349 all isImp imps,
1350 Just tl' <- slist' p bnd tl
1351 = Just (hd:tl')
1352 where
1353 isImp (PImp {}) = True
1354 isImp _ = False
1355 slist' _ _ tm = Nothing
1357 slist p bnd e | Just es <- slist' p bnd e = Just $
1358 case es of [] -> annotate AnnConstData $ text "[]"
1359 [x] -> enclose left right . group $
1360 prettySe p bnd x
1361 xs -> (enclose left right .
1362 align . group . vsep .
1363 punctuate comma .
1364 map (prettySe p bnd)) xs
1365 where left = (annotate AnnConstData (text "["))
1366 right = (annotate AnnConstData (text "]"))
1367 comma = (annotate AnnConstData (text ","))
1368 slist _ _ _ = Nothing
1370 pairElts :: PTerm -> Maybe [PTerm]
1371 pairElts (PPair _ _ x y) | Just elts <- pairElts y = Just (x:elts)
1372 | otherwise = Just [x, y]
1373 pairElts _ = Nothing
1375 natns = "Prelude.Nat."
1377 snat p (PRef _ z)
1378 | show z == (natns++"Z") || show z == "Z" = Just 0
1379 snat p (PApp _ s [PExp {getTm=n}])
1380 | show s == (natns++"S") || show s == "S",
1381 Just n' <- snat p n
1382 = Just $ 1 + n'
1383 snat _ _ = Nothing
1385 bracket outer inner doc
1386 | inner > outer = lparen <> doc <> rparen
1387 | otherwise = doc
1389 kwd = annotate AnnKeyword . text
1391 fixities :: M.Map String Fixity
1392 fixities = M.fromList [(s, f) | (Fix f s) <- infixes]
1394 getFixity :: String -> Maybe Fixity
1395 getFixity = flip M.lookup fixities
1397-- | Pretty-printer helper for the binding site of a name
1398bindingOf :: Name -- ^^ the bound name
1399 -> Bool -- ^^ whether the name is implicit
1400 -> Doc OutputAnnotation
1401bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1403-- | Pretty-printer helper for names that attaches the correct annotations
1404prettyName :: Bool -- ^^ whether to show namespaces
1405 -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1406 -> Name -- ^^ the name to pprint
1407 -> Doc OutputAnnotation
1408prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1409 | otherwise = annotate (AnnName n Nothing Nothing Nothing) (text (strName n))
1410 where strName (UN n) = T.unpack n
1411 strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1412 | otherwise = strName n
1413 strName n | n == falseTy = "_|_"
1414 strName (MN i s) = T.unpack s
1415 strName other = show other
1418showCImp :: Bool -> PClause -> Doc OutputAnnotation
1419showCImp impl (PClause _ n l ws r w)
1420 = prettyImp impl l <+> showWs ws <+> text "=" <+> prettyImp impl r
1421 <+> text "where" <+> text (show w)
1422 where
1423 showWs [] = empty
1424 showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1425showCImp impl (PWith _ n l ws r w)
1426 = prettyImp impl l <+> showWs ws <+> text "with" <+> prettyImp impl r
1427 <+> braces (text (show w))
1428 where
1429 showWs [] = empty
1430 showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1433showDImp :: Bool -> PData -> Doc OutputAnnotation
1434showDImp impl (PDatadecl n ty cons)
1435 = text "data" <+> text (show n) <+> colon <+> prettyImp impl ty <+> text "where" <$>
1436 (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp impl t) cons))
1438showDecls :: Bool -> [PDecl] -> Doc OutputAnnotation
1439showDecls i ds = vsep (map (showDeclImp i) ds)
1441showDeclImp _ (PFix _ f ops) = text (show f) <+> cat (punctuate (text ",") (map text ops))
1442showDeclImp i (PTy _ _ _ _ _ n t) = text "tydecl" <+> text (showCG n) <+> colon <+> prettyImp i t
1443showDeclImp i (PClauses _ _ n cs) = text "pat" <+> text (showCG n) <+> text "\t" <+>
1444 indent 2 (vsep (map (showCImp i) cs))
1445showDeclImp _ (PData _ _ _ _ _ d) = showDImp True d
1446showDeclImp i (PParams _ ns ps) = text "params" <+> braces (text (show ns) <> line <> showDecls i ps <> line)
1447showDeclImp i (PNamespace n ps) = text "namespace" <+> text n <> braces (line <> showDecls i ps <> line)
1448showDeclImp _ (PSyntax _ syn) = text "syntax" <+> text (show syn)
1449showDeclImp i (PClass _ _ _ cs n ps _ ds)
1450 = text "class" <+> text (show cs) <+> text (show n) <+> text (show ps) <> line <> showDecls i ds
1451showDeclImp i (PInstance _ _ cs n _ t _ ds)
1452 = text "instance" <+> text (show cs) <+> text (show n) <+> prettyImp i t <> line <> showDecls i ds
1453showDeclImp _ _ = text "..."
1454-- showDeclImp (PImport i) = "import " ++ i
1456instance Show (Doc OutputAnnotation) where
1457 show = flip (displayS . renderCompact) ""
1459getImps :: [PArg] -> [(Name, PTerm)]
1460getImps [] = []
1461getImps (PImp _ _ _ n tm : xs) = (n, tm) : getImps xs
1462getImps (_ : xs) = getImps xs
1464getExps :: [PArg] -> [PTerm]
1465getExps [] = []
1466getExps (PExp _ _ _ tm : xs) = tm : getExps xs
1467getExps (_ : xs) = getExps xs
1469getConsts :: [PArg] -> [PTerm]
1470getConsts [] = []
1471getConsts (PConstraint _ _ _ tm : xs) = tm : getConsts xs
1472getConsts (_ : xs) = getConsts xs
1474getAll :: [PArg] -> [PTerm]
1475getAll = map getTm
1478-- | Show Idris name
1479showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1480 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1481 -> Bool -- ^^ whether to show implicits
1482 -> Bool -- ^^ whether to colourise
1483 -> Name -- ^^ the term to show
1484 -> String
1485showName ist bnd impl colour n = case ist of
1486 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1487 Nothing -> showbasic n
1488 where name = if impl then show n else showbasic n
1489 showbasic n@(UN _) = showCG n
1490 showbasic (MN _ s) = str s
1491 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
1492 showbasic (SN s) = show s
1493 fst3 (x, _, _) = x
1494 colourise n t = let ctxt' = fmap tt_ctxt ist in
1495 case ctxt' of
1496 Nothing -> name
1497 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1498 else colouriseBound t name
1499 | isDConName n ctxt -> colouriseData t name
1500 | isFnName n ctxt -> colouriseFun t name
1501 | isTConName n ctxt -> colouriseType t name
1502 -- The assumption is that if a name is not bound and does not exist in the
1503 -- global context, then we're somewhere in which implicit info has been lost
1504 -- (like error messages). Thus, unknown vars are colourised as implicits.
1505 | otherwise -> colouriseImplicit t name
1507showTm :: IState -- ^^ the Idris state, for information about identifiers and colours
1508 -> PTerm -- ^^ the term to show
1509 -> String
1510showTm ist = displayDecorated (consoleDecorate ist) .
1511 renderPretty 0.8 100000 .
1512 prettyImp (opt_showimp (idris_options ist))
1514-- | Show a term with implicits, no colours
1515showTmImpls :: PTerm -> String
1516showTmImpls = flip (displayS . renderCompact . prettyImp True) ""
1519instance Sized PTerm where
1520 size (PQuote rawTerm) = size rawTerm
1521 size (PRef fc name) = size name
1522 size (PLam name ty bdy) = 1 + size ty + size bdy
1523 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1524 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1525 size (PTyped trm ty) = 1 + size trm + size ty
1526 size (PApp fc name args) = 1 + size args
1527 size (PAppBind fc name args) = 1 + size args
1528 size (PCase fc trm bdy) = 1 + size trm + size bdy
1529 size (PTrue fc _) = 1
1530 size (PFalse fc) = 1
1531 size (PRefl fc _) = 1
1532 size (PResolveTC fc) = 1
1533 size (PEq fc left right) = 1 + size left + size right
1534 size (PRewrite fc left right _) = 1 + size left + size right
1535 size (PPair fc _ left right) = 1 + size left + size right
1536 size (PDPair fs _ left ty right) = 1 + size left + size ty + size right
1537 size (PAlternative a alts) = 1 + size alts
1538 size (PHidden hidden) = size hidden
1539 size (PUnifyLog tm) = size tm
1540 size (PDisamb _ tm) = size tm
1541 size (PNoImplicits tm) = size tm
1542 size PType = 1
1543 size (PConstant const) = 1 + size const
1544 size Placeholder = 1
1545 size (PDoBlock dos) = 1 + size dos
1546 size (PIdiom fc term) = 1 + size term
1547 size (PReturn fc) = 1
1548 size (PMetavar name) = 1
1549 size (PProof tactics) = size tactics
1550 size (PElabError err) = size err
1551 size PImpossible = 1
1553getPArity :: PTerm -> Int
1554getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1555getPArity _ = 0
1557-- Return all names, free or globally bound, in the given term.
1559allNamesIn :: PTerm -> [Name]
1560allNamesIn tm = nub $ ni [] tm
1561 where -- TODO THINK added niTacImp, but is it right?
1562 ni env (PRef _ n)
1563 | not (n `elem` env) = [n]
1564 ni env (PPatvar _ n) = [n]
1565 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1566 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1567 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1568 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1569 ni env (PPi p n ty sc) = niTacImp env p ++ ni env ty ++ ni (n:env) sc
1570 ni env (PHidden tm) = ni env tm
1571 ni env (PEq _ l r) = ni env l ++ ni env r
1572 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1573 ni env (PTyped l r) = ni env l ++ ni env r
1574 ni env (PPair _ _ l r) = ni env l ++ ni env r
1575 ni env (PDPair _ _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1576 ni env (PDPair _ _ l t r) = ni env l ++ ni env t ++ ni env r
1577 ni env (PAlternative a ls) = concatMap (ni env) ls
1578 ni env (PUnifyLog tm) = ni env tm
1579 ni env (PDisamb _ tm) = ni env tm
1580 ni env (PNoImplicits tm) = ni env tm
1581 ni env _ = []
1583 niTacImp env (TacImp _ _ scr) = ni env scr
1584 niTacImp _ _ = []
1586-- Return all names defined in binders in the given term
1587boundNamesIn :: PTerm -> [Name]
1588boundNamesIn tm = nub $ ni tm
1589 where -- TODO THINK Added niTacImp, but is it right?
1590 ni (PApp _ f as) = ni f ++ concatMap (ni) (map getTm as)
1591 ni (PAppBind _ f as) = ni f ++ concatMap (ni) (map getTm as)
1592 ni (PCase _ c os) = ni c ++ concatMap (ni) (map snd os)
1593 ni (PLam n ty sc) = n : (ni ty ++ ni sc)
1594 ni (PLet n ty val sc) = n : (ni ty ++ ni val ++ ni sc)
1595 ni (PPi p n ty sc) = niTacImp p ++ (n : (ni ty ++ ni sc))
1596 ni (PEq _ l r) = ni l ++ ni r
1597 ni (PRewrite _ l r _) = ni l ++ ni r
1598 ni (PTyped l r) = ni l ++ ni r
1599 ni (PPair _ _ l r) = ni l ++ ni r
1600 ni (PDPair _ _ (PRef _ n) t r) = ni t ++ ni r
1601 ni (PDPair _ _ l t r) = ni l ++ ni t ++ ni r
1602 ni (PAlternative a as) = concatMap (ni) as
1603 ni (PHidden tm) = ni tm
1604 ni (PUnifyLog tm) = ni tm
1605 ni (PDisamb _ tm) = ni tm
1606 ni (PNoImplicits tm) = ni tm
1607 ni _ = []
1609 niTacImp (TacImp _ _ scr) = ni scr
1610 niTacImp _ = []
1612-- Return names which are free in the given term.
1613namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1614namesIn uvars ist tm = nub $ ni [] tm
1615 where
1616 ni env (PRef _ n)
1617 | not (n `elem` env)
1618 = case lookupTy n (tt_ctxt ist) of
1619 [] -> [n]
1620 _ -> if n `elem` (map fst uvars) then [n] else []
1621 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1622 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1623 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1624 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1625 ni env (PPi p n ty sc) = niTacImp env p ++ ni env ty ++ ni (n:env) sc
1626 ni env (PEq _ l r) = ni env l ++ ni env r
1627 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1628 ni env (PTyped l r) = ni env l ++ ni env r
1629 ni env (PPair _ _ l r) = ni env l ++ ni env r
1630 ni env (PDPair _ _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1631 ni env (PDPair _ _ l t r) = ni env l ++ ni env t ++ ni env r
1632 ni env (PAlternative a as) = concatMap (ni env) as
1633 ni env (PHidden tm) = ni env tm
1634 ni env (PUnifyLog tm) = ni env tm
1635 ni env (PDisamb _ tm) = ni env tm
1636 ni env (PNoImplicits tm) = ni env tm
1637 ni env _ = []
1639 niTacImp env (TacImp _ _ scr) = ni env scr
1640 niTacImp _ _ = []
1642-- Return which of the given names are used in the given term.
1644usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1645usedNamesIn vars ist tm = nub $ ni [] tm
1646 where -- TODO THINK added niTacImp, but is it right?
1647 ni env (PRef _ n)
1648 | n `elem` vars && not (n `elem` env)
1649 = case lookupDefExact n (tt_ctxt ist) of
1650 Nothing -> [n]
1651 _ -> []
1652 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1653 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1654 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1655 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1656 ni env (PPi p n ty sc) = niTacImp env p ++ ni env ty ++ ni (n:env) sc
1657 ni env (PEq _ l r) = ni env l ++ ni env r
1658 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1659 ni env (PTyped l r) = ni env l ++ ni env r
1660 ni env (PPair _ _ l r) = ni env l ++ ni env r
1661 ni env (PDPair _ _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1662 ni env (PDPair _ _ l t r) = ni env l ++ ni env t ++ ni env r
1663 ni env (PAlternative a as) = concatMap (ni env) as
1664 ni env (PHidden tm) = ni env tm
1665 ni env (PUnifyLog tm) = ni env tm
1666 ni env (PDisamb _ tm) = ni env tm
1667 ni env (PNoImplicits tm) = ni env tm
1668 ni env _ = []
1670 niTacImp env (TacImp _ _ scr) = ni env scr
1671 niTacImp _ _ = []