Skip to content

Commit 4761ea3

Browse files
committed
[ refactor ] Make name in Case erased
1 parent b70c54c commit 4761ea3

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/Core/Case/CaseTree.idr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ mutual
1919
public export
2020
data CaseTree : Scoped where
2121
||| case x return scTy of { p1 => e1 ; ... }
22-
Case : {name : _} ->
23-
(idx : Nat) ->
22+
Case : (idx : Nat) ->
2423
(0 p : IsVar name idx vars) ->
2524
(scTy : Term vars) -> List (CaseAlt vars) ->
2625
CaseTree vars
@@ -132,8 +131,8 @@ IsConPat = So . isConPat
132131
showCT : {vars : _} -> (indent : String) -> CaseTree vars -> String
133132
showCA : {vars : _} -> (indent : String) -> CaseAlt vars -> String
134133

135-
showCT indent (Case {name} idx prf ty alts)
136-
= "case " ++ show name ++ "[" ++ show idx ++ "] : " ++ show ty ++ " of"
134+
showCT indent (Case idx prf ty alts)
135+
= "case " ++ show (nameAt prf) ++ "[" ++ show idx ++ "] : " ++ show ty ++ " of"
137136
++ "\n" ++ indent ++ " { "
138137
++ showSep ("\n" ++ indent ++ " | ")
139138
(assert_total (map (showCA (" " ++ indent)) alts))

src/Core/Case/CaseTree/Pretty.idr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace Raw
1515
prettyTree : {vars : _} -> CaseTree vars -> Doc IdrisSyntax
1616
prettyAlt : {vars : _} -> CaseAlt vars -> Doc IdrisSyntax
1717

18-
prettyTree (Case {name} idx prf ty alts)
18+
prettyTree (Case idx prf ty alts)
1919
= let ann = case ty of
2020
Erased {} => ""
2121
_ => space <+> keyword ":" <++> byShow ty
22-
in case_ <++> annotate Bound (pretty0 name) <+> ann <++> of_
22+
in case_ <++> annotate Bound (pretty0 $ nameAt prf) <+> ann <++> of_
2323
<+> nest 2 (hardline
2424
<+> vsep (assert_total (map prettyAlt alts)))
2525
prettyTree (STerm i tm) = byShow tm
@@ -66,13 +66,13 @@ namespace Resugared
6666
{auto s : Ref Syn SyntaxInfo} ->
6767
Env Term vars -> CaseAlt vars -> Core (Doc IdrisSyntax)
6868

69-
prettyTree env (Case {name} idx prf ty alts) = do
69+
prettyTree env (Case idx prf ty alts) = do
7070
ann <- case ty of
7171
Erased {} => pure ""
7272
_ => do ty <- resugar env ty
7373
pure (space <+> keyword ":" <++> pretty ty)
7474
alts <- assert_total (traverse (prettyAlt env) alts)
75-
pure $ case_ <++> pretty0 name <+> ann <++> of_
75+
pure $ case_ <++> pretty0 (nameAt prf) <+> ann <++> of_
7676
<+> nest 2 (hardline <+> vsep alts)
7777
prettyTree env (STerm i tm) = pretty <$> resugar env tm
7878
prettyTree env (Unmatched msg) = pure ("Error:" <++> pretty0 msg)

src/Core/Coverage.idr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ buildArgs : {auto c : Ref Ctxt Defs} ->
273273
-- (because a previous case matches)
274274
List ClosedTerm -> -- ^ arguments, with explicit names
275275
CaseTree vars -> Core (List (List ClosedTerm))
276-
buildArgs fc defs known not ps cs@(Case {name = var} idx el ty altsIn)
276+
buildArgs fc defs known not ps cs@(Case idx el ty altsIn)
277277
-- If we've already matched on 'el' in this branch, restrict the alternatives
278278
-- to the tag we already know. Otherwise, add missing cases and filter out
279279
-- the ones it can't possibly be (the 'not') because a previous case
@@ -293,20 +293,21 @@ buildArgs fc defs known not ps cs@(Case {name = var} idx el ty altsIn)
293293
buildArgAlt not' (ConCase n t args sc)
294294
= do let l = mkSizeOf args
295295
let con = Ref fc (DataCon t (size l)) n
296-
let ps' = map (substName var
296+
let ps' = map (substName (nameAt el)
297297
(apply fc
298298
con (map (Ref fc Bound) args))) ps
299299
buildArgs fc defs (weakenNs l ((MkVar el, t) :: known))
300300
(weakenNs l not') ps' sc
301301
buildArgAlt not' (DelayCase t a sc)
302302
= let l = mkSizeOf [t, a]
303-
ps' = map (substName var (TDelay fc LUnknown
303+
ps' = map (substName (nameAt el)
304+
(TDelay fc LUnknown
304305
(Ref fc Bound t)
305306
(Ref fc Bound a))) ps in
306307
buildArgs fc defs (weakenNs l known) (weakenNs l not')
307308
ps' sc
308309
buildArgAlt not' (ConstCase c sc)
309-
= do let ps' = map (substName var (PrimVal fc c)) ps
310+
= do let ps' = map (substName (nameAt el) (PrimVal fc c)) ps
310311
buildArgs fc defs known not' ps' sc
311312
buildArgAlt not' (DefaultCase sc)
312313
= buildArgs fc defs known not' ps sc

src/Core/Normalise/Eval.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ parameters (defs : Defs) (topopts : EvalOpts)
422422
EvalOpts -> FC ->
423423
Stack free -> CaseTree args ->
424424
Core (CaseResult (TermWithEnv free))
425-
evalTree env loc opts fc stk (Case {name} idx x _ alts)
425+
evalTree env loc opts fc stk (Case idx x _ alts)
426426
= do xval <- evalLocal env fc Nothing idx (embedIsVar x) [] loc
427427
-- we have not defined quote yet (it depends on eval itself) so we show the NF
428428
-- i.e. only the top-level constructor.
429429
logC "eval.casetree" 5 $ do
430430
xval <- toFullNames xval
431-
pure "Evaluated \{show name} to \{show xval}"
431+
pure "Evaluated \{show (nameAt x)} to \{show xval}"
432432
let loc' = updateLocal opts env idx (embedIsVar x) loc xval
433433
findAlt env loc' opts fc stk xval alts
434434
evalTree env loc opts fc stk (STerm _ tm)

src/Core/TTC.idr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ TTC Pat where
468468
mutual
469469
export
470470
{vars : _} -> TTC (CaseTree vars) where
471-
toBuf (Case {name} idx x scTy xs)
472-
= do tag 0; toBuf name; toBuf idx; toBuf xs
471+
toBuf (Case idx x scTy xs)
472+
= do tag 0; toBuf idx; toBuf xs
473473
toBuf (STerm _ x)
474474
= do tag 1; toBuf x
475475
toBuf (Unmatched msg)
@@ -478,8 +478,10 @@ mutual
478478

479479
fromBuf
480480
= case !getTag of
481-
0 => do name <- fromBuf; idx <- fromBuf
481+
0 => do idx <- fromBuf
482482
xs <- fromBuf
483+
name <- maybe (corrupt "Term") pure
484+
(getAt idx vars)
483485
pure (Case {name} idx (mkPrf idx) (Erased emptyFC Placeholder) xs)
484486
1 => do x <- fromBuf
485487
pure (STerm 0 x)

0 commit comments

Comments
 (0)