@@ -109,7 +109,7 @@ specialise ctxt env limits t
109109
110110simplify :: Context -> Env -> TT Name -> TT Name
111111simplify ctxt env t
112− = evalState (do val <- eval False ctxt threshold []
112+ = evalState (do val <- eval False ctxt threshold [(UN "lazy", 0)]
113113 (map finalEntry env) (finalise t) [Simplify]
114114 quote 0 val) initEval
115115
@@ -133,12 +133,13 @@ unbindEnv :: EnvTT n -> TT n -> TT n
133133unbindEnv [] tm = tm
134134unbindEnv (_:bs) (Bind n b sc) = unbindEnv bs sc
135135
136−usable :: Name -> [(Name, Int)] -> (Bool, [(Name, Int)])
137−usable n [] = (True, [])
138−usable n ns = case lookup n ns of
139− Just 0 -> (False, ns)
140− Just i -> (True, (n, abs (i-1)) : filter (\ (n', _) -> n/=n') ns)
141− _ -> (True, (n, 100) : filter (\ (n', _) -> n/=n') ns)
136+usable :: Bool -> Name -> [(Name, Int)] -> (Bool, [(Name, Int)])
137+usable s n [] = (True, [])
138+usable s n ns = case lookup n ns of
139+ Just 0 -> (False, ns)
140+ Just i -> (True, (n, abs (i-1)) : filter (\ (n', _) -> n/=n') ns)
141+ _ -> if s then (True, (n, 0) : filter (\ (n', _) -> n/=n') ns)
142+ else (True, (n, 100) : filter (\ (n', _) -> n/=n') ns)
142143
143144reduction :: Eval ()
144145reduction = do ES ns s <- get
@@ -158,7 +159,7 @@ eval traceon ctxt maxred ntimes genv tm opts = ev ntimes [] True [] tm where
158159 | Just (Let t v) <- lookup n genv = do when (not atRepl) $ step maxred
159160 ev ntimes stk top env v
160161 ev ntimes_in stk top env (P Ref n ty)
161− | (True, ntimes) <- usable n ntimes_in
162+ | (True, ntimes) <- usable simpl n ntimes_in
162163 = do let val = lookupDefAcc Nothing n atRepl ctxt
163164 when (not atRepl) $ step maxred
164165 case val of
@@ -178,10 +179,17 @@ eval traceon ctxt maxred ntimes genv tm opts = ev ntimes [] True [] tm where
178179 ev ntimes stk top env (V i) | i < length env = return $ env !! i
179180 | otherwise = return $ VV i
180181 ev ntimes stk top env (Bind n (Let t v) sc)
182+ | not simpl || vinstances 0 sc < 2
181183 = do v' <- ev ntimes stk top env v --(finalise v)
182184 when (not atRepl) $ step maxred
183185 sc' <- ev ntimes stk top (v' : env) sc
184186 wknV (-1) sc'
187+ | otherwise
188+ = do t' <- ev ntimes stk top env t
189+ v' <- ev ntimes stk top env v --(finalise v)
190+ when (not atRepl) $ step maxred
191+ sc' <- ev ntimes stk top (v' : env) sc
192+ return $ VBind n (Let t' v') (\x -> return sc')
185193 ev ntimes stk top env (Bind n (NLet t v) sc)
186194 = do t' <- ev ntimes stk top env (finalise t)
187195 v' <- ev ntimes stk top env (finalise v)
@@ -219,7 +227,7 @@ eval traceon ctxt maxred ntimes genv tm opts = ev ntimes [] True [] tm where
219227-- apply ntimes stk False env f args
220228-- | spec = specApply ntimes stk env f args
221229 apply ntimes_in stk top env f@(VP Ref n ty) args
222− | (True, ntimes) <- usable n ntimes_in
230+ | (True, ntimes) <- usable simpl n ntimes_in
223231 = traceWhen traceon (show stk) $
224232 do let val = lookupDefAcc Nothing n atRepl ctxt
225233 case val of
@@ -683,16 +691,13 @@ addCasedef :: Name -> Bool -> Bool -> Bool ->
683691 Type -> Context -> Context
684692addCasedef n alwaysInline tcase covering ps psrt ty uctxt
685693 = let ctxt = definitions uctxt
686− ps' = ps -- simpl ps in
687− ctxt' = case (simpleCase tcase covering (FC "" 0) ps',
694+ ctxt' = case (simpleCase tcase covering (FC "" 0) ps,
688695 simpleCase tcase covering (FC "" 0) psrt) of
689696 (OK (CaseDef args sc _), OK (CaseDef args' sc' _)) ->
690− let inl = alwaysInline in
697+ let inl = alwaysInline || small sc' in
691698 addDef n (CaseOp inl ty ps args sc args' sc',
692699 Public, Unchecked) ctxt in
693700 uctxt { definitions = ctxt' }
694− where simpl [] = []
695− simpl ((l,r) : xs) = (l, simplify uctxt [] r) : simpl xs
696701
697702addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) -> Context -> Context
698703addOperator n ty a op uctxt