Skip to content

Commit

Permalink
Remove "dex abstract machine" (to be replaced by refs)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougalm committed Apr 22, 2024
1 parent 6c76a7a commit d5997a8
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 578 deletions.
1 change: 0 additions & 1 deletion dex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ library
, LLVM.Shims
, Lexing
, Linearize
, Lower
, MonadUtil
, MTL1
, Name
Expand Down
22 changes: 0 additions & 22 deletions src/lib/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -752,28 +752,6 @@ buildMap xs f = do
buildFor noHint Fwd (tabIxType t) \i ->
tabApp (sink xs) (toAtom i) >>= f

emitSeq :: (Emits n, ScopableBuilder SimpIR m)
=> Direction -> IxType SimpIR n -> Atom SimpIR n -> LamExpr SimpIR n
-> m n (Atom SimpIR n)
emitSeq d t x f = do
op <- mkSeq d t x f
emit $ PrimOp $ DAMOp op

mkSeq :: EnvReader m
=> Direction -> IxType SimpIR n -> Atom SimpIR n -> LamExpr SimpIR n
-> m n (DAMOp SimpIR n)
mkSeq d t x f = do
return $ Seq undefined d t x f

buildRememberDest :: (Emits n, ScopableBuilder SimpIR m)
=> NameHint -> SAtom n
-> (forall l. (Emits l, Distinct l, DExt n l) => SAtomVar l -> m l (SAtom l))
-> m n (SAtom n)
buildRememberDest hint dest cont = do
ty <- return $ getType dest
doit <- buildUnaryLamExpr hint ty cont
emit $ PrimOp $ DAMOp $ RememberDest undefined dest doit

-- === vector space (ish) type class ===

emitLin :: (Builder r m, ToExpr e r, Emits n) => e n -> m n (Atom r n)
Expand Down
10 changes: 0 additions & 10 deletions src/lib/CheapReduction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ instance IRRep r => VisitGeneric (PrimOp r) r where
VectorOp op -> VectorOp <$> visitGeneric op
MiscOp op -> MiscOp <$> visitGeneric op
Hof op -> Hof <$> visitGeneric op
DAMOp op -> DAMOp <$> visitGeneric op
RefOp r op -> RefOp <$> visitGeneric r <*> traverseOp op visitGeneric visitGeneric visitGeneric

instance IRRep r => VisitGeneric (TypedHof r) r where
Expand All @@ -446,14 +445,6 @@ instance IRRep r => VisitGeneric (Hof r) r where
instance IRRep r => VisitGeneric (BaseMonoid r) r where
visitGeneric (BaseMonoid x lam) = BaseMonoid <$> visitGeneric x <*> visitGeneric lam

instance IRRep r => VisitGeneric (DAMOp r) r where
visitGeneric = \case
Seq eff dir d x lam -> Seq <$> visitGeneric eff <*> pure dir <*> visitGeneric d <*> visitGeneric x <*> visitGeneric lam
RememberDest eff x lam -> RememberDest <$> visitGeneric eff <*> visitGeneric x <*> visitGeneric lam
AllocDest t -> AllocDest <$> visitGeneric t
Place x y -> Place <$> visitGeneric x <*> visitGeneric y
Freeze x -> Freeze <$> visitGeneric x

