Skip to content

Commit 416b07f

Browse files
committed
Inline and eliminate translateBlockWithDest.
Turns out that the Atom that the implementation of translateBlockWithDest so diligently returned was always thrown away by its callers, so the inlining even slightly simplifies them.
1 parent 207b0ea commit 416b07f

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/lib/Imp.hs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ translateBlock :: forall i o. Emits o
269269
=> SBlock i -> SubstImpM i o (SAtom o)
270270
translateBlock (Block _ decls result) = translateDeclNest decls $ substM result
271271

272-
translateBlockWithDest :: forall i o. Emits o
273-
=> Dest o -> SBlock i -> SubstImpM i o (SAtom o)
274-
translateBlockWithDest dest (Block _ decls result) =
275-
translateDeclNest decls $ translateAtom dest result
276-
277272
translateDeclNestSubst
278273
:: Emits o => Subst AtomSubstVal l o
279274
-> Nest SDecl l i' -> SubstImpM i o (Subst AtomSubstVal i' o)
@@ -291,12 +286,6 @@ translateDeclNest decls cont = do
291286
withSubst s' cont
292287
{-# INLINE translateDeclNest #-}
293288

294-
translateAtom :: forall i o. Emits o
295-
=> Dest o -> SAtom i -> SubstImpM i o (SAtom o)
296-
translateAtom dest x = do
297-
x' <- substM x
298-
storeAtom dest x' >> return x'
299-
300289
translateExpr :: forall i o. Emits o => SExpr i -> SubstImpM i o (SAtom o)
301290
translateExpr expr = confuseGHC >>= \_ -> case expr of
302291
Hof hof -> toImpHof hof
@@ -336,8 +325,8 @@ translateExpr expr = confuseGHC >>= \_ -> case expr of
336325
dest <- allocDest =<< substM ty
337326
emitSwitch tag' (zip xss alts) $
338327
\(xs, Abs b body) ->
339-
void $ extendSubst (b @> SubstVal (sink xs)) $
340-
translateBlockWithDest (sink dest) body
328+
extendSubst (b @> SubstVal (sink xs)) $
329+
translateBlock body >>= storeAtom (sink dest)
341330
loadAtom dest
342331
DAMOp damOp -> case damOp of
343332
Seq d ixDict carry f -> do
@@ -535,8 +524,8 @@ toImpFor resultTy d ixDict (UnaryLamExpr b body) = do
535524
emitLoop (getNameHint b) d n \i -> do
536525
idx <- unsafeFromOrdinalImp (sink ixTy) i
537526
ithDest <- indexDest (sink dest) idx
538-
void $ extendSubst (b @> SubstVal idx) $
539-
translateBlockWithDest ithDest body
527+
extendSubst (b @> SubstVal idx) $
528+
translateBlock body >>= storeAtom ithDest
540529
loadAtom dest
541530
toImpFor _ _ _ _ = error "expected a lambda as the atom argument"
542531

@@ -572,8 +561,8 @@ toImpHof hof = do
572561
PairE accTy' e'' <- sinkM $ PairE accTy e'
573562
liftMonoidEmpty accTy' e''
574563
storeAtom wDest emptyVal
575-
void $ extendSubst (h @> SubstVal (Con HeapVal) <.> ref @> SubstVal (destToAtom wDest)) $
576-
translateBlockWithDest aDest body
564+
extendSubst (h @> SubstVal (Con HeapVal) <.> ref @> SubstVal (destToAtom wDest)) $
565+
translateBlock body >>= storeAtom aDest
577566
PairVal <$> loadAtom aDest <*> loadAtom wDest
578567
RunState d s f -> do
579568
BinaryLamExpr h ref body <- return f
@@ -585,10 +574,10 @@ toImpHof hof = do
585574
sDest <- atomToDest =<< substM d'
586575
return (aDest, sDest)
587576
storeAtom sDest =<< substM s
588-
void $ extendSubst (h @> SubstVal (Con HeapVal) <.> ref @> SubstVal (destToAtom sDest)) $
589-
translateBlockWithDest aDest body
577+
extendSubst (h @> SubstVal (Con HeapVal) <.> ref @> SubstVal (destToAtom sDest)) $
578+
translateBlock body >>= storeAtom aDest
590579
PairVal <$> loadAtom aDest <*> loadAtom sDest
591-
RunIO body-> translateBlock body
580+
RunIO body -> translateBlock body
592581
RunInit body -> translateBlock body
593582
where
594583
liftMonoidEmpty :: Emits n => SType n -> SAtom n -> SBuilderM n (SAtom n)

0 commit comments

Comments
 (0)