Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove built in fst and snd #322

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prelude.dx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ instance float32Fractional : Fractional Float32 where

def (&) (a:Type) (b:Type) : Type = %PairType a b
def (,) (x:a) (y:b) : (a & b) = %pair x y
def fst (p: (a & b)) : a = %fst p
def snd (p: (a & b)) : b = %snd p
def swap (p:(a&b)) : (b&a) = (snd p, fst p)
def fst ((f,s): (a & b)) : a = f
def snd ((f,s): (a & b)) : b = s
def swap ((f,s):(a&b)) : (b&a) = (s, f)

def (<<<) (f: b -> c) (g: a -> b) : a -> c = \x. f (g x)
def (>>>) (g: a -> b) (f: b -> c) : a -> c = \x. f (g x)
Expand Down
4 changes: 0 additions & 4 deletions src/lib/Autodiff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ linearizeOp op = case op of
MTell x -> liftA MTell $ la x
MGet -> pure MGet
MPut x -> liftA MPut $ la x) `bindLin` emitOp
Fst x -> (Fst <$> la x) `bindLin` emitOp
Snd x -> (Snd <$> la x) `bindLin` emitOp
IndexRef ref i -> (IndexRef <$> la ref <*> pure i) `bindLin` emitOp
FstRef ref -> (FstRef <$> la ref ) `bindLin` emitOp
SndRef ref -> (SndRef <$> la ref ) `bindLin` emitOp
Expand Down Expand Up @@ -582,8 +580,6 @@ transposeExpr expr ct = case expr of

transposeOp :: Op -> Atom -> TransposeM ()
transposeOp op ct = case op of
Fst x -> flip emitCTToRef ct =<< (traverse $ emitOp . FstRef) =<< linAtomRef x
Snd x -> flip emitCTToRef ct =<< (traverse $ emitOp . SndRef) =<< linAtomRef x
ScalarUnOp FNeg x -> transposeAtom x =<< neg ct
ScalarUnOp _ _ -> notLinear
ScalarBinOp FAdd x y -> transposeAtom x ct >> transposeAtom y ct
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ toImpOp (maybeDest, op) = case op of
ithDest <- destGet dest =<< intToIndex (binderType b) (IIdxRepVal i)
copyAtom ithDest row
destToAtom dest
Fst ~(PairVal x _) -> returnVal x
Snd ~(PairVal _ y) -> returnVal y
PrimEffect refDest m -> do
case m of
MAsk -> returnVal =<< destToAtom refDest
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ evalOp expr = case expr of
Con (IntRangeVal _ _ i) -> return i
Con (IndexRangeVal _ _ _ i) -> return i
_ -> evalEmbed (indexToIntE idxArg)
Fst p -> return x where (PairVal x _) = p
Snd p -> return y where (PairVal _ y) = p
_ -> error $ "Not implemented: " ++ pprint expr

-- We can use this when we know we won't be dereferencing pointers. A better
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Simplify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ simplifyExpr expr = case expr of
-- TODO: come up with a coherent strategy for ordering these various reductions
simplifyOp :: Op -> SimplifyM Atom
simplifyOp op = case op of
Fst (PairVal x _) -> return x
Snd (PairVal _ y) -> return y
RecordCons left right -> case getType right of
RecordTy (NoExt rightTys) -> do
-- Unpack, then repack with new arguments (possibly in the middle).
Expand Down
4 changes: 1 addition & 3 deletions src/lib/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ data PrimCon e =
deriving (Show, Eq, Generic, Functor, Foldable, Traversable)

data PrimOp e =
Fst e
| Snd e
| TabCon e [e] -- table type elements
TabCon e [e] -- table type elements
| ScalarBinOp BinOp e e
| ScalarUnOp UnOp e
| Select e e e -- predicate, val-if-true, val-if-false
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ typeCheckOp op = case op of
mapM_ (uncurry (|:)) $ zip xs (fmap (snd . applyAbs a) idxs)
assertEq (length idxs) (length xs) "Index set size mismatch"
return ty
Fst p -> do { PairTy x _ <- typeCheck p; return x}
Snd p -> do { PairTy _ y <- typeCheck p; return y}
ScalarBinOp binop x y -> bindM2 (checkBinOp binop) (typeCheck x) (typeCheck y)
ScalarUnOp unop x -> checkUnOp unop =<< typeCheck x
Select p x y -> do
Expand Down