@@ -526,6 +526,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
526 [ty] -> return ty
526 [ty] -> return ty
527 pats_in <- mapM (elabClause info (Dictionary `elem` opts))
527 pats_in <- mapM (elabClause info (Dictionary `elem` opts))
528 (zip [0..] cs)
528 (zip [0..] cs)
529+ logLvl 3 $ "Elaborated patterns:\n" ++ show pats_in
529 -- if the return type of 'ty' is collapsible, the optimised version should
531 -- if the return type of 'ty' is collapsible, the optimised version should
530 -- just do nothing
532 -- just do nothing
531 ist <- getIState
533 ist <- getIState
@@ -557,12 +559,25 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
557 -- show r) pats))
559 -- show r) pats))
558 let tcase = opt_typecase (idris_options ist)
560 let tcase = opt_typecase (idris_options ist)
562+ -- Summary of what's about to happen: Definitions go:
564+ -- pats_in -> pats -> optpats
565+ -- pdef comes from pats,
566+ -- optpdef comes from optpats
567+ -- Then pdef' is optpdef with forcing/collapsing applied everywhere
569+ -- addCaseDef builds case trees from <pdef> and <pdef'>
560− -- pdef is the compile-time pattern definition with basic
571+ -- pdef is the compile-time pattern definition.
561− -- simplifications applied.
562 -- This will get further optimised for run-time, and, separately,
572 -- This will get further optimised for run-time, and, separately,
563 -- further inlined to help with totality checking.
573 -- further inlined to help with totality checking.
564− let pdef = map debind $ map (simpl (tt_ctxt ist)) pats
574+ let pdef = map debind $ map (simple_lhs (tt_ctxt ist)) pats
576+ logLvl 5 $ "Initial typechecked patterns:\n" ++ show pdef
578+ -- TODO: Inlining on initial definition happens here
566 numArgs <- tclift $ sameLength pdef
581 numArgs <- tclift $ sameLength pdef
568 -- patterns after collapsing optimisation applied
583 -- patterns after collapsing optimisation applied
@@ -572,13 +587,11 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
572 (take numArgs (repeat Erased)), Erased)]
587 (take numArgs (repeat Erased)), Erased)]
573 else stripCollapsed pats
588 else stripCollapsed pats
575− logLvl 5 $ "Patterns:\n" ++ show pats_in
576 case specNames opts of
590 case specNames opts of
577 Just _ -> logLvl 5 $ "Partially evaluated:\n" ++ show pats
591 Just _ -> logLvl 5 $ "Partially evaluated:\n" ++ show pats
578 _ -> return ()
592 _ -> return ()
579− logLvl 3 $ "SIMPLIFIED: \n" ++ show pdef
581− let optpdef = map debind $ map (simpl (tt_ctxt ist)) optpats
594+ let optpdef = map debind $ map (simple_lhs (tt_ctxt ist)) optpats
582 tree@(CaseDef scargs sc _) <- tclift $
595 tree@(CaseDef scargs sc _) <- tclift $
583 simpleCase tcase False reflect CompileTime fc pdef
596 simpleCase tcase False reflect CompileTime fc pdef
584 cov <- coverage
597 cov <- coverage
@@ -600,13 +613,11 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
600 return (filter (noMatch ist clhs) missing')
613 return (filter (noMatch ist clhs) missing')
601 else return []
614 else return []
602 let pcover = null pmissing
615 let pcover = null pmissing
603− logLvl 2 $ "Optimising patterns"
604− logLvl 5 $ show optpdef
606 -- pdef' is the version that gets compiled for run-time
617 -- pdef' is the version that gets compiled for run-time
607 pdef' <- applyOpts optpdef
618 pdef' <- applyOpts optpdef
608− logLvl 2 $ "Optimised patterns"
619+ logLvl 5 $ "After data structure transofmrations:\n" ++ show pdef'
609− logLvl 5 $ show pdef'
620+
610 ist <- getIState
621 ist <- getIState
611 -- let wf = wellFounded ist n sc
622 -- let wf = wellFounded ist n sc
612 let tot = if pcover || AssertTotal `elem` opts
623 let tot = if pcover || AssertTotal `elem` opts
@@ -642,7 +653,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
643 (AssertTotal `elem` opts)
654 (AssertTotal `elem` opts)
645− pdef pdef' ty)
656+ pdef pdef_inl pdef' ty)
646 addIBC (IBCDef n)
657 addIBC (IBCDef n)
647 setTotality n tot
658 setTotality n tot
648 when (not reflect) $ totcheck (fc, n)
659 when (not reflect) $ totcheck (fc, n)
@@ -686,9 +697,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
687 getLHS (_, l, _) = l
698 getLHS (_, l, _) = l
689− simpl ctxt (Right (x, y)) = Right (normalise ctxt [] x, y)
700+ simple_lhs ctxt (Right (x, y)) = Right (normalise ctxt [] x, y)
690−-- Core.Evaluate.simplify ctxt False [] y)
691− simpl ctxt t = t
701+ simple_lhs ctxt t = t
693 specNames [] = Nothing
703 specNames [] = Nothing
694 specNames (Specialise ns : _) = Just ns
704 specNames (Specialise ns : _) = Just ns