@@ -74,9 +74,11 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
7474 let atys = map snd (getArgTys fty)
7575 cs_elab <- mapM (elabClause info opts)
7676 (zip [0..] cs)
77+ -- pats_raw is the version we'll work with at compile time:
78+ -- no simplification or PE
7779 let (pats_in, cs_full) = unzip cs_elab
78−
79− logLvl 3 $ "Elaborated patterns:\n" ++ show pats_in
80+ let pats_raw = map (simple_lhs (tt_ctxt ist)) pats_in
81+ logLvl 3 $ "Elaborated patterns:\n" ++ show pats_raw
8082
8183 solveDeferred n
8284
@@ -94,7 +96,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
9496 -- If the definition is specialisable, this reduces the
9597 -- RHS
9698 pe_tm <- doPartialEval ist tpats
97− let pats = map (simple_lhs (tt_ctxt ist)) pe_tm
99+ let pats_pe = map (simple_lhs (tt_ctxt ist)) pe_tm
98100
99101 let tcase = opt_typecase (idris_options ist)
100102
@@ -103,13 +105,13 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
103105 -- for partially evaluated definitions
104106 newrules <- mapM (\ e -> case e of
105107 Left _ -> return []
106− Right (l, r) -> elabPE info fc n r) pats
108+ Right (l, r) -> elabPE info fc n r) pats_pe
107109
108110 -- Redo transforms with the newly generated transformations, so
109111 -- that the specialised application we've just made gets
110112 -- used in place of the general one
111113 ist <- getIState
112− let pats_transformed = transformPats ist pats
114+ let pats_transformed = transformPats ist pats_pe
113115
114116 -- Summary of what's about to happen: Definitions go:
115117 --
@@ -118,11 +120,13 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
118120 -- addCaseDef builds case trees from <pdef> and <pdef'>
119121
120122 -- pdef is the compile-time pattern definition.
121− -- This will get further optimised for run-time, and, separately,
122− -- further inlined to help with totality checking.
123− let pdef = map debind pats_transformed
123+ -- This will get further inlined to help with totality checking.
124+ let pdef = map debind pats_raw
125+ -- pdef_pe is the one which will get further optimised
126+ -- for run-time, and, partially evaluated
127+ let pdef_pe = map debind pats_transformed
124128
125− logLvl 5 $ "Initial typechecked patterns:\n" ++ show pats
129+ logLvl 5 $ "Initial typechecked patterns:\n" ++ show pats_raw
126130 logLvl 5 $ "Initial typechecked pattern def:\n" ++ show pdef
127131
128132 -- NOTE: Need to store original definition so that proofs which
@@ -137,13 +141,13 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
137141
138142 case specNames opts of
139143 Just _ ->
140− do logLvl 2 $ "Partially evaluated:\n" ++ show pats
144+ do logLvl 2 $ "Partially evaluated:\n" ++ show pats_pe
141145 logLvl 2 $ "Transformed:\n" ++ show pats_transformed
142146 _ -> return ()
143147
144148 erInfo <- getErasureInfo <$> getIState
145149 tree@(CaseDef scargs sc _) <- tclift $
146− simpleCase tcase False reflect CompileTime fc inacc atys pdef erInfo
150+ simpleCase tcase False reflect CompileTime fc inacc atys pdef erInfo
147151 cov <- coverage
148152 pmissing <-
149153 if cov && not (hasDefault cs)
@@ -164,8 +168,9 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
164168 else return []
165169 let pcover = null pmissing
166170
167− -- pdef' is the version that gets compiled for run-time
168− pdef_in' <- applyOpts pdef
171+ -- pdef' is the version that gets compiled for run-time,
172+ -- so we start from the partially evaluated version
173+ pdef_in' <- applyOpts pdef_pe
169174 let pdef' = map (simple_rt (tt_ctxt ist)) pdef_in'
170175
171176 logLvl 5 $ "After data structure transformations:\n" ++ show pdef'
@@ -197,7 +202,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
197202 ctxt <- getContext
198203 ist <- getIState
199204 let opt = idris_optimisation ist
200− putIState (ist { idris_patdefs = addDef n (force pdef, force pmissing)
205+ putIState (ist { idris_patdefs = addDef n (force pdef_pe, force pmissing)
201206 (idris_patdefs ist) })
202207 let caseInfo = CaseInfo (inlinable opts) (dictionary opts)
203208 case lookupTy n ctxt of
@@ -207,8 +212,11 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
207212 (AssertTotal `elem` opts)
208213 atys
209214 inacc
210− pats
211− pdef pdef pdef_inl pdef' ty)
215+ pats_pe
216+ pdef
217+ pdef -- compile time
218+ pdef_inl -- inlined
219+ pdef' ty)
212220 addIBC (IBCDef n)
213221 setTotality n tot
214222 when (not reflect) $ do totcheck (fc, n)
@@ -320,7 +328,8 @@ elabPE info fc caller r =
320328 let cgns' = filter (/= n) cgns
321329 let opts = [Specialise (map (\x -> (x, Nothing)) cgns' ++
322330 (n, Just 65536) :
323− mapMaybe specName (snd specapp))]
331+ mapMaybe (specName (pe_simple specdecl))
332+ (snd specapp))]
324333 logLvl 3 $ "Specialising application: " ++ show specapp
325334 ++ " in " ++ show caller ++
326335 " with " ++ show opts
@@ -347,14 +356,14 @@ elabPE info fc caller r =
347356 -- if it doesn't work, just don't specialise. Could happen for lots
348357 -- of valid reasons (e.g. local variables in scope which can't be
349358 -- lifted out).
350− (\e -> do logLvl 4 $ "Couldn't specialise: " ++ (pshow ist e)
359+ (\e -> do logLvl 3 $ "Couldn't specialise: " ++ (pshow ist e)
351360 return [])
352361
353− specName (ImplicitS, tm)
354− | (P Ref n _, _) <- unApply tm = Just (n, Just 1)
355− specName (ExplicitS, tm)
356− | (P Ref n _, _) <- unApply tm = Just (n, Just 1)
357− specName _ = Nothing
362+ specName simpl (ImplicitS, tm)
363+ | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
364+ specName simpl (ExplicitS, tm)
365+ | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
366+ specName simpl _ = Nothing
358367
359368 concreteArg ist (ImplicitS, tm) = concreteTm ist tm
360369 concreteArg ist (ExplicitS, tm) = concreteTm ist tm