instance IRRep r => VisitGeneric (Effects r) r where
visitGeneric = \case
Pure -> return Pure
Expand Down Expand Up @@ -696,7 +687,6 @@ instance SubstE AtomSubstVal RepVal
instance SubstE AtomSubstVal TyConParams
instance SubstE AtomSubstVal DataConDef
instance IRRep r => SubstE AtomSubstVal (BaseMonoid r)
instance IRRep r => SubstE AtomSubstVal (DAMOp r)
instance IRRep r => SubstE AtomSubstVal (TypedHof r)
instance IRRep r => SubstE AtomSubstVal (Hof r)
instance IRRep r => SubstE AtomSubstVal (TyCon r)
Expand Down
33 changes: 0 additions & 33 deletions src/lib/CheckType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ instance IRRep r => CheckableE r (PrimOp r) where
return $ UnOp unop x'
MiscOp op -> MiscOp <$> checkE op
MemOp op -> MemOp <$> checkE op
DAMOp op -> DAMOp <$> checkE op
RefOp ref m -> do
(ref', TyCon (RefType h s)) <- checkAndGetType ref
m' <- case m of
Expand Down Expand Up @@ -629,38 +628,6 @@ checkHof (EffTy _ reqTy) = \case
checkTypesEq (sink $ binderType b') (sink reqTy)
return $ Transpose (LamExpr (UnaryNest b') body') x'

instance IRRep r => CheckableE r (DAMOp r) where
checkE = \case
Seq effAnn dir ixTy carry lam -> do
LamExpr (UnaryNest b) body <- return lam
effAnn' <- checkE effAnn
ixTy' <- checkE ixTy
(carry', carryTy') <- checkAndGetType carry
let badCarry = throwInternal $ "Seq carry should be a product of raw references, got: " ++ pprint carryTy'
case carryTy' of
TyCon (ProdType refTys) -> forM_ refTys \case RawRefTy _ -> return (); _ -> badCarry
_ -> badCarry
let binderReqTy = PairTy (ixTypeType ixTy') carryTy'
checkBinderType binderReqTy b \b' -> do
body' <- checkE body
return $ Seq effAnn' dir ixTy' carry' $ LamExpr (UnaryNest b') body'
RememberDest effAnn d lam -> do
LamExpr (UnaryNest b) body <- return lam
effAnn' <- checkE effAnn
(d', dTy@(RawRefTy _)) <- checkAndGetType d
checkBinderType dTy b \b' -> do
body' <- checkE body
return $ RememberDest effAnn' d' $ LamExpr (UnaryNest b') body'
AllocDest ty -> AllocDest <$> checkE ty
Place ref val -> do
val' <- checkE val
ref' <- ref |: RawRefTy (getType val')
return $ Place ref' val'
Freeze ref -> do
ref' <- checkE ref
RawRefTy _ <- return $ getType ref'
return $ Freeze ref'

checkLamExpr :: IRRep r => PiType r o -> LamExpr r i -> TyperM r i o (LamExpr r o)
checkLamExpr piTy (LamExpr bs body) =
checkB bs \bs' -> do
Expand Down
24 changes: 0 additions & 24 deletions src/lib/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,30 +374,6 @@ toImpOp :: forall i o . Emits o => PrimOp SimpIR i -> SubstImpM i o (SAtom o)
toImpOp op = case op of
Hof hof -> toImpTypedHof hof
RefOp refDest eff -> toImpRefOp refDest eff
DAMOp damOp -> case damOp of
Seq _ d ixTy' carry f -> do
UnaryLamExpr b body <- return f
ixTy <- substM ixTy'
carry' <- substM carry
n <- indexSetSizeImp ixTy
emitLoop (getNameHint b) d n \i -> do
idx <- unsafeFromOrdinalImp (sink ixTy) i
void $ extendSubst (b @> SubstVal (PairVal idx (sink carry'))) $
translateExpr body
return carry'
RememberDest _ d f -> do
UnaryLamExpr b body <- return f
d' <- substM d
void $ extendSubst (b @> SubstVal d') $ translateExpr body
return d'
Place ref val -> do
val' <- substM val
refDest <- atomToDest =<< substM ref
storeAtom refDest val' >> return UnitVal
Freeze ref -> loadAtom =<< atomToDest =<< substM ref
AllocDest ty -> do
d <- liftM destToAtom $ allocDest =<< substM ty
return d
BinOp binOp x y -> returnIExprVal =<< emitInstr =<< (IBinOp binOp <$> fsa x <*> fsa y)
UnOp unOp x -> returnIExprVal =<< emitInstr =<< (IUnOp unOp <$> fsa x)
MemOp op' -> toImpMemOp =<< substM op'
Expand Down
1 change: 0 additions & 1 deletion src/lib/Linearize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ linearizeExpr expr = case expr of
linearizeOp :: Emits o => PrimOp SimpIR i -> LinM i o SAtom SAtom
linearizeOp op = case op of
Hof (TypedHof _ e) -> linearizeHof e
DAMOp _ -> error "shouldn't occur here"
RefOp ref m -> do
ref' <- linearizeAtom ref
case m of
Expand Down
Loading

0 comments on commit d5997a8

Please sign in to comment.