Skip to content

Commit 9865765

Browse files
authored
Normalise errors on display, not when they arise (#1906)
* Move Context into its own file Just the core definition - this is so that we have access to it in Core.Core, for inclusion in error messages, to save normalisation of terms in errors until we actually show them. * Normalise errors on display, not when they arise This can save a lot of time in ambiguity resolution if the errors are complicated, because the errors might never be displayed if it's in an abandoned branch. This involves lifting 'Context' out of Core.Context, because we need to store it in Error, which is needed by Core, which in turn is needed in Core.Context. Also moved a couple of test caes from ttimp to idris2, so that the errors get rendered properly and won't need updating unnecessarily. In fact all of the ttimp tests - which were just part of the initial scaffolding - are probably now subsumed by the idris2 tests. * Add new coverage001 test files
1 parent 2a5739c commit 9865765

38 files changed

+989
-1027
lines changed

idris2api.ipkg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ modules =
4242

4343
Core.AutoSearch,
4444
Core.Binary,
45+
Core.Binary.Prims,
4546
Core.CaseBuilder,
4647
Core.CaseTree,
4748
Core.CompileExpr,
4849
Core.Context,
50+
Core.Context.Context,
4951
Core.Context.Data,
5052
Core.Context.Log,
5153
Core.Core,

src/Compiler/Common.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Compiler.LambdaLift
88
import Compiler.Opts.CSE
99
import Compiler.VMCode
1010

11+
import Core.Binary.Prims
1112
import Core.Context
1213
import Core.Context.Log
1314
import Core.Directory
@@ -17,7 +18,6 @@ import Core.TT
1718
import Core.TTC
1819
import Libraries.Data.IOArray
1920
import Libraries.Data.SortedMap
20-
import Libraries.Utils.Binary
2121
import Libraries.Utils.Path
2222

2323
import Data.List

src/Core/AutoSearch.idr

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ searchIfHole : {vars : _} ->
7878
(arg : ArgInfo vars) ->
7979
Core ()
8080
searchIfHole fc defaults trying ispair Z def top env arg
81-
= throw (CantSolveGoal fc [] top) -- possibly should say depth limit hit?
81+
= throw (CantSolveGoal fc (gamma !(get Ctxt)) [] top) -- possibly should say depth limit hit?
8282
searchIfHole fc defaults trying ispair (S depth) def top env arg
8383
= do let hole = holeID arg
8484
let rig = argRig arg
8585

8686
defs <- get Ctxt
8787
Just gdef <- lookupCtxtExact (Resolved hole) (gamma defs)
88-
| Nothing => throw (CantSolveGoal fc [] top)
88+
| Nothing => throw (CantSolveGoal fc (gamma !(get Ctxt)) [] top)
8989
let Hole _ _ = definition gdef
9090
| _ => pure () -- already solved
9191
top' <- if ispair
@@ -101,7 +101,7 @@ searchIfHole fc defaults trying ispair (S depth) def top env arg
101101
then pure ()
102102
else do vs <- unify inTerm fc env (metaApp arg) argdef
103103
let [] = constraints vs
104-
| _ => throw (CantSolveGoal fc [] top)
104+
| _ => throw (CantSolveGoal fc (gamma defs) [] top)
105105
pure ()
106106

107107
successful : {vars : _} ->
@@ -135,12 +135,12 @@ anyOne : {vars : _} ->
135135
FC -> Env Term vars -> (topTy : ClosedTerm) ->
136136
List (Core (Term vars)) ->
137137
Core (Term vars)
138-
anyOne fc env top [] = throw (CantSolveGoal fc [] top)
138+
anyOne fc env top [] = throw (CantSolveGoal fc (gamma !(get Ctxt)) [] top)
139139
anyOne fc env top [elab]
140140
= catch elab $
141141
\case
142-
err@(CantSolveGoal _ _ _) => throw err
143-
_ => throw $ CantSolveGoal fc [] top
142+
err@(CantSolveGoal _ _ _ _) => throw err
143+
_ => throw $ CantSolveGoal fc (gamma !(get Ctxt)) [] top
144144
anyOne fc env top (elab :: elabs)
145145
= tryUnify elab (anyOne fc env top elabs)
146146

@@ -153,8 +153,8 @@ exactlyOne : {vars : _} ->
153153
exactlyOne fc env top target [elab]
154154
= catch elab $
155155
\case
156-
err@(CantSolveGoal _ _ _) => throw err
157-
_ => throw $ CantSolveGoal fc [] top
156+
err@(CantSolveGoal _ _ _ _) => throw err
157+
_ => throw $ CantSolveGoal fc (gamma !(get Ctxt)) [] top
158158
exactlyOne {vars} fc env top target all
159159
= do elabs <- successful all
160160
case rights elabs of
@@ -163,7 +163,7 @@ exactlyOne {vars} fc env top target all
163163
put Ctxt defs
164164
commit
165165
pure res
166-
[] => throw (CantSolveGoal fc [] top)
166+
[] => throw (CantSolveGoal fc (gamma !(get Ctxt)) [] top)
167167
rs => throw (AmbiguousSearch fc env !(quote !(get Ctxt) env target)
168168
!(traverse normRes rs))
169169
where
@@ -275,7 +275,7 @@ searchLocalWith {vars} fc rigc defaults trying depth def top env (prf, ty) targe
275275
logNF "auto" 10 "For target" env target
276276
ures <- unify inTerm fc env target appTy
277277
let [] = constraints ures
278-
| _ => throw (CantSolveGoal fc [] top)
278+
| _ => throw (CantSolveGoal fc (gamma defs) [] top)
279279
-- We can only use the local if its type is not an unsolved hole
280280
if !(usableLocal fc defaults env ty)
281281
then do
@@ -290,7 +290,7 @@ searchLocalWith {vars} fc rigc defaults trying depth def top env (prf, ty) targe
290290
(impLast args)
291291
pure candidate
292292
else do logNF "auto" 10 "Can't use " env ty
293-
throw (CantSolveGoal fc [] top)
293+
throw (CantSolveGoal fc (gamma defs) [] top)
294294

295295
findPos : Defs -> Term vars ->
296296
(Term vars -> Term vars) ->
@@ -300,10 +300,10 @@ searchLocalWith {vars} fc rigc defaults trying depth def top env (prf, ty) targe
300300
findPos defs p f nty@(NTCon pfc pn _ _ [(_, xty), (_, yty)]) target
301301
= handleUnify (findDirect defs prf f nty target) (\e =>
302302
if ambig e then throw e else
303-
do fname <- maybe (throw (CantSolveGoal fc [] top))
303+
do fname <- maybe (throw (CantSolveGoal fc (gamma defs) [] top))
304304
pure
305305
!fstName
306-
sname <- maybe (throw (CantSolveGoal fc [] top))
306+
sname <- maybe (throw (CantSolveGoal fc (gamma defs) [] top))
307307
pure
308308
!sndName
309309
if !(isPairType pn)
@@ -325,7 +325,7 @@ searchLocalWith {vars} fc rigc defaults trying depth def top env (prf, ty) targe
325325
ytytm,
326326
f arg])
327327
ytynf target)]
328-
else throw (CantSolveGoal fc [] top))
328+
else throw (CantSolveGoal fc (gamma defs) [] top))
329329
findPos defs p f nty target
330330
= findDirect defs p f nty target
331331

