@@ -613,11 +613,9 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
613613 -- Look for 'static' names and generate new specialised
614614 -- definitions for them
615615
616− {-
617616 mapM_ (\ e -> case e of
618617 Left _ -> return ()
619618 Right (l, r) -> elabPE info fc n r) pats
620− -}
621619
622620 -- NOTE: Need to store original definition so that proofs which
623621 -- rely on its structure aren't affected by any changes to the
@@ -789,36 +787,39 @@ elabPE info fc caller r =
789787 let sa = getSpecApps ist [] r
790788 mapM_ (mkSpecialised ist) sa
791789 where
792− -- TODO: Freeze the newly defined name, make sure it never gets
793− -- reduced when specialising (not quite the same as an 'abstract' name
794− -- so may need a new class (public/abstract/private/specialised)
795−
796− -- Add a PTerm level transformation rule, which is basically the
790+ -- TODO: Add a PTerm level transformation rule, which is basically the
797791 -- new definition in reverse (before specialising it).
798792 -- RHS => LHS where implicit arguments are left blank in the
799793 -- transformation.
800794
801795 -- Apply that transformation after every PClauses elaboration
802796
803− mkSpecialised ist specapp = do
804− iputStrLn (show specapp)
805− let specTy = getSpecTy ist specapp
797+ mkSpecialised ist specapp_in = do
798+ let (specTy, specapp) = getSpecTy ist specapp_in
806799 let (n, newnm, [(lhs, rhs)]) = getSpecClause ist specapp
807800 let undef = case lookupDef newnm (tt_ctxt ist) of
808801 [] -> True
809802 _ -> False
810− iputStrLn $ show (newnm, map (concreteArg ist) (snd specapp))
811− when (undef && all (concreteArg ist) (snd specapp)) $ do
803+ logLvl 5 $ show (newnm, map (concreteArg ist) (snd specapp))
804+ idrisCatch
805+ (when (undef && all (concreteArg ist) (snd specapp)) $ do
812806 let opts = [Specialise ((n, Nothing) :
813807 (mapMaybe specName (snd specapp)))]
814− iputStrLn (show specapp)
815− iputStrLn $ "PE definition type : " ++ (show specTy)
808+ logLvl 3 $ "Specialising application: " ++ show specapp
809+ logLvl 2 $ "New name: " ++ show newnm
810+ iLOG $ "PE definition type : " ++ (show specTy)
816811 ++ "\n" ++ show opts
817− iputStrLn $ "PE definition " ++ show newnm ++ ":\n" ++
818− (show lhs ++ " = " ++ show rhs)
812+ logLvl 2 $ "PE definition " ++ show newnm ++ ":\n" ++
813+ (showImp Nothing True False lhs ++ " = " ++
814+ showImp Nothing True False rhs)
819815 elabType info defaultSyntax "" fc opts newnm specTy
820816 let def = [PClause fc newnm lhs [] rhs []]
821817 elabClauses info fc opts newnm def
818+ logLvl 1 $ "Specialised " ++ show newnm)
819+ -- if it doesn't work, just don't specialise. Could happen for lots
820+ -- of valid reasons (e.g. local variables in scope which can't be
821+ -- lifted out).
822+ (\e -> logLvl 4 $ "Couldn't specialise: " ++ (pshow ist e))
822823
823824 specName (ImplicitS, tm)
824825 | (P Ref n _, _) <- unApply tm = Just (n, Just 1)
@@ -840,17 +841,21 @@ elabPE info fc caller r =
840841 -- get the type of a specialised application
841842 getSpecTy ist (n, args)
842843 = case lookupTy n (tt_ctxt ist) of
843− [ty] -> let specty = normalise (tt_ctxt ist) [] (specType args ty) in
844− trace (show specty) $ mkPE_TyDecl ist args
845− (explicitNames specty)
844+ [ty] -> let (specty_in, args') = specType args (explicitNames ty)
845+ specty = normalise (tt_ctxt ist) [] (finalise specty_in)
846+ t = mkPE_TyDecl ist args' (explicitNames specty) in
847+ (t, (n, args'))
846848-- (normalise (tt_ctxt ist) [] (specType args ty))
847849 _ -> error "Can't happen (getSpecTy)"
848850
849851 getSpecClause ist (n, args)
850− = let newnm = UN (show (nsroot n) ++ "_" ++ show (nsroot caller) ++
851− "__spectest") in -- UN (show n ++ show (map snd args)) in
852+ = let newnm = UN ("__"++show (nsroot n) ++ "_" ++
853+ showSep "_" (map showArg args)) in
854+ -- UN (show n ++ show (map snd args)) in
852855 (n, newnm, mkPE_TermDecl ist newnm n args)
853−
856+ where showArg (ExplicitS, n) = show n
857+ showArg (ImplicitS, n) = show n
858+ showArg _ = ""
854859
855860
856861-- Elaborate a value, returning any new bindings created (this will only