2 | import Core.Case.CaseTree
3 | import Core.CompileExpr
4 | import public Core.Context.Context
5 | import public Core.Core
8 | import public Core.Name
10 | import public Core.Options.Log
11 | import public Core.TT
13 | import Libraries.Utils.Binary
14 | import Libraries.Utils.Path
15 | import Libraries.Utils.Scheme
16 | import Libraries.Text.PrettyPrint.Prettyprinter
18 | import Idris.Syntax.Pragmas
25 | import Data.SortedSet
26 | import Libraries.Data.IntMap
27 | import Libraries.Data.NameMap
28 | import Libraries.Data.NatSet
29 | import Libraries.Data.StringMap
30 | import Libraries.Data.UserNameMap
31 | import Libraries.Data.WithDefault
32 | import Libraries.Text.Distance.Levenshtein
35 | import System.Directory
40 | getContent : Context -> Ref Arr (IOArray ContextEntry)
41 | getContent = content
44 | namesResolvedAs : Context -> NameMap Name
45 | namesResolvedAs ctxt = map Resolved ctxt.resolvedAs
50 | decode : Context -> Int -> (update : Bool) -> ContextEntry -> Core GlobalDef
59 | initCtxtS : Int -> Core Context
61 | = do arr <- coreLift $
newArray s
62 | aref <- newRef Arr arr
66 | , resolvedAs = empty
71 | , visibleNS = [partialEvalNS]
73 | , inlineOnly = False
79 | initCtxt : Core Context
80 | initCtxt = initCtxtS initSize
82 | addPossible : Name -> Int ->
83 | UserNameMap (List PossibleName) -> UserNameMap (List PossibleName)
85 | = case userNameRoot n of
88 | case lookup nr ps of
89 | Nothing => insert nr [Direct n i] ps
90 | Just nis => insert nr (Direct n i :: nis) ps
92 | addAlias : Name -> Name -> Int ->
93 | UserNameMap (List PossibleName) -> UserNameMap (List PossibleName)
94 | addAlias alias full i ps
95 | = case userNameRoot alias of
98 | case lookup nr ps of
99 | Nothing => insert nr [Alias alias full i] ps
100 | Just nis => insert nr (Alias alias full i :: nis) ps
103 | newEntry : Name -> Context -> Core (Int, Context)
105 | = do let idx = nextEntry ctxt
106 | let a = content ctxt
108 | when (idx >= max arr) $
109 | do arr' <- coreLift $
newArrayCopy (max arr + Grow) arr
111 | pure (idx, { nextEntry := idx + 1,
112 | resolvedAs $= insert n idx,
113 | possibles $= addPossible n idx
120 | getPosition : Name -> Context -> Core (Int, Context)
121 | getPosition (Resolved idx) ctxt = pure (idx, ctxt)
123 | = case lookup n (resolvedAs ctxt) of
125 | do pure (idx, ctxt)
126 | Nothing => newEntry n ctxt
128 | newAlias : Name -> Name -> Context -> Core Context
129 | newAlias alias full ctxt
130 | = do (idx, ctxt) <- getPosition full ctxt
131 | pure $
{ possibles $= addAlias alias full idx } ctxt
134 | getNameID : Name -> Context -> Maybe Int
135 | getNameID (Resolved idx) ctxt = Just idx
136 | getNameID n ctxt = lookup n (resolvedAs ctxt)
142 | addCtxt : Name -> GlobalDef -> Context -> Core (Int, Context)
143 | addCtxt n val ctxt_in
144 | = if branchDepth ctxt_in == 0
145 | then do (idx, ctxt) <- getPosition n ctxt_in
146 | let a = content ctxt
148 | coreLift_ $
writeArray arr idx (Decoded val)
150 | else do (idx, ctxt) <- getPosition n ctxt_in
151 | pure (idx, { staging $= insert idx (Decoded val) } ctxt)
154 | addEntry : Name -> ContextEntry -> Context -> Core (Int, Context)
155 | addEntry n entry ctxt_in
156 | = if branchDepth ctxt_in == 0
157 | then do (idx, ctxt) <- getPosition n ctxt_in
158 | let a = content ctxt
160 | coreLift_ $
writeArray arr idx entry
162 | else do (idx, ctxt) <- getPosition n ctxt_in
163 | pure (idx, { staging $= insert idx entry } ctxt)
165 | returnDef : Bool -> Int -> GlobalDef -> Maybe (Int, GlobalDef)
166 | returnDef False idx def = Just (idx, def)
167 | returnDef True idx def
168 | = case definition def of
169 | PMDef pi _ _ _ _ =>
171 | then Just (idx, def)
176 | lookupCtxtExactI : Name -> Context -> Core (Maybe (Int, GlobalDef))
177 | lookupCtxtExactI (Resolved idx) ctxt
178 | = case lookup idx (staging ctxt) of
180 | pure $
returnDef (inlineOnly ctxt) idx !(decode ctxt idx True val)
182 | do arr <- get Arr @{content ctxt}
183 | Just def <- coreLift (readArray arr idx)
184 | | Nothing => pure Nothing
185 | pure $
returnDef (inlineOnly ctxt) idx !(decode ctxt idx True def)
186 | lookupCtxtExactI n ctxt
187 | = do let Just idx = lookup n (resolvedAs ctxt)
188 | | Nothing => pure Nothing
189 | lookupCtxtExactI (Resolved idx) ctxt
192 | lookupCtxtExact : Name -> Context -> Core (Maybe GlobalDef)
193 | lookupCtxtExact (Resolved idx) ctxt
194 | = case lookup idx (staging ctxt) of
196 | do def <- decode ctxt idx True res
197 | pure $
map (\(_, def) => def) $
198 | returnDef (inlineOnly ctxt) idx def
200 | do arr <- get Arr @{content ctxt}
201 | Just res <- coreLift (readArray arr idx)
202 | | Nothing => pure Nothing
203 | def <- decode ctxt idx True res
204 | pure $
map (\(_, def) => def) $
205 | returnDef (inlineOnly ctxt) idx def
206 | lookupCtxtExact n ctxt
207 | = do Just (i, def) <- lookupCtxtExactI n ctxt
208 | | Nothing => pure Nothing
212 | lookupContextEntry : Name -> Context -> Core (Maybe (Int, ContextEntry))
213 | lookupContextEntry (Resolved idx) ctxt
214 | = case lookup idx (staging ctxt) of
215 | Just res => pure (Just (idx, res))
217 | do let a = content ctxt
219 | Just res <- coreLift (readArray arr idx)
220 | | Nothing => pure Nothing
221 | pure (Just (idx, res))
222 | lookupContextEntry n ctxt
223 | = do let Just idx = lookup n (resolvedAs ctxt)
224 | | Nothing => pure Nothing
225 | lookupContextEntry (Resolved idx) ctxt
229 | isHidden : Name -> Context -> Bool
230 | isHidden fulln ctxt = isJust $
lookup fulln (hidden ctxt)
235 | lookupCtxtName' : Bool -> Name -> Context -> Core (List (Name, Int, GlobalDef))
236 | lookupCtxtName' allowHidden n ctxt
237 | = case userNameRoot n of
238 | Nothing => do Just (i, res) <- lookupCtxtExactI n ctxt
239 | | Nothing => pure []
242 | do let Just ps = lookup r (possibles ctxt)
243 | | Nothing => pure []
244 | lookupPossibles [] ps
247 | resn : (Name, Int, GlobalDef) -> Int
250 | hlookup : Name -> NameMap () -> Maybe ()
251 | hlookup fulln hiddens = if allowHidden
253 | else lookup fulln hiddens
255 | lookupPossibles : List (Name, Int, GlobalDef) ->
256 | List PossibleName ->
257 | Core (List (Name, Int, GlobalDef))
258 | lookupPossibles acc [] = pure (reverse acc)
259 | lookupPossibles acc (Direct fulln i :: ps)
260 | = case (hlookup fulln (hidden ctxt)) of
262 | do Just res <- lookupCtxtExact (Resolved i) ctxt
263 | | Nothing => lookupPossibles acc ps
264 | if matches n fulln && not (i `elem` map resn acc)
265 | then lookupPossibles ((fulln, i, res) :: acc) ps
266 | else lookupPossibles acc ps
267 | _ => lookupPossibles acc ps
268 | lookupPossibles acc (Alias asn fulln i :: ps)
269 | = case (hlookup fulln (hidden ctxt)) of
271 | do Just res <- lookupCtxtExact (Resolved i) ctxt
272 | | Nothing => lookupPossibles acc ps
273 | if (matches n asn) && not (i `elem` map resn acc)
274 | then lookupPossibles ((fulln, i, res) :: acc) ps
275 | else lookupPossibles acc ps
276 | _ => lookupPossibles acc ps
280 | lookupCtxtName : Name -> Context -> Core (List (Name, Int, GlobalDef))
281 | lookupCtxtName = lookupCtxtName' False
285 | lookupHiddenCtxtName : Name -> Context -> Core (List (Name, Int, GlobalDef))
286 | lookupHiddenCtxtName = lookupCtxtName' True
288 | hideName : Name -> Context -> Context
289 | hideName n ctxt = { hidden $= insert n () } ctxt
291 | unhideName : Name -> Context -> Context
292 | unhideName n ctxt = { hidden $= delete n } ctxt
294 | branchCtxt : Context -> Core Context
295 | branchCtxt ctxt = pure ({ branchDepth $= S } ctxt)
297 | commitCtxt : Context -> Core Context
299 | = case branchDepth ctxt of
302 | do let a = content ctxt
304 | coreLift $
commitStaged (toList (staging ctxt)) arr
305 | pure ({ staging := empty,
306 | branchDepth := Z } ctxt)
307 | S k => pure ({ branchDepth := k } ctxt)
311 | commitStaged : List (Int, ContextEntry) -> IOArray ContextEntry -> IO ()
312 | commitStaged [] arr = pure ()
313 | commitStaged ((idx, val) :: rest) arr
314 | = do ignore $
writeArray arr idx val
315 | commitStaged rest arr
326 | newDef : (fc : FC) -> (n : Name) -> (rig : RigCount) -> (vars : Scope) ->
327 | (ty : ClosedTerm) -> (vis : WithDefault Visibility Private) -> (def : Def) -> GlobalDef
328 | newDef fc n rig vars ty vis def
333 | , eraseArgs = NatSet.empty
334 | , safeErase = NatSet.empty
335 | , specArgs = NatSet.empty
336 | , inferrable = NatSet.empty
337 | , multiplicity = rig
340 | , totality = unchecked
341 | , isEscapeHatch = False
343 | , refersToM = Nothing
344 | , refersToRuntimeM = Nothing
345 | , invertible = False
347 | , linearChecked = False
349 | , compexpr = Nothing
350 | , namedcompexpr = Nothing
352 | , schemeExpr = Nothing
362 | data Transform : Type where
363 | MkTransform : {vars : _} ->
365 | Env Term vars -> Term vars -> Term vars -> Transform
370 | data BuiltinType : Type where
371 | BuiltinNatural : BuiltinType
372 | NaturalToInteger : BuiltinType
373 | IntegerToNatural : BuiltinType
376 | Show BuiltinType where
377 | show BuiltinNatural = "Natural"
378 | show NaturalToInteger = "NaturalToInteger"
379 | show IntegerToNatural = "IntegerToNatural"
382 | getFnName : Transform -> Maybe Name
383 | getFnName (MkTransform _ _ app _)
384 | = case getFn app of
385 | Ref _ _ fn => Just fn
393 | interface HasNames a where
394 | full : Context -> a -> Core a
395 | resolved : Context -> a -> Core a
398 | HasNames Name where
399 | full gam (Resolved i)
400 | = do Just gdef <- lookupCtxtExact (Resolved i) gam
403 | | Nothing => pure (Resolved i)
404 | pure (fullname gdef)
405 | full gam n = pure n
407 | resolved gam (Resolved i)
408 | = pure (Resolved i)
410 | = do let Just i = getNameID n gam
411 | | Nothing => pure n
415 | HasNames UConstraint where
417 | = do x' <- full gam x;
y' <- full gam y
420 | = do x' <- full gam x;
y' <- full gam y
423 | resolved gam (ULT x y)
424 | = do x' <- resolved gam x;
y' <- resolved gam y
426 | resolved gam (ULE x y)
427 | = do x' <- resolved gam x;
y' <- resolved gam y
431 | HasNames (Term vars) where
432 | full gam (Ref fc x (Resolved i))
433 | = do Just gdef <- lookupCtxtExact (Resolved i) gam
434 | | Nothing => pure (Ref fc x (Resolved i))
435 | pure (Ref fc x (fullname gdef))
436 | full gam (Meta fc x i xs)
437 | = do xs <- traverse (full gam) xs
438 | pure $
case !(lookupCtxtExact (Resolved i) gam) of
439 | Nothing => Meta fc x i xs
440 | Just gdef => Meta fc (fullname gdef) i xs
441 | full gam (Bind fc x b scope)
442 | = pure (Bind fc x !(traverse (full gam) b) !(full gam scope))
443 | full gam (App fc fn arg)
444 | = pure (App fc !(full gam fn) !(full gam arg))
445 | full gam (As fc s p tm)
446 | = pure (As fc s !(full gam p) !(full gam tm))
447 | full gam (TDelayed fc x y)
448 | = pure (TDelayed fc x !(full gam y))
449 | full gam (TDelay fc x t y)
450 | = pure (TDelay fc x !(full gam t) !(full gam y))
451 | full gam (TForce fc r y)
452 | = pure (TForce fc r !(full gam y))
453 | full gam (TType fc (Resolved i))
454 | = do Just gdef <- lookupCtxtExact (Resolved i) gam
455 | | Nothing => pure (TType fc (Resolved i))
456 | pure (TType fc (fullname gdef))
457 | full gam (Erased fc (Dotted t))
458 | = pure (Erased fc (Dotted !(full gam t)))
459 | full gam tm = pure tm
461 | resolved gam (Ref fc x n)
462 | = do let Just i = getNameID n gam
463 | | Nothing => pure (Ref fc x n)
464 | pure (Ref fc x (Resolved i))
465 | resolved gam (Meta fc x y xs)
466 | = do xs' <- traverse (resolved gam) xs
467 | let Just i = getNameID x gam
468 | | Nothing => pure (Meta fc x y xs')
469 | pure (Meta fc x i xs')
470 | resolved gam (Bind fc x b scope)
471 | = pure (Bind fc x !(traverse (resolved gam) b) !(resolved gam scope))
472 | resolved gam (App fc fn arg)
473 | = pure (App fc !(resolved gam fn) !(resolved gam arg))
474 | resolved gam (As fc s p tm)
475 | = pure (As fc s !(resolved gam p) !(resolved gam tm))
476 | resolved gam (TDelayed fc x y)
477 | = pure (TDelayed fc x !(resolved gam y))
478 | resolved gam (TDelay fc x t y)
479 | = pure (TDelay fc x !(resolved gam t) !(resolved gam y))
480 | resolved gam (TForce fc r y)
481 | = pure (TForce fc r !(resolved gam y))
482 | resolved gam (TType fc n)
483 | = do let Just i = getNameID n gam
484 | | Nothing => pure (TType fc n)
485 | pure (TType fc (Resolved i))
486 | resolved gam (Erased fc (Dotted t))
487 | = pure (Erased fc (Dotted !(resolved gam t)))
488 | resolved gam tm = pure tm
492 | full gam (PAs fc n p)
493 | = [| PAs (pure fc) (full gam n) (full gam p) |]
494 | full gam (PCon fc n i ar ps)
495 | = [| PCon (pure fc) (full gam n) (pure i) (pure ar) (traverse (full gam) ps) |]
496 | full gam (PTyCon fc n ar ps)
497 | = [| PTyCon (pure fc) (full gam n) (pure ar) (traverse (full gam) ps) |]
498 | full gam p@(PConst {}) = pure p
499 | full gam (PArrow fc x p q)
500 | = [| PArrow (pure fc) (full gam x) (full gam p) (full gam q) |]
501 | full gam (PDelay fc laz p q)
502 | = [| PDelay (pure fc) (pure laz) (full gam p) (full gam q) |]
503 | full gam (PLoc fc n) = PLoc fc <$> full gam n
504 | full gam (PUnmatchable fc t) = PUnmatchable fc <$> full gam t
506 | resolved gam (PAs fc n p)
507 | = [| PAs (pure fc) (resolved gam n) (resolved gam p) |]
508 | resolved gam (PCon fc n i ar ps)
509 | = [| PCon (pure fc) (resolved gam n) (pure i) (pure ar) (traverse (resolved gam) ps) |]
510 | resolved gam (PTyCon fc n ar ps)
511 | = [| PTyCon (pure fc) (resolved gam n) (pure ar) (traverse (resolved gam) ps) |]
512 | resolved gam p@(PConst {}) = pure p
513 | resolved gam (PArrow fc x p q)
514 | = [| PArrow (pure fc) (resolved gam x) (resolved gam p) (resolved gam q) |]
515 | resolved gam (PDelay fc laz p q)
516 | = [| PDelay (pure fc) (pure laz) (resolved gam p) (resolved gam q) |]
517 | resolved gam (PLoc fc n) = PLoc fc <$> resolved gam n
518 | resolved gam (PUnmatchable fc t) = PUnmatchable fc <$> resolved gam t
522 | HasNames (CaseTree vars) where
523 | full gam (Case i v ty alts)
524 | = pure $
Case i v !(full gam ty) !(traverse (full gam) alts)
525 | full gam (STerm i tm)
526 | = pure $
STerm i !(full gam tm)
527 | full gam t = pure t
529 | resolved gam (Case i v ty alts)
530 | = pure $
Case i v !(resolved gam ty) !(traverse (resolved gam) alts)
531 | resolved gam (STerm i tm)
532 | = pure $
STerm i !(resolved gam tm)
533 | resolved gam t = pure t
536 | HasNames (CaseAlt vars) where
537 | full gam (ConCase n t args sc)
538 | = do sc' <- full gam sc
539 | Just gdef <- lookupCtxtExact n gam
540 | | Nothing => pure (ConCase n t args sc')
541 | pure $
ConCase (fullname gdef) t args sc'
542 | full gam (DelayCase ty arg sc)
543 | = pure $
DelayCase ty arg !(full gam sc)
544 | full gam (ConstCase c sc)
545 | = pure $
ConstCase c !(full gam sc)
546 | full gam (DefaultCase sc)
547 | = pure $
DefaultCase !(full gam sc)
549 | resolved gam (ConCase n t args sc)
550 | = do sc' <- resolved gam sc
551 | let Just i = getNameID n gam
552 | | Nothing => pure (ConCase n t args sc')
553 | pure $
ConCase (Resolved i) t args sc'
554 | resolved gam (DelayCase ty arg sc)
555 | = pure $
DelayCase ty arg !(resolved gam sc)
556 | resolved gam (ConstCase c sc)
557 | = pure $
ConstCase c !(resolved gam sc)
558 | resolved gam (DefaultCase sc)
559 | = pure $
DefaultCase !(resolved gam sc)
562 | HasNames (Env Term vars) where
563 | full gam [] = pure Env.empty
565 | = pure $
!(traverse (full gam) b) :: !(full gam bs)
567 | resolved gam [] = pure Env.empty
568 | resolved gam (b :: bs)
569 | = pure $
!(traverse (resolved gam) b) :: !(resolved gam bs)
572 | HasNames Clause where
573 | full gam (MkClause env lhs rhs)
574 | = pure $
MkClause !(full gam env) !(full gam lhs) !(full gam rhs)
576 | resolved gam (MkClause env lhs rhs)
577 | = [| MkClause (resolved gam env) (resolved gam lhs) (resolved gam rhs) |]
582 | full gam (PMDef r args ct rt pats)
583 | = pure $
PMDef r args !(full gam ct) !(full gam rt)
584 | !(traverse fullNamesPat pats)
586 | fullNamesPat : (
vs ** (Env Term vs, Term vs, Term vs))
->
587 | Core (
vs ** (Env Term vs, Term vs, Term vs))
588 | fullNamesPat (
_ ** (env, lhs, rhs))
589 | = pure $ (
_ ** (!(full gam env),
590 | !(full gam lhs), !(full gam rhs)))
591 | full gam (TCon a ps ds u ms mcs det)
592 | = pure $
TCon a ps ds u !(traverse (full gam) ms)
593 | !(traverseOpt (traverse (full gam)) mcs) det
594 | full gam (BySearch c d def)
595 | = pure $
BySearch c d !(full gam def)
596 | full gam (Guess tm b cs)
597 | = pure $
Guess !(full gam tm) b cs
598 | full gam t = pure t
600 | resolved gam (PMDef r args ct rt pats)
601 | = pure $
PMDef r args !(resolved gam ct) !(resolved gam rt)
602 | !(traverse resolvedNamesPat pats)
604 | resolvedNamesPat : (
vs ** (Env Term vs, Term vs, Term vs))
->
605 | Core (
vs ** (Env Term vs, Term vs, Term vs))
606 | resolvedNamesPat (
_ ** (env, lhs, rhs))
607 | = pure $ (
_ ** (!(resolved gam env),
608 | !(resolved gam lhs), !(resolved gam rhs)))
609 | resolved gam (TCon a ps ds u ms mcs det)
610 | = pure $
TCon a ps ds u !(traverse (resolved gam) ms)
611 | !(traverseOpt (traverse (full gam)) mcs) det
612 | resolved gam (BySearch c d def)
613 | = pure $
BySearch c d !(resolved gam def)
614 | resolved gam (Guess tm b cs)
615 | = pure $
Guess !(resolved gam tm) b cs
616 | resolved gam t = pure t
619 | StripNamespace Def where
620 | trimNS ns (PMDef i args ct rt pats)
621 | = PMDef i args (trimNS ns ct) rt (map trimNSpat pats)
623 | trimNSpat : (
vs ** (Env Term vs, Term vs, Term vs))
->
624 | (
vs ** (Env Term vs, Term vs, Term vs))
625 | trimNSpat (
vs ** (env, lhs, rhs))
626 | = (
vs ** (env, trimNS ns lhs, trimNS ns rhs))
629 | restoreNS ns (PMDef i args ct rt pats)
630 | = PMDef i args (restoreNS ns ct) rt (map restoreNSpat pats)
632 | restoreNSpat : (
vs ** (Env Term vs, Term vs, Term vs))
->
633 | (
vs ** (Env Term vs, Term vs, Term vs))
634 | restoreNSpat (
vs ** (env, lhs, rhs))
635 | = (
vs ** (env, restoreNS ns lhs, restoreNS ns rhs))
639 | StripNamespace GlobalDef where
640 | trimNS ns def = { definition $= trimNS ns } def
641 | restoreNS ns def = { definition $= restoreNS ns } def
643 | HasNames (NameMap a) where
645 | = insertAll empty (toList nmap)
647 | insertAll : NameMap a -> List (Name, a) -> Core (NameMap a)
648 | insertAll ms [] = pure ms
649 | insertAll ms ((k, v) :: ns)
650 | = insertAll (insert !(full gam k) v ms) ns
653 | = insertAll empty (toList nmap)
655 | insertAll : NameMap a -> List (Name, a) -> Core (NameMap a)
656 | insertAll ms [] = pure ms
657 | insertAll ms ((k, v) :: ns)
658 | = insertAll (insert !(resolved gam k) v ms) ns
661 | HasNames PartialReason where
662 | full gam NotStrictlyPositive = pure NotStrictlyPositive
663 | full gam (BadCall ns) = pure $
BadCall !(traverse (full gam) ns)
664 | full gam (BadPath init n) = pure $
BadPath !(traverse (traversePair (full gam)) init) !(full gam n)
665 | full gam (RecPath loop) = pure $
RecPath !(traverse (traversePair (full gam)) loop)
667 | resolved gam NotStrictlyPositive = pure NotStrictlyPositive
668 | resolved gam (BadCall ns) = pure $
BadCall !(traverse (resolved gam) ns)
669 | resolved gam (BadPath init n) = pure $
BadPath !(traverse (traversePair (resolved gam)) init) !(resolved gam n)
670 | resolved gam (RecPath loop) = pure $
RecPath !(traverse (traversePair (resolved gam)) loop)
673 | HasNames Terminating where
674 | full gam (NotTerminating p) = pure $
NotTerminating !(full gam p)
675 | full gam t = pure t
677 | resolved gam (NotTerminating p) = pure $
NotTerminating !(resolved gam p)
678 | resolved gam t = pure t
681 | HasNames Covering where
682 | full gam IsCovering = pure IsCovering
683 | full gam (MissingCases ts)
684 | = pure $
MissingCases !(traverse (full gam) ts)
685 | full gam (NonCoveringCall ns)
686 | = pure $
NonCoveringCall !(traverse (full gam) ns)
688 | resolved gam IsCovering = pure IsCovering
689 | resolved gam (MissingCases ts)
690 | = pure $
MissingCases !(traverse (resolved gam) ts)
691 | resolved gam (NonCoveringCall ns)
692 | = pure $
NonCoveringCall !(traverse (resolved gam) ns)
695 | HasNames CaseError where
696 | full gam DifferingArgNumbers = pure DifferingArgNumbers
697 | full gam DifferingTypes = pure DifferingTypes
698 | full gam (MatchErased (
vs ** (rho, t))
) = do
699 | rho <- full gam rho
701 | pure (MatchErased (
vs ** (rho, t))
)
702 | full gam (NotFullyApplied n) = NotFullyApplied <$> full gam n
703 | full gam UnknownType = pure UnknownType
705 | resolved gam DifferingArgNumbers = pure DifferingArgNumbers
706 | resolved gam DifferingTypes = pure DifferingTypes
707 | resolved gam (MatchErased (
vs ** (rho, t))
) = do
708 | rho <- resolved gam rho
709 | t <- resolved gam t
710 | pure (MatchErased (
vs ** (rho, t))
)
711 | resolved gam (NotFullyApplied n) = NotFullyApplied <$> resolved gam n
712 | resolved gam UnknownType = pure UnknownType
716 | HasNames Warning where
717 | full gam (ParserWarning fc x) = pure (ParserWarning fc x)
718 | full gam (UnreachableClause fc rho s) = UnreachableClause fc <$> full gam rho <*> full gam s
719 | full gam (ShadowingGlobalDefs fc xs)
720 | = ShadowingGlobalDefs fc <$> traverseList1 (traversePair (traverseList1 (full gam))) xs
721 | full gam (IncompatibleVisibility fc x y n) = IncompatibleVisibility fc x y <$> full gam n
722 | full gam w@(ShadowingLocalBindings {}) = pure w
723 | full gam (Deprecated fc x y) = Deprecated fc x <$> traverseOpt (traversePair (full gam)) y
724 | full gam (GenericWarn fc x) = pure (GenericWarn fc x)
726 | resolved gam (ParserWarning fc x) = pure (ParserWarning fc x)
727 | resolved gam (UnreachableClause fc rho s) = UnreachableClause fc <$> resolved gam rho <*> resolved gam s
728 | resolved gam (ShadowingGlobalDefs fc xs)
729 | = ShadowingGlobalDefs fc <$> traverseList1 (traversePair (traverseList1 (resolved gam))) xs
730 | resolved gam (IncompatibleVisibility fc x y n) = IncompatibleVisibility fc x y <$> resolved gam n
731 | resolved gam w@(ShadowingLocalBindings {}) = pure w
732 | resolved gam (Deprecated fc x y) = Deprecated fc x <$> traverseOpt (traversePair (resolved gam)) y
733 | resolved gam (GenericWarn fc x) = pure (GenericWarn fc x)
736 | HasNames Error where
737 | full gam (Fatal err) = Fatal <$> full gam err
738 | full _ (CantConvert fc gam rho s t)
739 | = CantConvert fc gam <$> full gam rho <*> full gam s <*> full gam t
740 | full _ (CantSolveEq fc gam rho s t)
741 | = CantSolveEq fc gam <$> full gam rho <*> full gam s <*> full gam t
742 | full gam (PatternVariableUnifies fc fct rho n s)
743 | = PatternVariableUnifies fc fct <$> full gam rho <*> full gam n <*> full gam s
744 | full gam (CyclicMeta fc rho n s)
745 | = CyclicMeta fc <$> full gam rho <*> full gam n <*> full gam s
746 | full _ (WhenUnifying fc gam rho s t err)
747 | = WhenUnifying fc gam <$> full gam rho <*> full gam s <*> full gam t <*> full gam err
748 | full gam (ValidCase fc rho x)
749 | = ValidCase fc <$> full gam rho <*> either (map Left . full gam) (map Right . full gam) x
750 | full gam (UndefinedName fc n) = UndefinedName fc <$> full gam n
751 | full gam (InvisibleName fc n mns) = InvisibleName fc <$> full gam n <*> pure mns
752 | full gam (BadTypeConType fc n) = BadTypeConType fc <$> full gam n
753 | full gam (BadDataConType fc n n') = BadDataConType fc <$> full gam n <*> full gam n'
754 | full gam (NotCovering fc n cov) = NotCovering fc <$> full gam n <*> full gam cov
755 | full gam (NotTotal fc n pr) = NotTotal fc <$> full gam n <*> full gam pr
756 | full gam ImpossibleCase = pure ImpossibleCase
757 | full gam (LinearUsed fc k n) = LinearUsed fc k <$> full gam n
758 | full gam (LinearMisuse fc n x y) = LinearMisuse fc <$> full gam n <*> pure x <*> pure y
759 | full gam (BorrowPartial fc rho s t) = BorrowPartial fc <$> full gam rho <*> full gam s <*> full gam t
760 | full gam (BorrowPartialType fc rho s) = BorrowPartialType fc <$> full gam rho <*> full gam s
761 | full gam (AmbiguousName fc xs) = AmbiguousName fc <$> traverse (full gam) xs
762 | full gam (AmbiguousElab fc rho xs)
763 | = AmbiguousElab fc <$> full gam rho <*> traverse (\ (gam, t) => (gam,) <$> full gam t) xs
764 | full gam (AmbiguousSearch fc rho s xs)
765 | = AmbiguousSearch fc <$> full gam rho <*> full gam s <*> traverse (full gam) xs
766 | full gam (AmbiguityTooDeep fc n xs) = AmbiguityTooDeep fc <$> full gam n <*> traverse (full gam) xs
767 | full gam (AllFailed xs)
768 | = map AllFailed $
for xs $
\ (mn, err) =>
769 | (,) <$> traverseOpt (full gam) mn <*> full gam err
770 | full gam (RecordTypeNeeded fc rho) = RecordTypeNeeded fc <$> full gam rho
771 | full gam (DuplicatedRecordUpdatePath fc xs) = pure (DuplicatedRecordUpdatePath fc xs)
772 | full gam (NotRecordField fc x mn) = NotRecordField fc x <$> traverseOpt (full gam) mn
773 | full gam (NotRecordType fc n) = NotRecordType fc <$> full gam n
774 | full gam (IncompatibleFieldUpdate fc xs) = pure (IncompatibleFieldUpdate fc xs)
775 | full gam (InvalidArgs fc rho xs s) = InvalidArgs fc <$> full gam rho <*> traverse (full gam) xs <*> full gam s
776 | full gam (TryWithImplicits fc rho xs)
777 | = TryWithImplicits fc <$> full gam rho
778 | <*> for xs (\ (n, t) => (,) <$> full gam n <*> full gam t)
779 | full gam (BadUnboundImplicit fc rho n s) = BadUnboundImplicit fc <$> full gam rho <*> full gam n <*> full gam s
780 | full _ (CantSolveGoal fc gam rho s merr)
781 | = CantSolveGoal fc gam <$> full gam rho <*> full gam s <*> traverseOpt (full gam) merr
782 | full gam (DeterminingArg fc n x rho s)
783 | = DeterminingArg fc <$> full gam n <*> pure x <*> full gam rho <*> full gam s
784 | full gam (UnsolvedHoles xs) = UnsolvedHoles <$> traverse (traversePair (full gam)) xs
785 | full gam (CantInferArgType fc rho n n1 s)
786 | = CantInferArgType fc <$> full gam rho <*> full gam n <*> full gam n1 <*> full gam s
787 | full gam (SolvedNamedHole fc rho n s) = SolvedNamedHole fc <$> full gam rho <*> full gam n <*> full gam s
788 | full gam (VisibilityError fc x n y n1) = VisibilityError fc x <$> full gam n <*> pure y <*> full gam n1
789 | full gam (NonLinearPattern fc n) = NonLinearPattern fc <$> full gam n
790 | full gam (BadPattern fc n) = BadPattern fc <$> full gam n
791 | full gam (NoDeclaration fc n) = NoDeclaration fc <$> full gam n
792 | full gam (AlreadyDefined fc n) = AlreadyDefined fc <$> full gam n
793 | full gam (NotFunctionType fc rho s) = NotFunctionType fc <$> full gam rho <*> full gam s
794 | full gam (RewriteNoChange fc rho s t) = RewriteNoChange fc <$> full gam rho <*> full gam s <*> full gam t
795 | full gam (NotRewriteRule fc rho s) = NotRewriteRule fc <$> full gam rho <*> full gam s
796 | full gam (CaseCompile fc n x) = CaseCompile fc <$> full gam n <*> full gam x
797 | full gam (MatchTooSpecific fc rho s) = MatchTooSpecific fc <$> full gam rho <*> full gam s
798 | full gam (BadDotPattern fc rho x s t)
799 | = BadDotPattern fc <$> full gam rho <*> pure x <*> full gam s <*> full gam t
800 | full gam (BadImplicit fc x) = pure (BadImplicit fc x)
801 | full gam (BadRunElab fc rho s desc) = BadRunElab fc <$> full gam rho <*> full gam s <*> pure desc
802 | full gam (RunElabFail e) = RunElabFail <$> full gam e
803 | full gam (GenericMsg fc x) = pure (GenericMsg fc x)
804 | full gam (GenericMsgSol fc x y z) = pure (GenericMsgSol fc x y z)
805 | full gam (TTCError x) = pure (TTCError x)
806 | full gam (FileErr x y) = pure (FileErr x y)
807 | full gam (CantFindPackage x) = pure (CantFindPackage x)
808 | full gam (LazyImplicitFunction fc) = pure (LazyImplicitFunction fc)
809 | full gam (LazyPatternVar fc) = pure (LazyPatternVar fc)
810 | full gam (LitFail fc) = pure (LitFail fc)
811 | full gam (LexFail fc x) = pure (LexFail fc x)
812 | full gam (ParseFail xs) = pure (ParseFail xs)
813 | full gam (ModuleNotFound fc x) = pure (ModuleNotFound fc x)
814 | full gam (CyclicImports xs) = pure (CyclicImports xs)
815 | full gam ForceNeeded = pure ForceNeeded
816 | full gam (InternalError x) = pure (InternalError x)
817 | full gam (UserError x) = pure (UserError x)
818 | full gam (NoForeignCC fc xs) = pure (NoForeignCC fc xs)
819 | full gam (BadMultiline fc x) = pure (BadMultiline fc x)
820 | full gam (Timeout x) = pure (Timeout x)
821 | full gam (FailingDidNotFail fc) = pure (FailingDidNotFail fc)
822 | full gam (FailingWrongError fc x err) = FailingWrongError fc x <$> traverseList1 (full gam) err
823 | full gam (InType fc n err) = InType fc <$> full gam n <*> full gam err
824 | full gam (InCon n err) = InCon <$> traverse (full gam) n <*> full gam err
825 | full gam (InLHS fc n err) = InLHS fc <$> full gam n <*> full gam err
826 | full gam (InRHS fc n err) = InRHS fc <$> full gam n <*> full gam err
827 | full gam (MaybeMisspelling err xs) = MaybeMisspelling <$> full gam err <*> pure xs
828 | full gam (WarningAsError wrn) = WarningAsError <$> full gam wrn
829 | full gam (OperatorBindingMismatch {print} fc expected actual (Left opName) rhs candidates)
830 | = OperatorBindingMismatch {print} fc expected actual
831 | <$> (Left <$> full gam opName) <*> pure rhs <*> pure candidates
832 | full gam (OperatorBindingMismatch {print} fc expected actual (Right opName) rhs candidates)
833 | = OperatorBindingMismatch {print} fc expected actual
834 | <$> (Right <$> full gam opName) <*> pure rhs <*> pure candidates
836 | resolved gam (Fatal err) = Fatal <$> resolved gam err
837 | resolved _ (CantConvert fc gam rho s t)
838 | = CantConvert fc gam <$> resolved gam rho <*> resolved gam s <*> resolved gam t
839 | resolved _ (CantSolveEq fc gam rho s t)
840 | = CantSolveEq fc gam <$> resolved gam rho <*> resolved gam s <*> resolved gam t
841 | resolved gam (PatternVariableUnifies fc fct rho n s)
842 | = PatternVariableUnifies fc fct <$> resolved gam rho <*> resolved gam n <*> resolved gam s
843 | resolved gam (CyclicMeta fc rho n s)
844 | = CyclicMeta fc <$> resolved gam rho <*> resolved gam n <*> resolved gam s
845 | resolved _ (WhenUnifying fc gam rho s t err)
846 | = WhenUnifying fc gam <$> resolved gam rho <*> resolved gam s <*> resolved gam t <*> resolved gam err
847 | resolved gam (ValidCase fc rho x)
848 | = ValidCase fc <$> resolved gam rho <*> either (map Left . resolved gam) (map Right . resolved gam) x
849 | resolved gam (UndefinedName fc n) = UndefinedName fc <$> resolved gam n
850 | resolved gam (InvisibleName fc n mns) = InvisibleName fc <$> resolved gam n <*> pure mns
851 | resolved gam (BadTypeConType fc n) = BadTypeConType fc <$> resolved gam n
852 | resolved gam (BadDataConType fc n n') = BadDataConType fc <$> resolved gam n <*> resolved gam n'
853 | resolved gam (NotCovering fc n cov) = NotCovering fc <$> resolved gam n <*> resolved gam cov
854 | resolved gam (NotTotal fc n pr) = NotTotal fc <$> resolved gam n <*> resolved gam pr
855 | resolved gam ImpossibleCase = pure ImpossibleCase
856 | resolved gam (LinearUsed fc k n) = LinearUsed fc k <$> resolved gam n
857 | resolved gam (LinearMisuse fc n x y) = LinearMisuse fc <$> resolved gam n <*> pure x <*> pure y
858 | resolved gam (BorrowPartial fc rho s t) = BorrowPartial fc <$> resolved gam rho <*> resolved gam s <*> resolved gam t
859 | resolved gam (BorrowPartialType fc rho s) = BorrowPartialType fc <$> resolved gam rho <*> resolved gam s
860 | resolved gam (AmbiguousName fc xs) = AmbiguousName fc <$> traverse (resolved gam) xs
861 | resolved gam (AmbiguousElab fc rho xs)
862 | = AmbiguousElab fc <$> resolved gam rho <*> traverse (\ (gam, t) => (gam,) <$> resolved gam t) xs
863 | resolved gam (AmbiguousSearch fc rho s xs)
864 | = AmbiguousSearch fc <$> resolved gam rho <*> resolved gam s <*> traverse (resolved gam) xs
865 | resolved gam (AmbiguityTooDeep fc n xs) = AmbiguityTooDeep fc <$> resolved gam n <*> traverse (resolved gam) xs
866 | resolved gam (AllFailed xs)
867 | = map AllFailed $
for xs $
\ (mn, err) =>
868 | (,) <$> traverseOpt (resolved gam) mn <*> resolved gam err
869 | resolved gam (RecordTypeNeeded fc rho) = RecordTypeNeeded fc <$> resolved gam rho
870 | resolved gam (DuplicatedRecordUpdatePath fc xs) = pure (DuplicatedRecordUpdatePath fc xs)
871 | resolved gam (NotRecordField fc x mn) = NotRecordField fc x <$> traverseOpt (resolved gam) mn
872 | resolved gam (NotRecordType fc n) = NotRecordType fc <$> resolved gam n
873 | resolved gam (IncompatibleFieldUpdate fc xs) = pure (IncompatibleFieldUpdate fc xs)
874 | resolved gam (InvalidArgs fc rho xs s) = InvalidArgs fc <$> resolved gam rho <*> traverse (resolved gam) xs <*> resolved gam s
875 | resolved gam (TryWithImplicits fc rho xs)
876 | = TryWithImplicits fc <$> resolved gam rho
877 | <*> for xs (\ (n, t) => (,) <$> resolved gam n <*> resolved gam t)
878 | resolved gam (BadUnboundImplicit fc rho n s) = BadUnboundImplicit fc <$> resolved gam rho <*> resolved gam n <*> resolved gam s
879 | resolved _ (CantSolveGoal fc gam rho s merr)
880 | = CantSolveGoal fc gam <$> resolved gam rho <*> resolved gam s <*> traverseOpt (resolved gam) merr
881 | resolved gam (DeterminingArg fc n x rho s)
882 | = DeterminingArg fc <$> resolved gam n <*> pure x <*> resolved gam rho <*> resolved gam s
883 | resolved gam (UnsolvedHoles xs) = UnsolvedHoles <$> traverse (traversePair (resolved gam)) xs
884 | resolved gam (CantInferArgType fc rho n n1 s)
885 | = CantInferArgType fc <$> resolved gam rho <*> resolved gam n <*> resolved gam n1 <*> resolved gam s
886 | resolved gam (SolvedNamedHole fc rho n s) = SolvedNamedHole fc <$> resolved gam rho <*> resolved gam n <*> resolved gam s
887 | resolved gam (VisibilityError fc x n y n1) = VisibilityError fc x <$> resolved gam n <*> pure y <*> resolved gam n1
888 | resolved gam (NonLinearPattern fc n) = NonLinearPattern fc <$> resolved gam n
889 | resolved gam (BadPattern fc n) = BadPattern fc <$> resolved gam n
890 | resolved gam (NoDeclaration fc n) = NoDeclaration fc <$> resolved gam n
891 | resolved gam (AlreadyDefined fc n) = AlreadyDefined fc <$> resolved gam n
892 | resolved gam (NotFunctionType fc rho s) = NotFunctionType fc <$> resolved gam rho <*> resolved gam s
893 | resolved gam (RewriteNoChange fc rho s t) = RewriteNoChange fc <$> resolved gam rho <*> resolved gam s <*> resolved gam t
894 | resolved gam (NotRewriteRule fc rho s) = NotRewriteRule fc <$> resolved gam rho <*> resolved gam s
895 | resolved gam (CaseCompile fc n x) = CaseCompile fc <$> resolved gam n <*> resolved gam x
896 | resolved gam (MatchTooSpecific fc rho s) = MatchTooSpecific fc <$> resolved gam rho <*> resolved gam s
897 | resolved gam (BadDotPattern fc rho x s t)
898 | = BadDotPattern fc <$> resolved gam rho <*> pure x <*> resolved gam s <*> resolved gam t
899 | resolved gam (BadImplicit fc x) = pure (BadImplicit fc x)
900 | resolved gam (BadRunElab fc rho s desc) = BadRunElab fc <$> resolved gam rho <*> resolved gam s <*> pure desc
901 | resolved gam (RunElabFail e) = RunElabFail <$> resolved gam e
902 | resolved gam (GenericMsg fc x) = pure (GenericMsg fc x)
903 | resolved gam (GenericMsgSol fc x y z) = pure (GenericMsgSol fc x y z)
904 | resolved gam (TTCError x) = pure (TTCError x)
905 | resolved gam (FileErr x y) = pure (FileErr x y)
906 | resolved gam (CantFindPackage x) = pure (CantFindPackage x)
907 | resolved gam (LazyImplicitFunction fc) = pure (LazyImplicitFunction fc)
908 | resolved gam (LazyPatternVar fc) = pure (LazyPatternVar fc)
909 | resolved gam (LitFail fc) = pure (LitFail fc)
910 | resolved gam (LexFail fc x) = pure (LexFail fc x)
911 | resolved gam (ParseFail xs) = pure (ParseFail xs)
912 | resolved gam (ModuleNotFound fc x) = pure (ModuleNotFound fc x)
913 | resolved gam (CyclicImports xs) = pure (CyclicImports xs)
914 | resolved gam ForceNeeded = pure ForceNeeded
915 | resolved gam (InternalError x) = pure (InternalError x)
916 | resolved gam (UserError x) = pure (UserError x)
917 | resolved gam (NoForeignCC fc xs) = pure (NoForeignCC fc xs)
918 | resolved gam (BadMultiline fc x) = pure (BadMultiline fc x)
919 | resolved gam (Timeout x) = pure (Timeout x)
920 | resolved gam (FailingDidNotFail fc) = pure (FailingDidNotFail fc)
921 | resolved gam (FailingWrongError fc x err) = FailingWrongError fc x <$> traverseList1 (resolved gam) err
922 | resolved gam (InType fc n err) = InType fc <$> resolved gam n <*> resolved gam err
923 | resolved gam (InCon n err) = InCon <$> traverse (resolved gam) n <*> resolved gam err
924 | resolved gam (InLHS fc n err) = InLHS fc <$> resolved gam n <*> resolved gam err
925 | resolved gam (InRHS fc n err) = InRHS fc <$> resolved gam n <*> resolved gam err
926 | resolved gam (MaybeMisspelling err xs) = MaybeMisspelling <$> resolved gam err <*> pure xs
927 | resolved gam (WarningAsError wrn) = WarningAsError <$> resolved gam wrn
928 | resolved gam (OperatorBindingMismatch {print} fc expected actual (Left opName) rhs candidates)
929 | = OperatorBindingMismatch {print} fc expected actual
930 | <$> (Left <$> resolved gam opName) <*> pure rhs <*> pure candidates
931 | resolved gam (OperatorBindingMismatch {print} fc expected actual (Right opName) rhs candidates)
932 | = OperatorBindingMismatch {print} fc expected actual
933 | <$> (Right <$> resolved gam opName) <*> pure rhs <*> pure candidates
936 | HasNames Totality where
937 | full gam (MkTotality t c) = pure $
MkTotality !(full gam t) !(full gam c)
938 | resolved gam (MkTotality t c) = pure $
MkTotality !(resolved gam t) !(resolved gam c)
941 | HasNames SCCall where
942 | full gam sc = pure $
{ fnCall := !(full gam (fnCall sc)) } sc
943 | resolved gam sc = pure $
{ fnCall := !(resolved gam (fnCall sc)) } sc
946 | HasNames a => HasNames (Maybe a) where
947 | full gam Nothing = pure Nothing
948 | full gam (Just x) = pure $
Just !(full gam x)
949 | resolved gam Nothing = pure Nothing
950 | resolved gam (Just x) = pure $
Just !(resolved gam x)
953 | HasNames GlobalDef where
960 | pure $
{ type := !(full gam (type def)),
961 | definition := !(full gam (definition def)),
962 | totality := !(full gam (totality def)),
963 | refersToM := !(full gam (refersToM def)),
964 | refersToRuntimeM := !(full gam (refersToRuntimeM def)),
965 | sizeChange := !(traverse (full gam) (sizeChange def))
968 | = pure $
{ type := !(resolved gam (type def)),
969 | definition := !(resolved gam (definition def)),
970 | totality := !(resolved gam (totality def)),
971 | refersToM := !(resolved gam (refersToM def)),
972 | refersToRuntimeM := !(resolved gam (refersToRuntimeM def)),
973 | sizeChange := !(traverse (resolved gam) (sizeChange def))
977 | HasNames Transform where
978 | full gam (MkTransform n env lhs rhs)
979 | = pure $
MkTransform !(full gam n) !(full gam env)
980 | !(full gam lhs) !(full gam rhs)
982 | resolved gam (MkTransform n env lhs rhs)
983 | = pure $
MkTransform !(resolved gam n) !(resolved gam env)
984 | !(resolved gam lhs) !(resolved gam rhs)
988 | allNames : Context -> Core (List Name)
989 | allNames ctxt = traverse (full ctxt) $
map Resolved [1..nextEntry ctxt - 1]
995 | mutData : List Name
996 | currentNS : Namespace
997 | nestedNS : List Namespace
999 | toSave : NameMap ()
1000 | typeHints : NameMap (List (Name, Bool))
1006 | autoHints : NameMap Bool
1014 | localHints : NameMap ()
1016 | saveTypeHints : List (Name, Name, Bool)
1019 | saveAutoHints : List (Name, Bool)
1020 | transforms : NameMap (List Transform)
1023 | saveTransforms : List (Name, Transform)
1024 | pendingTransforms : List (Name, Transform)
1027 | namedirectives : NameMap (List String)
1029 | importHashes : List (Namespace, Int)
1031 | imported : List (ModuleIdent, Bool, Namespace)
1033 | allImported : List (String, (ModuleIdent, Bool, Namespace))
1037 | cgdirectives : SortedSet (CG, String)
1040 | toCompileCase : List Name
1042 | incData : List (CG, String, List String)
1045 | allIncData : List (CG, List String, List String)
1051 | userHoles : NameMap Bool
1055 | peFailures : NameMap ()
1058 | timings : StringMap (Bool, Integer)
1060 | timer : Maybe (Integer, String)
1063 | warnings : List Warning
1065 | schemeEvalLoaded : Bool
1066 | foreignExports : NameMap (List (String, String))
1069 | defsStack : SnocList Name
1077 | clearDefs : Defs -> Core Defs
1079 | = pure ({ gamma->inlineOnly := True } defs)
1101 | , pendingTransforms = []
1102 | , namedirectives = empty
1107 | , cgdirectives = SortedSet.empty
1117 | , schemeEvalLoaded = False
1118 | , foreignExports = empty
1124 | clearCtxt : {auto c : Ref Ctxt Defs} ->
1128 | put Ctxt ({ options := resetElab (options defs),
1129 | timings := timings defs } !initDefs)
1131 | resetElab : Options -> Options
1133 | let tot = totalReq (session opts) in
1134 | { elabDirectives := { totality := tot } defaultElab } opts
1137 | getFieldNames : Context -> Namespace -> List Name
1138 | getFieldNames ctxt recNS
1139 | = let nms = resolvedAs ctxt in
1140 | keys $
flip filterBy nms $
\ n =>
1143 | Just (ns, field) => ns == recNS
1147 | getSimilarNames : {auto c : Ref Ctxt Defs} ->
1150 | {default Nothing keepPredicate : Maybe ((Name, GlobalDef) -> Core Bool)} ->
1151 | Name -> Core (Maybe (String, List (Name, Visibility, Nat)))
1152 | getSimilarNames nm = case show <$> userNameRoot nm of
1153 | Nothing => pure Nothing
1154 | Just str => if length str <= 1 then pure (Just (str, [])) else
1156 | let threshold : Nat := max 1 (assert_total (divNat (length str) 3))
1157 | let test : Name -> Core (Maybe (Visibility, Nat)) := \ nm => do
1158 | let (Just str') = show <$> userNameRoot nm
1160 | dist <- coreLift $
Levenshtein.compute str str'
1161 | let True = dist <= threshold
1162 | | False => pure Nothing
1163 | Just def <- lookupCtxtExact nm (gamma defs)
1164 | | Nothing => pure Nothing
1165 | let predicate = fromMaybe (\_ => pure True) keepPredicate
1166 | True <- predicate (nm, def)
1167 | | False => pure Nothing
1168 | pure (Just (collapseDefault $
visibility def, dist))
1169 | kept <- NameMap.mapMaybeM @{CORE} test (resolvedAs (gamma defs))
1170 | pure $
Just (str, toList kept)
1173 | showSimilarNames : Namespace -> Name -> String ->
1174 | List (Name, Visibility, Nat) -> List String
1175 | showSimilarNames ns nm str kept
1176 | = let (loc, priv) := partitionEithers $
kept <&> \ (nm', vis, n) =>
1177 | let False = fst (splitNS nm') `isParentOf` ns
1182 | sorted := sortBy (compare `on` snd)
1183 | roots1 := mapMaybe (showNames nm str False . fst) (sorted loc)
1184 | roots2 := mapMaybe (showNames nm str True . fst) (sorted priv)
1185 | in nub roots1 ++ nub roots2
1189 | showNames : Name -> String -> Bool -> Name -> Maybe String
1190 | showNames target str priv nm = do
1191 | let adj = if priv then " (not exported)" else ""
1194 | | _ => pure (root ++ adj)
1195 | let full = show (pretty nm)
1196 | let True = (str == full || show target == full) && not priv
1197 | | _ => pure (full ++ adj)
1201 | getVisibility : {auto c : Ref Ctxt Defs} ->
1202 | FC -> Name -> Core (WithDefault Visibility Private)
1205 | Just def <- lookupCtxtExact n (gamma defs)
1206 | | Nothing => throw (UndefinedName fc n)
1209 | maybeMisspelling : {auto c : Ref Ctxt Defs} ->
1210 | Error -> Name -> Core a
1211 | maybeMisspelling err nm = do
1212 | ns <- currentNS <$> get Ctxt
1213 | Just (str, kept) <- getSimilarNames nm
1215 | let candidates = showSimilarNames ns nm str kept
1218 | (x::xs) => throw (MaybeMisspelling err (x ::: xs))
1222 | undefinedName : {auto c : Ref Ctxt Defs} ->
1224 | undefinedName loc nm = maybeMisspelling (UndefinedName loc nm) nm
1228 | noDeclaration : {auto c : Ref Ctxt Defs} ->
1230 | noDeclaration loc nm = maybeMisspelling (NoDeclaration loc nm) nm
1233 | ambiguousName : {auto c : Ref Ctxt Defs} -> FC
1236 | ambiguousName fc n ns = do
1237 | ns <- filterM (\x => pure $
!(collapseDefault <$> getVisibility fc x) /= Private) ns
1239 | [] => undefinedName fc n
1240 | ns => throw $
AmbiguousName fc ns
1245 | canonicalName : {auto c : Ref Ctxt Defs} ->
1246 | FC -> Name -> Core Name
1249 | case !(lookupCtxtName n (gamma defs)) of
1251 | ns => ambiguousName fc n (map fst ns)
1255 | aliasName : {auto c : Ref Ctxt Defs} ->
1259 | let Just r = userNameRoot fulln
1260 | | Nothing => pure fulln
1261 | let Just ps = lookup r (possibles (gamma defs))
1262 | | Nothing => pure fulln
1265 | findAlias : List PossibleName -> Core Name
1266 | findAlias [] = pure fulln
1267 | findAlias (Alias as full i :: ps)
1271 | findAlias (_ :: ps) = findAlias ps
1277 | addHash : {auto c : Ref Ctxt Defs} -> Hashable a => a -> Core ()
1278 | addHash x = update Ctxt { ifaceHash $= flip hashWithSalt x }
1281 | initHash : {auto c : Ref Ctxt Defs} -> Core ()
1282 | initHash = update Ctxt { ifaceHash := 5381 }
1285 | addUserHole : {auto c : Ref Ctxt Defs} ->
1289 | addUserHole ext n = update Ctxt { userHoles $= insert n ext }
1292 | clearUserHole : {auto c : Ref Ctxt Defs} -> Name -> Core ()
1293 | clearUserHole n = update Ctxt { userHoles $= delete n }
1296 | getUserHoles : {auto c : Ref Ctxt Defs} ->
1300 | let hs = sort (keys (userHoles defs))
1301 | filterM (isHole defs) hs
1307 | isHole : Defs -> Name -> Core Bool
1309 | = do Just def <- lookupCtxtExact n (gamma defs)
1311 | pure $
case definition def of
1317 | addDef : {auto c : Ref Ctxt Defs} ->
1318 | Name -> GlobalDef -> Core Int
1321 | (idx, gam') <- addCtxt n def (gamma defs)
1322 | put Ctxt ({ gamma := gam' } defs)
1326 | _ => clearUserHole (fullname def)
1330 | addContextEntry : {auto c : Ref Ctxt Defs} ->
1331 | Namespace -> Name -> Binary -> Core Int
1332 | addContextEntry ns n def
1334 | (idx, gam') <- addEntry n (Coded ns def) (gamma defs)
1335 | put Ctxt ({ gamma := gam' } defs)
1339 | addContextAlias : {auto c : Ref Ctxt Defs} ->
1340 | Name -> Name -> Core ()
1341 | addContextAlias alias full
1343 | Nothing <- lookupCtxtExact alias (gamma defs)
1345 | gam' <- newAlias alias full (gamma defs)
1346 | put Ctxt ({ gamma := gam' } defs)
1349 | addBuiltin : {arity : _} ->
1350 | {auto x : Ref Ctxt Defs} ->
1351 | Name -> ClosedTerm -> Totality ->
1352 | PrimFn arity -> Core ()
1359 | , eraseArgs = NatSet.empty
1360 | , safeErase = NatSet.empty
1361 | , specArgs = NatSet.empty
1362 | , inferrable = NatSet.empty
1364 | , localVars = Scope.empty
1365 | , visibility = specified Public
1367 | , isEscapeHatch = False
1370 | , refersToRuntimeM = Nothing
1374 | , definition = Builtin op
1376 | , namedcompexpr = Nothing
1382 | updateDef : {auto c : Ref Ctxt Defs} ->
1383 | Name -> (Def -> Maybe Def) -> Core ()
1386 | Just gdef <- lookupCtxtExact n (gamma defs)
1388 | case fdef (definition gdef) of
1390 | Just def' => ignore $
addDef n ({ definition := def',
1391 | schemeExpr := Nothing } gdef)
1394 | updateTy : {auto c : Ref Ctxt Defs} ->
1395 | Int -> ClosedTerm -> Core ()
1398 | Just gdef <- lookupCtxtExact (Resolved i) (gamma defs)
1400 | ignore $
addDef (Resolved i) ({ type := ty } gdef)
1403 | setCompiled : {auto c : Ref Ctxt Defs} ->
1404 | Name -> CDef -> Core ()
1407 | Just gdef <- lookupCtxtExact n (gamma defs)
1409 | ignore $
addDef n ({ compexpr := Just cexp } gdef)
1414 | setLinearCheck : {auto c : Ref Ctxt Defs} ->
1418 | Just gdef <- lookupCtxtExact (Resolved i) (gamma defs)
1420 | ignore $
addDef (Resolved i) ({ linearChecked := chk } gdef)
1423 | setCtxt : {auto c : Ref Ctxt Defs} -> Context -> Core ()
1424 | setCtxt gam = update Ctxt { gamma := gam }
1427 | resolveName : {auto c : Ref Ctxt Defs} ->
1429 | resolveName (Resolved idx) = pure idx
1432 | (i, gam') <- getPosition n (gamma defs)
1437 | addName : {auto c : Ref Ctxt Defs} ->
1439 | addName (Resolved idx) = pure idx
1442 | (i, gam') <- newEntry n (gamma defs)
1451 | branch : {auto c : Ref Ctxt Defs} ->
1455 | gam' <- branchCtxt (gamma ctxt)
1463 | commit : {auto c : Ref Ctxt Defs} ->
1467 | gam' <- commitCtxt (gamma defs)
1471 | depth : {auto c : Ref Ctxt Defs} ->
1475 | pure (branchDepth (gamma defs))
1478 | dumpStaging : {auto c : Ref Ctxt Defs} ->
1482 | coreLift $
putStrLn $
"Staging area: " ++ show (keys (staging (gamma defs)))
1486 | addToSave : {auto c : Ref Ctxt Defs} ->
1490 | n <- full (gamma defs) n_in
1491 | put Ctxt ({ toSave $= insert n (),
1497 | lookupExactBy : (GlobalDef -> a) -> Name -> Context ->
1500 | = do Just gdef <- lookupCtxtExact n gam
1501 | | Nothing => pure Nothing
1505 | lookupNameBy : (GlobalDef -> a) -> Name -> Context ->
1506 | Core (List (Name, Int, a))
1508 | = do gdef <- lookupCtxtName n gam
1509 | pure (map (\ (n, i, gd) => (n, i, fn gd)) gdef)
1512 | lookupDefExact : Name -> Context -> Core (Maybe Def)
1513 | lookupDefExact = lookupExactBy definition
1516 | lookupDefName : Name -> Context -> Core (List (Name, Int, Def))
1517 | lookupDefName = lookupNameBy definition
1520 | lookupTyExact : Name -> Context -> Core (Maybe ClosedTerm)
1521 | lookupTyExact = lookupExactBy type
1524 | lookupTyName : Name -> Context -> Core (List (Name, Int, ClosedTerm))
1525 | lookupTyName = lookupNameBy type
1528 | lookupDefTyExact : Name -> Context -> Core (Maybe (Def, ClosedTerm))
1529 | lookupDefTyExact = lookupExactBy (\g => (definition g, type g))
1535 | visibleIn : Namespace -> Name -> Visibility -> Bool
1536 | visibleIn nspace (NS ns n) Private = isParentOf ns nspace
1538 | visibleIn nspace n _ = True
1541 | visibleInAny : List Namespace -> Name -> Visibility -> Bool
1542 | visibleInAny nss n vis = any (\ns => visibleIn ns n vis) nss
1544 | reducibleIn : Namespace -> Name -> Visibility -> Bool
1545 | reducibleIn nspace (NS ns (UN n)) Export = isParentOf ns nspace
1546 | reducibleIn nspace (NS ns (UN n)) Private = isParentOf ns nspace
1547 | reducibleIn nspace n _ = True
1550 | reducibleInAny : List Namespace -> Name -> Visibility -> Bool
1551 | reducibleInAny nss n vis = any (\ns => reducibleIn ns n vis) nss
1554 | toFullNames : {auto c : Ref Ctxt Defs} ->
1555 | HasNames a => a -> Core a
1561 | toResolvedNames : {auto c : Ref Ctxt Defs} ->
1562 | HasNames a => a -> Core a
1565 | resolved (gamma defs) t
1569 | prettyName : {auto c : Ref Ctxt Defs} ->
1571 | prettyName (Nested (i, _) n)
1572 | = do i' <- toFullNames (Resolved i)
1573 | pure (!(prettyName i') ++ "," ++
1575 | prettyName (CaseBlock outer idx)
1576 | = pure ("case block in " ++ outer)
1577 | prettyName (WithBlock outer idx)
1578 | = pure ("with block in " ++ outer)
1579 | prettyName (NS ns n) = prettyName n
1580 | prettyName n = pure (show n)
1587 | addHashWithNames : {auto c : Ref Ctxt Defs} ->
1588 | Hashable a => HasNames a => a -> Core ()
1589 | addHashWithNames x = toFullNames x >>= addHash
1592 | setIsEscapeHatch : {auto c : Ref Ctxt Defs} ->
1596 | Just def <- lookupCtxtExact n (gamma defs)
1597 | | Nothing => undefinedName fc n
1598 | ignore $
addDef n ({ isEscapeHatch := True } def)
1601 | setFlag : {auto c : Ref Ctxt Defs} ->
1602 | FC -> Name -> DefFlag -> Core ()
1605 | Just def <- lookupCtxtExact n (gamma defs)
1606 | | Nothing => undefinedName fc n
1607 | let flags' = fl :: filter (/= fl) (flags def)
1608 | ignore $
addDef n ({ flags := flags' } def)
1611 | setNameFlag : {auto c : Ref Ctxt Defs} ->
1612 | FC -> Name -> DefFlag -> Core ()
1615 | [(n', i, def)] <- lookupCtxtName n (gamma defs)
1616 | | res => ambiguousName fc n (map fst res)
1617 | let flags' = fl :: filter (/= fl) (flags def)
1618 | ignore $
addDef (Resolved i) ({ flags := flags' } def)
1621 | unsetFlag : {auto c : Ref Ctxt Defs} ->
1622 | FC -> Name -> DefFlag -> Core ()
1625 | Just def <- lookupCtxtExact n (gamma defs)
1626 | | Nothing => undefinedName fc n
1627 | let flags' = filter (/= fl) (flags def)
1628 | ignore $
addDef n ({ flags := flags' } def)
1631 | hasFlag : {auto c : Ref Ctxt Defs} ->
1632 | FC -> Name -> DefFlag -> Core Bool
1635 | Just def <- lookupCtxtExact n (gamma defs)
1636 | | Nothing => undefinedName fc n
1637 | pure (fl `elem` flags def)
1640 | hasSetTotal : {auto c : Ref Ctxt Defs} -> FC -> Name -> Core Bool
1643 | Just def <- lookupCtxtExact n (gamma defs)
1644 | | Nothing => undefinedName fc n
1645 | pure $
isJust $
findSetTotal def.flags
1648 | setSizeChange : {auto c : Ref Ctxt Defs} ->
1649 | FC -> Name -> List SCCall -> Core ()
1652 | Just def <- lookupCtxtExact n (gamma defs)
1653 | | Nothing => undefinedName loc n
1654 | ignore $
addDef n ({ sizeChange := sc } def)
1657 | setTotality : {auto c : Ref Ctxt Defs} ->
1658 | FC -> Name -> Totality -> Core ()
1661 | Just def <- lookupCtxtExact n (gamma defs)
1662 | | Nothing => undefinedName loc n
1663 | ignore $
addDef n ({ totality := tot } def)
1666 | setCovering : {auto c : Ref Ctxt Defs} ->
1667 | FC -> Name -> Covering -> Core ()
1670 | Just def <- lookupCtxtExact n (gamma defs)
1671 | | Nothing => undefinedName loc n
1672 | ignore $
addDef n ({ totality->isCovering := tot } def)
1675 | setTerminating : {auto c : Ref Ctxt Defs} ->
1676 | FC -> Name -> Terminating -> Core ()
1677 | setTerminating loc n tot
1679 | Just def <- lookupCtxtExact n (gamma defs)
1680 | | Nothing => undefinedName loc n
1681 | ignore $
addDef n ({ totality->isTerminating := tot } def)
1684 | getTotality : {auto c : Ref Ctxt Defs} ->
1685 | FC -> Name -> Core Totality
1688 | Just def <- lookupCtxtExact n (gamma defs)
1689 | | Nothing => undefinedName loc n
1693 | getSizeChange : {auto c : Ref Ctxt Defs} ->
1694 | FC -> Name -> Core (List SCCall)
1697 | Just def <- lookupCtxtExact n (gamma defs)
1698 | | Nothing => undefinedName loc n
1702 | setVisibility : {auto c : Ref Ctxt Defs} ->
1703 | FC -> Name -> Visibility -> Core ()
1706 | Just def <- lookupCtxtExact n (gamma defs)
1707 | | Nothing => undefinedName fc n
1708 | ignore $
addDef n ({ visibility := specified vis } def)
1711 | withDefStacked : {auto c : Ref Ctxt Defs} ->
1712 | Name -> Core a -> Core a
1715 | let ds = defs.defsStack
1716 | put Ctxt $
{defsStack $= (:< n)} defs
1717 | act <* update Ctxt {defsStack := ds}
1720 | record SearchData where
1721 | constructor MkSearchData
1737 | hintGroups : List (Bool, List Name)
1741 | getSearchData : {auto c : Ref Ctxt Defs} ->
1742 | FC -> (defaults : Bool) -> Name ->
1744 | getSearchData fc defaults target
1746 | Just (TCon _ _ dets u _ _ _) <- lookupDefExact target (gamma defs)
1747 | | _ => undefinedName fc target
1748 | hs <- case lookup !(toFullNames target) (typeHints defs) of
1749 | Just hs => filterM (\x => notHidden x (gamma defs)) hs
1752 | then let defns = map fst !(filterM (\x => pure $
isDefault x
1753 | && !(notHidden x (gamma defs)))
1754 | (toList (autoHints defs))) in
1755 | pure (MkSearchData NatSet.empty [(False, defns)])
1756 | else let opens = map fst !(filterM (\x => notHidden x (gamma defs))
1757 | (toList (openHints defs)))
1758 | autos = map fst !(filterM (\x => pure $
not (isDefault x)
1759 | && !(notHidden x (gamma defs)))
1760 | (toList (autoHints defs)))
1761 | tyhs = map fst (filter direct hs)
1762 | chasers = map fst (filter (not . direct) hs) in
1763 | pure (MkSearchData dets (filter (isCons . snd)
1766 | (not (uniqueAuto u), tyhs),
1771 | notHidden : forall a. (Name, a) -> Context -> Core Bool
1772 | notHidden (n, _) ctxt = do
1774 | pure $
not (isHidden fulln ctxt)
1776 | isDefault : (Name, Bool) -> Bool
1779 | direct : (Name, Bool) -> Bool
1783 | setMutWith : {auto c : Ref Ctxt Defs} ->
1784 | FC -> Name -> List Name -> Core ()
1787 | Just g <- lookupCtxtExact tn (gamma defs)
1788 | | _ => undefinedName fc tn
1789 | let TCon a ps dets u _ cons det = definition g
1790 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setMutWith]"))
1791 | updateDef tn (const (Just (TCon a ps dets u tns cons det)))
1794 | addMutData : {auto c : Ref Ctxt Defs} ->
1796 | addMutData n = update Ctxt { mutData $= (n ::) }
1799 | dropMutData : {auto c : Ref Ctxt Defs} ->
1801 | dropMutData n = update Ctxt { mutData $= filter (/= n) }
1804 | setDetermining : {auto c : Ref Ctxt Defs} ->
1805 | FC -> Name -> List1 Name -> Core ()
1806 | setDetermining fc tyn args
1808 | Just g <- lookupCtxtExact tyn (gamma defs)
1809 | | _ => undefinedName fc tyn
1810 | let TCon a ps _ u cons ms det = definition g
1811 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]"))
1812 | apos <- getPos 0 (forget args) (type g)
1813 | updateDef tyn (const (Just (TCon a ps apos u cons ms det)))
1817 | getPos : Nat -> List Name -> Term vs -> Core NatSet
1818 | getPos i ns (Bind _ x (Pi {}) sc)
1820 | then do rest <- getPos (1 + i) (filter (/=x) ns) sc
1822 | else getPos (1 + i) ns sc
1823 | getPos _ [] _ = pure NatSet.empty
1824 | getPos _ ns ty = throw (GenericMsg fc ("Unknown determining arguments: "
1825 | ++ showSep ", " (map show ns)))
1828 | setDetags : {auto c : Ref Ctxt Defs} ->
1829 | FC -> Name -> Maybe NatSet -> Core ()
1832 | Just g <- lookupCtxtExact tyn (gamma defs)
1833 | | _ => undefinedName fc tyn
1834 | let TCon a ps det u cons ms _ = definition g
1835 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]"))
1836 | updateDef tyn (const (Just (TCon a ps det u cons ms args)))
1839 | setUniqueSearch : {auto c : Ref Ctxt Defs} ->
1840 | FC -> Name -> Bool -> Core ()
1841 | setUniqueSearch fc tyn u
1843 | Just g <- lookupCtxtExact tyn (gamma defs)
1844 | | _ => undefinedName fc tyn
1845 | let TCon a ps ds fl cons ms det = definition g
1846 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]"))
1847 | let fl' = { uniqueAuto := u } fl
1848 | updateDef tyn (const (Just (TCon a ps ds fl' cons ms det)))
1851 | setExternal : {auto c : Ref Ctxt Defs} ->
1852 | FC -> Name -> Bool -> Core ()
1855 | Just g <- lookupCtxtExact tyn (gamma defs)
1856 | | _ => undefinedName fc tyn
1857 | let TCon a ps ds fl cons ms det = definition g
1858 | | _ => throw (GenericMsg fc (show (fullname g) ++ " is not a type constructor [setDetermining]"))
1859 | let fl' = { external := u } fl
1860 | updateDef tyn (const (Just (TCon a ps ds fl' cons ms det)))
1863 | addHintFor : {auto c : Ref Ctxt Defs} ->
1864 | FC -> Name -> Name -> Bool -> Bool -> Core ()
1865 | addHintFor fc tyn_in hintn_in direct loading
1867 | tyn <- toFullNames tyn_in
1871 | hintn <- toResolvedNames hintn_in
1873 | let hs = case lookup tyn (typeHints defs) of
1878 | ({ typeHints $= insert tyn ((hintn, direct) :: hs)
1881 | ({ typeHints $= insert tyn ((hintn, direct) :: hs),
1882 | saveTypeHints $= ((tyn, hintn, direct) :: )
1886 | addGlobalHint : {auto c : Ref Ctxt Defs} ->
1887 | Name -> Bool -> Core ()
1888 | addGlobalHint hintn_in isdef
1889 | = do hintn <- toResolvedNames hintn_in
1890 | update Ctxt { autoHints $= insert hintn isdef,
1891 | saveAutoHints $= ((hintn, isdef) ::) }
1894 | addLocalHint : {auto c : Ref Ctxt Defs} ->
1897 | = do hintn <- toResolvedNames hintn_in
1898 | update Ctxt { localHints $= insert hintn () }
1901 | addOpenHint : {auto c : Ref Ctxt Defs} -> Name -> Core ()
1903 | = do hintn <- toResolvedNames hintn_in
1904 | update Ctxt { openHints $= insert hintn () }
1907 | dropOpenHint : {auto c : Ref Ctxt Defs} -> Name -> Core ()
1909 | = do hintn <- toResolvedNames hintn_in
1910 | update Ctxt { openHints $= delete hintn }
1913 | setOpenHints : {auto c : Ref Ctxt Defs} -> NameMap () -> Core ()
1914 | setOpenHints hs = update Ctxt { openHints := hs }
1917 | insertTransform : Name -> Transform ->
1918 | NameMap (List Transform) -> NameMap (List Transform)
1919 | insertTransform fn t ts = insert fn (maybe [t] (t ::) (lookup fn ts)) ts
1928 | resolveTransforms : {auto c : Ref Ctxt Defs} -> Core ()
1931 | case pendingTransforms defs of
1933 | ps => do put Ctxt ({ pendingTransforms := [] } defs)
1936 | add : (Name, Transform) -> Core ()
1938 | = do n' <- toResolvedNames n
1939 | t' <- toResolvedNames t
1940 | update Ctxt { transforms $= insertTransform n' t' }
1943 | addTransform : {auto c : Ref Ctxt Defs} ->
1944 | FC -> Transform -> Core ()
1947 | let Just fn_in = getFnName t_in
1949 | throw (GenericMsg fc "LHS of a transformation must be a function application")
1950 | fn <- toResolvedNames fn_in
1951 | t <- toResolvedNames t_in
1952 | fn_full <- toFullNames fn_in
1953 | t_full <- toFullNames t_in
1954 | update Ctxt { transforms $= insertTransform fn t,
1955 | saveTransforms $= ((fn_full, t_full) ::) }
1958 | clearSavedHints : {auto c : Ref Ctxt Defs} -> Core ()
1959 | clearSavedHints = update Ctxt { saveTypeHints := [], saveAutoHints := [] }
1963 | setNS : {auto c : Ref Ctxt Defs} -> Namespace -> Core ()
1964 | setNS ns = update Ctxt { currentNS := ns }
1968 | setNestedNS : {auto c : Ref Ctxt Defs} ->
1969 | List Namespace -> Core ()
1970 | setNestedNS ns = update Ctxt { nestedNS := ns }
1974 | getNS : {auto c : Ref Ctxt Defs} ->
1982 | getNestedNS : {auto c : Ref Ctxt Defs} ->
1993 | addImported : {auto c : Ref Ctxt Defs} ->
1994 | (ModuleIdent, Bool, Namespace) -> Core ()
1995 | addImported mod = update Ctxt { imported $= (mod ::) }
1998 | getImported : {auto c : Ref Ctxt Defs} ->
1999 | Core (List (ModuleIdent, Bool, Namespace))
2005 | addDirective : {auto c : Ref Ctxt Defs} ->
2006 | String -> String -> Core ()
2009 | case getCG (options defs) c of
2010 | Nothing => put Ctxt ({ cgdirectives $= insert (Other (toLower c), str) } defs)
2011 | Just cg => put Ctxt ({ cgdirectives $= insert (cg, str) } defs)
2014 | getDirectives : {auto c : Ref Ctxt Defs} ->
2015 | CG -> Core (List String)
2018 | pure $
defs.options.session.directives ++
2019 | mapMaybe getDir (Prelude.toList $
cgdirectives defs)
2021 | getDir : (CG, String) -> Maybe String
2022 | getDir (x', str) = if cg == x' then Just str else Nothing
2029 | extendNS : {auto c : Ref Ctxt Defs} -> Namespace -> Core ()
2030 | extendNS ns = update Ctxt { currentNS $= (<.> ns) }
2033 | withExtendedNS : {auto c : Ref Ctxt Defs} ->
2034 | Namespace -> Core a -> Core a
2037 | let cns = currentNS defs
2038 | let nns = nestedNS defs
2039 | put Ctxt ({ currentNS := cns <.> ns } defs)
2040 | ma <- catch (Right <$> act) (pure . Left)
2042 | put Ctxt ({ currentNS := cns, nestedNS := nns } defs)
2051 | inCurrentNS : {auto c : Ref Ctxt Defs} ->
2055 | pure (NS (currentNS defs) (UN n))
2056 | inCurrentNS n@(CaseBlock {})
2058 | pure (NS (currentNS defs) n)
2059 | inCurrentNS n@(WithBlock {})
2061 | pure (NS (currentNS defs) n)
2062 | inCurrentNS n@(Nested {})
2064 | pure (NS (currentNS defs) n)
2067 | pure (NS (currentNS defs) n)
2070 | pure (NS (currentNS defs) n)
2074 | setVisible : {auto c : Ref Ctxt Defs} ->
2076 | setVisible nspace = update Ctxt { gamma->visibleNS $= (nspace ::) }
2079 | getVisible : {auto c : Ref Ctxt Defs} ->
2083 | pure (visibleNS (gamma defs))
2089 | setAllPublic : {auto c : Ref Ctxt Defs} ->
2090 | (pub : Bool) -> Core ()
2091 | setAllPublic pub = update Ctxt { gamma->allPublic := pub }
2094 | isAllPublic : {auto c : Ref Ctxt Defs} ->
2098 | pure (allPublic (gamma defs))
2103 | isVisible : {auto c : Ref Ctxt Defs} ->
2107 | pure (any visible (allParents (currentNS defs) ++
2109 | visibleNS (gamma defs)))
2114 | visible : Namespace -> Bool
2115 | visible visns = isParentOf visns nspace
2120 | getNextEntry : {auto c : Ref Ctxt Defs} ->
2124 | pure (nextEntry (gamma defs))
2127 | setNextEntry : {auto c : Ref Ctxt Defs} ->
2129 | setNextEntry i = update Ctxt { gamma->nextEntry := i }
2134 | resetFirstEntry : {auto c : Ref Ctxt Defs} ->
2138 | put Ctxt ({ gamma->firstEntry := nextEntry (gamma defs) } defs)
2141 | getFullName : {auto c : Ref Ctxt Defs} ->
2143 | getFullName (Resolved i)
2145 | Just gdef <- lookupCtxtExact (Resolved i) (gamma defs)
2146 | | Nothing => pure (Resolved i)
2153 | getPPrint : {auto c : Ref Ctxt Defs} ->
2157 | pure (printing (options defs))
2160 | setPPrint : {auto c : Ref Ctxt Defs} -> PPrinter -> Core ()
2161 | setPPrint ppopts = update Ctxt { options->printing := ppopts }
2164 | updatePPrint : {auto c : Ref Ctxt Defs} -> (PPrinter -> PPrinter) -> Core ()
2165 | updatePPrint f = update Ctxt { options->printing $= f }
2168 | setCG : {auto c : Ref Ctxt Defs} -> CG -> Core ()
2169 | setCG cg = update Ctxt { options->session->codegen := cg }
2172 | getDirs : {auto c : Ref Ctxt Defs} -> Core Dirs
2175 | pure (dirs (options defs))
2178 | addExtraDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2179 | addExtraDir dir = update Ctxt { options->dirs->extra_dirs $= ((::) dir) . filter (/= dir) }
2182 | addPackageDir: {auto c : Ref Ctxt Defs} -> String -> Core ()
2183 | addPackageDir dir = update Ctxt { options->dirs->package_dirs $= ((::) dir) . filter (/= dir) }
2186 | addPackageSearchPath: {auto c : Ref Ctxt Defs} -> String -> Core ()
2187 | addPackageSearchPath dir =
2188 | let newPath = parse dir
2189 | in update Ctxt { options->dirs->package_search_paths $= ((::) newPath) . filter (/= newPath) }
2192 | addDataDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2193 | addDataDir dir = update Ctxt { options->dirs->data_dirs $= (++ [dir]) }
2196 | addLibDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2197 | addLibDir dir = update Ctxt { options->dirs->lib_dirs $= (++ [dir]) }
2200 | setBuildDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2201 | setBuildDir dir = update Ctxt { options->dirs->build_dir := dir }
2204 | setDependsDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2205 | setDependsDir dir = update Ctxt { options->dirs->depends_dir := dir }
2208 | setOutputDir : {auto c : Ref Ctxt Defs} -> Maybe String -> Core ()
2209 | setOutputDir dir = update Ctxt { options->dirs->output_dir := dir }
2212 | setSourceDir : {auto c : Ref Ctxt Defs} -> Maybe String -> Core ()
2213 | setSourceDir mdir = update Ctxt { options->dirs->source_dir := mdir }
2216 | setWorkingDir : {auto c : Ref Ctxt Defs} -> String -> Core ()
2218 | = do coreLift_ $
changeDir dir
2219 | Just cdir <- coreLift $
currentDir
2220 | | Nothing => throw (InternalError "Can't get current directory")
2221 | update Ctxt { options->dirs->working_dir := cdir }
2224 | getWorkingDir : Core String
2226 | = do Just d <- coreLift $
currentDir
2227 | | Nothing => throw (InternalError "Can't get current directory")
2231 | setExtraDirs : {auto c : Ref Ctxt Defs} -> List String -> Core ()
2232 | setExtraDirs dirs = update Ctxt { options->dirs->extra_dirs := dirs }
2235 | setPackageDirs : {auto c : Ref Ctxt Defs} -> List String -> Core ()
2236 | setPackageDirs dirs = update Ctxt { options->dirs->package_dirs := dirs }
2239 | withCtxt : {auto c : Ref Ctxt Defs} -> Core a -> Core a
2240 | withCtxt = wrapRef Ctxt resetCtxt
2242 | resetCtxt : Defs -> Core ()
2243 | resetCtxt defs = do let dir = defs.options.dirs.working_dir
2244 | coreLift_ $
changeDir dir
2247 | setPrefix : {auto c : Ref Ctxt Defs} -> String -> Core ()
2248 | setPrefix dir = update Ctxt { options->dirs->prefix_dir := dir }
2251 | setExtension : {auto c : Ref Ctxt Defs} -> LangExt -> Core ()
2252 | setExtension e = update Ctxt { options $= setExtension e }
2255 | isExtension : LangExt -> Defs -> Bool
2256 | isExtension e defs = isExtension e (options defs)
2259 | checkUnambig : {auto c : Ref Ctxt Defs} ->
2260 | FC -> Name -> Core Name
2263 | case !(lookupDefName n (gamma defs)) of
2264 | [(fulln, i, _)] => pure (Resolved i)
2265 | ns => ambiguousName fc n (map fst ns)
2268 | lazyActive : {auto c : Ref Ctxt Defs} -> Bool -> Core ()
2269 | lazyActive a = update Ctxt { options->elabDirectives->lazyActive := a }
2272 | setUnboundImplicits : {auto c : Ref Ctxt Defs} -> Bool -> Core ()
2273 | setUnboundImplicits a = update Ctxt { options->elabDirectives->unboundImplicits := a }
2276 | setPrefixRecordProjections : {auto c : Ref Ctxt Defs} -> Bool -> Core ()
2277 | setPrefixRecordProjections b = update Ctxt { options->elabDirectives->prefixRecordProjections := b }
2280 | setDefaultTotalityOption : {auto c : Ref Ctxt Defs} ->
2282 | setDefaultTotalityOption tot = update Ctxt { options->elabDirectives->totality := tot }
2285 | setAmbigLimit : {auto c : Ref Ctxt Defs} ->
2287 | setAmbigLimit max = update Ctxt { options->elabDirectives->ambigLimit := max }
2290 | setTotalLimit : {auto c : Ref Ctxt Defs} ->
2292 | setTotalLimit max = update Ctxt { options->elabDirectives->totalLimit := max }
2295 | setAutoImplicitLimit : {auto c : Ref Ctxt Defs} ->
2297 | setAutoImplicitLimit max = update Ctxt { options->elabDirectives->autoImplicitLimit := max }
2300 | setNFThreshold : {auto c : Ref Ctxt Defs} ->
2302 | setNFThreshold max = update Ctxt { options->elabDirectives->nfThreshold := max }
2305 | setSearchTimeout : {auto c : Ref Ctxt Defs} ->
2307 | setSearchTimeout t = update Ctxt { options->session->searchTimeout := t }
2310 | isLazyActive : {auto c : Ref Ctxt Defs} ->
2314 | pure (lazyActive (elabDirectives (options defs)))
2317 | isUnboundImplicits : {auto c : Ref Ctxt Defs} ->
2321 | pure (unboundImplicits (elabDirectives (options defs)))
2324 | isPrefixRecordProjections : {auto c : Ref Ctxt Defs} -> Core Bool
2325 | isPrefixRecordProjections =
2326 | prefixRecordProjections . elabDirectives . options <$> get Ctxt
2329 | getDefaultTotalityOption : {auto c : Ref Ctxt Defs} ->
2331 | getDefaultTotalityOption
2333 | pure (totality (elabDirectives (options defs)))
2336 | getAmbigLimit : {auto c : Ref Ctxt Defs} ->
2340 | pure (ambigLimit (elabDirectives (options defs)))
2343 | getAutoImplicitLimit : {auto c : Ref Ctxt Defs} ->
2347 | pure (autoImplicitLimit (elabDirectives (options defs)))
2350 | addForeignImpl : {auto c : Ref Ctxt Defs} ->
2351 | FC -> (fullName : Name) -> (def : String) -> Core ()
2352 | addForeignImpl fc name def
2353 | = do name <- toFullNames name
2354 | update Ctxt { options $= addForeignImpl name def }
2357 | setPair : {auto c : Ref Ctxt Defs} ->
2358 | FC -> (pairType : Name) -> (fstn : Name) -> (sndn : Name) ->
2361 | = do ty' <- checkUnambig fc ty
2362 | f' <- checkUnambig fc f
2363 | s' <- checkUnambig fc s
2364 | update Ctxt { options $= setPair ty' f' s' }
2367 | setRewrite : {auto c : Ref Ctxt Defs} ->
2368 | FC -> (eq : Name) -> (rwlemma : Name) -> Core ()
2370 | = do rw' <- checkUnambig fc rw
2371 | eq' <- checkUnambig fc eq
2372 | update Ctxt { options $= setRewrite eq' rw' }
2376 | setFromInteger : {auto c : Ref Ctxt Defs} ->
2378 | setFromInteger n = update Ctxt { options $= setFromInteger n }
2381 | setFromString : {auto c : Ref Ctxt Defs} ->
2383 | setFromString n = update Ctxt { options $= setFromString n }
2386 | setFromChar : {auto c : Ref Ctxt Defs} ->
2388 | setFromChar n = update Ctxt { options $= setFromChar n }
2391 | setFromDouble : {auto c : Ref Ctxt Defs} ->
2393 | setFromDouble n = update Ctxt { options $= setFromDouble n }
2396 | setFromTTImp : {auto c : Ref Ctxt Defs} ->
2398 | setFromTTImp n = update Ctxt { options $= setFromTTImp n }
2401 | setFromName : {auto c : Ref Ctxt Defs} ->
2403 | setFromName n = update Ctxt { options $= setFromName n }
2406 | setFromDecls : {auto c : Ref Ctxt Defs} ->
2408 | setFromDecls n = update Ctxt { options $= setFromDecls n }
2411 | addNameDirective : {auto c : Ref Ctxt Defs} ->
2412 | FC -> Name -> List String -> Core ()
2413 | addNameDirective fc n ns
2414 | = do n' <- checkUnambig fc n
2415 | update Ctxt { namedirectives $= insert n' ns }
2420 | isPairType : {auto c : Ref Ctxt Defs} ->
2424 | case pairnames (options defs) of
2426 | Just l => pure $
!(getFullName n) == !(getFullName (pairType l))
2429 | fstName : {auto c : Ref Ctxt Defs} ->
2433 | pure $
maybe Nothing (Just . fstName) (pairnames (options defs))
2436 | sndName : {auto c : Ref Ctxt Defs} ->
2440 | pure $
maybe Nothing (Just . sndName) (pairnames (options defs))
2443 | getRewrite :{auto c : Ref Ctxt Defs} ->
2447 | pure $
maybe Nothing (Just . rewriteName) (rewritenames (options defs))
2450 | isEqualTy : {auto c : Ref Ctxt Defs} ->
2454 | case rewritenames (options defs) of
2456 | Just r => pure $
!(getFullName n) == !(getFullName (equalType r))
2459 | fromIntegerName : {auto c : Ref Ctxt Defs} ->
2463 | pure $
fromIntegerName (primnames (options defs))
2466 | fromStringName : {auto c : Ref Ctxt Defs} ->
2470 | pure $
fromStringName (primnames (options defs))
2473 | fromCharName : {auto c : Ref Ctxt Defs} ->
2477 | pure $
fromCharName (primnames (options defs))
2480 | fromDoubleName : {auto c : Ref Ctxt Defs} ->
2484 | pure $
fromDoubleName (primnames (options defs))
2487 | fromTTImpName : {auto c : Ref Ctxt Defs} ->
2491 | pure $
fromTTImpName (primnames (options defs))
2494 | fromNameName : {auto c : Ref Ctxt Defs} ->
2498 | pure $
fromNameName (primnames (options defs))
2501 | fromDeclsName : {auto c : Ref Ctxt Defs} ->
2505 | pure $
fromDeclsName (primnames (options defs))
2508 | getPrimNames : {auto c : Ref Ctxt Defs} -> Core PrimNames
2509 | getPrimNames = [| MkPrimNs fromIntegerName
2518 | getPrimitiveNames : {auto c : Ref Ctxt Defs} -> Core (List Name)
2519 | getPrimitiveNames = primNamesToList <$> getPrimNames
2522 | isPrimName : List Name -> Name -> Bool
2523 | isPrimName prims given = let (ns, nm) = splitNS given in go ns nm prims where
2525 | go : Namespace -> Name -> List Name -> Bool
2528 | = let (ns', nm') = splitNS p in
2529 | (nm' == nm && (ns' `isApproximationOf` ns))
2533 | addLogLevel : {auto c : Ref Ctxt Defs} ->
2534 | Maybe LogLevel -> Core ()
2535 | addLogLevel Nothing = update Ctxt { options->session->logEnabled := False, options->session->logLevel := defaultLogLevel }
2536 | addLogLevel (Just l) = update Ctxt { options->session->logEnabled := True, options->session->logLevel $= insertLogLevel l }
2539 | setLogLevel : {auto c : Ref Ctxt Defs} ->
2541 | setLogLevel = addLogLevel . Just
2544 | stopLogging : {auto c : Ref Ctxt Defs} -> Core ()
2545 | stopLogging = addLogLevel Nothing
2548 | withLogLevel : {auto c : Ref Ctxt Defs} ->
2549 | LogLevel -> Core a -> Core a
2550 | withLogLevel l comp = do
2552 | let logs = logLevel (session (options defs))
2553 | put Ctxt ({ options->session->logLevel := insertLogLevel l logs } defs)
2556 | put Ctxt ({ options->session->logLevel := logs } defs)
2560 | setLogTimings : {auto c : Ref Ctxt Defs} -> Nat -> Core ()
2561 | setLogTimings n = update Ctxt { options->session->logTimings := Just n }
2564 | setDebugElabCheck : {auto c : Ref Ctxt Defs} -> Bool -> Core ()
2565 | setDebugElabCheck b = update Ctxt { options->session->debugElabCheck := b }
2568 | getSession : {auto c : Ref Ctxt Defs} ->
2572 | pure (session (options defs))
2575 | setSession : {auto c : Ref Ctxt Defs} -> Session -> Core ()
2576 | setSession sopts = update Ctxt { options->session := sopts }
2580 | updateSession : {auto c : Ref Ctxt Defs} ->
2581 | (Session -> Session) -> Core ()
2582 | updateSession f = setSession (f !getSession)
2585 | recordWarning : {auto c : Ref Ctxt Defs} -> Warning -> Core ()
2586 | recordWarning w = update Ctxt { warnings $= (w ::) }
2591 | = do clock <- coreLift (clockTime Monotonic)
2592 | pure (seconds clock * nano + nanoseconds clock)
2606 | startTimer : {auto c : Ref Ctxt Defs} ->
2607 | Integer -> String -> Core ()
2610 | update Ctxt { timer := Just (t + tmax * 1000000, action) }
2614 | clearTimer : {auto c : Ref Ctxt Defs} -> Core ()
2615 | clearTimer = update Ctxt { timer := Nothing }
2619 | checkTimer : {auto c : Ref Ctxt Defs} ->
2623 | let Just (max, action) = timer defs
2627 | then throw (Timeout action)
2633 | addImportedInc : {auto c : Ref Ctxt Defs} ->
2634 | ModuleIdent -> List (CG, String, List String) -> Core ()
2635 | addImportedInc modNS inc
2639 | when (cg `elem` s.incrementalCGs) $
2644 | do recordWarning (GenericWarn emptyFC ("No incremental compile data for " ++ show modNS))
2646 | put Ctxt ({ allIncData $= drop cg } defs)
2648 | when (show modNS /= "") $
2649 | updateSession { incrementalCGs $= (delete cg) }
2651 | put Ctxt ({ allIncData $= addMod cg (mods, extra) }
2654 | addMod : CG -> (String, List String) ->
2655 | List (CG, (List String, List String)) ->
2656 | List (CG, (List String, List String))
2657 | addMod cg (mod, all) [] = [(cg, ([mod], all))]
2658 | addMod cg (mod, all) ((cg', (mods, libs)) :: xs)
2660 | then ((cg, (mod :: mods, libs ++ all)) :: xs)
2661 | else ((cg', (mods, libs)) :: addMod cg (mod, all) xs)
2663 | drop : CG -> List (CG, a) -> List (CG, a)
2668 | else ((x, v) :: drop cg xs)
2671 | setIncData : {auto c : Ref Ctxt Defs} ->
2672 | CG -> (String, List String) -> Core ()
2673 | setIncData cg res = update Ctxt { incData $= ((cg, res) :: )}
2678 | hide : {auto c : Ref Ctxt Defs} ->
2682 | [(nsn, _)] <- lookupCtxtName n (gamma defs)
2683 | | res => ambiguousName fc n (map fst res)
2684 | put Ctxt ({ gamma $= hideName nsn } defs)
2689 | unhide : {auto c : Ref Ctxt Defs} ->
2693 | [(nsn, _)] <- lookupHiddenCtxtName n (gamma defs)
2694 | | res => ambiguousName fc n (map fst res)
2695 | put Ctxt ({ gamma $= unhideName nsn } defs)
2696 | unless (isHidden nsn (gamma defs)) $
do
2697 | recordWarning $
GenericWarn fc $
2698 | "Trying to %unhide `" ++ show nsn ++ "`, which was not hidden in the first place"