@@ -366,9 +366,9 @@ searchName fc rigc defaults trying depth def top env target (n, ndef)
366366
= do defs <- get Ctxt
367367
when (not (visibleInAny (!getNS :: !getNestedNS)
368368
(fullname ndef) (visibility ndef))) $
369-
throw (CantSolveGoal fc [] top)
369+
throw (CantSolveGoal fc (gamma defs) [] top)
370370
when (BlockedHint `elem` flags ndef) $
371-
throw (CantSolveGoal fc [] top)
371+
throw (CantSolveGoal fc (gamma defs) [] top)
372372

373373
let ty = type ndef
374374
let namety : NameType
@@ -381,7 +381,7 @@ searchName fc rigc defaults trying depth def top env target (n, ndef)
381381
(args, appTy) <- mkArgs fc rigc env nty
382382
ures <- unify inTerm fc env target appTy
383383
let [] = constraints ures
384-
| _ => throw (CantSolveGoal fc [] top)
384+
| _ => throw (CantSolveGoal fc (gamma defs) [] top)
385385
ispair <- isPairNF env nty defs
386386
let candidate = apply fc (Ref fc namety n) (map metaApp args)
387387
logTermNF "auto" 10 "Candidate " env candidate
@@ -401,7 +401,7 @@ searchNames : {vars : _} ->
401401
Env Term vars -> Bool -> List Name ->
402402
(target : NF vars) -> Core (Term vars)
403403
searchNames fc rigc defaults trying depth defining topty env ambig [] target
404-
= throw (CantSolveGoal fc [] topty)
404+
= throw (CantSolveGoal fc (gamma !(get Ctxt)) [] topty)
405405
searchNames fc rigc defaults trying depth defining topty env ambig (n :: ns) target
406406
= do defs <- get Ctxt
407407
visnsm <- traverse (visible (gamma defs) (currentNS defs :: nestedNS defs)) (n :: ns)
@@ -463,9 +463,9 @@ concreteDets {vars} fc defaults env top pos dets (arg :: args)
463463
throw (DeterminingArg fc n i [] top)
464464
concrete defs (NApp _ (NMeta n i _) _) False
465465
= do Just (Hole _ b) <- lookupDefExact n (gamma defs)
466-
| def => throw (CantSolveGoal fc [] top)
466+
| def => throw (CantSolveGoal fc (gamma defs) [] top)
467467
unless (implbind b) $
468-
throw (CantSolveGoal fc [] top)
468+
throw (CantSolveGoal fc (gamma defs) [] top)
469469
concrete defs tm atTop = pure ()
470470

471471
checkConcreteDets : {vars : _} ->
@@ -535,7 +535,7 @@ searchType {vars} fc rigc defaults trying depth def checkdets top env target
535535
(\e => if ambig e
536536
then throw e
537537
else tryGroups Nothing nty (hintGroups sd))
538-
else throw (CantSolveGoal fc [] top)
538+
else throw (CantSolveGoal fc (gamma defs) [] top)
539539
_ => do logNF "auto" 10 "Next target: " env nty
540540
searchLocalVars fc rigc defaults trying' depth def top env nty
541541
where
@@ -548,7 +548,7 @@ searchType {vars} fc rigc defaults trying depth def checkdets top env target
548548
tryGroups : Maybe Error ->
549549
NF vars -> List (Bool, List Name) -> Core (Term vars)
550550
tryGroups (Just err) nty [] = throw err
551-
tryGroups Nothing nty [] = throw (CantSolveGoal fc [] top)
551+
tryGroups Nothing nty [] = throw (CantSolveGoal fc (gamma !(get Ctxt)) [] top)
552552
tryGroups merr nty ((ambigok, g) :: gs)
553553
= handleUnify
554554
(do logC "auto" 5

src/Core/Binary.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
||| everything, not just the things in the current file).
44
module Core.Binary
55

6+
import public Core.Binary.Prims
67
import Core.CaseTree
78
import Core.Context
89
import Core.Context.Log

0 commit comments

Comments
 (0)