on master help sign in
Get rid of dependency on uniplate so AST does not need to derive Data or Typeable
7b20993Evan Czaplicki
Elm.cabal−2
@@ -109,7 +109,6 @@ Library
109 text,
109 text,
110 transformers >= 0.2,
110 transformers >= 0.2,
111 union-find,
111 union-find,
112− uniplate,
113 unordered-containers
112 unordered-containers
114
113
115Executable elm
114Executable elm
@@ -188,7 +187,6 @@ Executable elm
188 text,
187 text,
189 transformers >= 0.2,
188 transformers >= 0.2,
190 union-find,
189 union-find,
191− uniplate,
192 unordered-containers
190 unordered-containers
193
191
194Executable elm-doc
192Executable elm-doc
compiler/SourceSyntax/Declaration.hs−2
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Declaration where
1module SourceSyntax.Declaration where
3
2
4−import Data.Data
5import qualified SourceSyntax.Expression as Expr
3import qualified SourceSyntax.Expression as Expr
6import SourceSyntax.Type
4import SourceSyntax.Type
7import SourceSyntax.PrettyPrint
5import SourceSyntax.PrettyPrint
compiler/SourceSyntax/Expression.hs+5−4
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Expression where
1module SourceSyntax.Expression where
3
2
4−import Data.Data
5import Data.List (intercalate)
3import Data.List (intercalate)
6import SourceSyntax.PrettyPrint
4import SourceSyntax.PrettyPrint
7import Text.PrettyPrint as P
5import Text.PrettyPrint as P
@@ -30,12 +28,12 @@ data Expr t v
30 | Modify (LExpr t v) [(String, LExpr t v)]
28 | Modify (LExpr t v) [(String, LExpr t v)]
31 | Record [(String, LExpr t v)]
29 | Record [(String, LExpr t v)]
32 | Markdown String String [LExpr t v]
30 | Markdown String String [LExpr t v]
33− deriving (Eq, Show, Data, Typeable)
31+ deriving (Eq)
34
32
35data Def tipe var
33data Def tipe var
36 = Def Pattern.Pattern (LExpr tipe var)
34 = Def Pattern.Pattern (LExpr tipe var)
37 | TypeAnnotation String Type.Type
35 | TypeAnnotation String Type.Type
38− deriving (Eq, Show, Data, Typeable)
36+ deriving (Eq, Show)
39
37
40tuple es = Data ("_Tuple" ++ show (length es)) es
38tuple es = Data ("_Tuple" ++ show (length es)) es
41
39
@@ -47,6 +45,9 @@ saveEnvName = "_save_the_environment!!!"
47dummyLet defs =
45dummyLet defs =
48 Location.none $ Let defs (Location.none $ Var saveEnvName)
46 Location.none $ Let defs (Location.none $ Var saveEnvName)
49
47
48+instance Show (Expr t v) where
49+ show = render . pretty
50+
50instance Pretty (Expr t v) where
51instance Pretty (Expr t v) where
51 pretty expr =
52 pretty expr =
52 case expr of
53 case expr of
compiler/SourceSyntax/Literal.hs+1−3
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Literal where
1module SourceSyntax.Literal where
3
2
4−import Data.Data
5import SourceSyntax.PrettyPrint
3import SourceSyntax.PrettyPrint
6import qualified Text.PrettyPrint as PP
4import qualified Text.PrettyPrint as PP
7
5
@@ -10,7 +8,7 @@ data Literal = IntNum Int
10 | Chr Char
8 | Chr Char
11 | Str String
9 | Str String
12 | Boolean Bool
10 | Boolean Bool
13− deriving (Eq, Ord, Data, Typeable, Show)
11+ deriving (Eq, Ord, Show)
14
12
15instance Pretty Literal where
13instance Pretty Literal where
16 pretty literal =
14 pretty literal =
compiler/SourceSyntax/Location.hs+3−5
@@ -1,19 +1,17 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Location where
1module SourceSyntax.Location where
3
2
4−import Data.Data
5import Text.PrettyPrint
3import Text.PrettyPrint
6import SourceSyntax.PrettyPrint
4import SourceSyntax.PrettyPrint
7import qualified Text.Parsec.Pos as Parsec
5import qualified Text.Parsec.Pos as Parsec
8
6
9data SrcPos = Pos { line :: Int, column :: Int }
7data SrcPos = Pos { line :: Int, column :: Int }
10− deriving (Eq, Ord, Data, Typeable)
8+ deriving (Eq, Ord)
11
9
12data SrcSpan = Span SrcPos SrcPos String | NoSpan String
10data SrcSpan = Span SrcPos SrcPos String | NoSpan String
13− deriving (Eq, Ord, Data, Typeable)
11+ deriving (Eq, Ord)
14
12
15data Located e = L SrcSpan e
13data Located e = L SrcSpan e
16− deriving (Eq, Ord, Data, Typeable)
14+ deriving (Eq, Ord)
17
15
18none e = L (NoSpan (render $ pretty e)) e
16none e = L (NoSpan (render $ pretty e)) e
19noneNoDocs = L (NoSpan "")
17noneNoDocs = L (NoSpan "")
compiler/SourceSyntax/Module.hs+1−3
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Module where
1module SourceSyntax.Module where
3
2
4−import Data.Data
5import Data.Binary
3import Data.Binary
6import Data.List (intercalate)
4import Data.List (intercalate)
7import qualified Data.Map as Map
5import qualified Data.Map as Map
@@ -24,7 +22,7 @@ type Exports = [String]
24
22
25type Imports = [(String, ImportMethod)]
23type Imports = [(String, ImportMethod)]
26data ImportMethod = As String | Importing [String] | Hiding [String]
24data ImportMethod = As String | Importing [String] | Hiding [String]
27− deriving (Eq, Ord, Show, Data, Typeable)
25+ deriving (Eq, Ord, Show)
28
26
29instance Binary ImportMethod where
27instance Binary ImportMethod where
30 put (As s) = do put (0 :: Word8)
28 put (As s) = do put (0 :: Word8)
compiler/SourceSyntax/Pattern.hs+1−3
@@ -1,8 +1,6 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Pattern where
1module SourceSyntax.Pattern where
3
2
4import Data.List (intercalate)
3import Data.List (intercalate)
5−import Data.Data
6import SourceSyntax.Helpers as Help
4import SourceSyntax.Helpers as Help
7import SourceSyntax.PrettyPrint
5import SourceSyntax.PrettyPrint
8import Text.PrettyPrint as PP
6import Text.PrettyPrint as PP
@@ -14,7 +12,7 @@ data Pattern = PData String [Pattern]
14 | PVar String
12 | PVar String
15 | PAnything
13 | PAnything
16 | PLiteral Literal.Literal
14 | PLiteral Literal.Literal
17− deriving (Eq, Ord, Data, Typeable, Show)
15+ deriving (Eq, Ord, Show)
18
16
19cons h t = PData "::" [h,t]
17cons h t = PData "::" [h,t]
20nil = PData "[]" []
18nil = PData "[]" []
compiler/SourceSyntax/Type.hs+1−3
@@ -1,8 +1,6 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Type where
1module SourceSyntax.Type where
3
2
4import Data.Binary
3import Data.Binary
5−import Data.Data
6import qualified Data.Map as Map
4import qualified Data.Map as Map
7import qualified SourceSyntax.Helpers as Help
5import qualified SourceSyntax.Helpers as Help
8import Control.Applicative ((<$>), (<*>))
6import Control.Applicative ((<$>), (<*>))
@@ -14,7 +12,7 @@ data Type = Lambda Type Type
14 | Data String [Type]
12 | Data String [Type]
15 | EmptyRecord
13 | EmptyRecord
16 | Record [(String,Type)] Type
14 | Record [(String,Type)] Type
17− deriving (Eq, Show, Data, Typeable)
15+ deriving (Eq, Show)
18
16
19fieldMap :: [(String,a)] -> Map.Map String [a]
17fieldMap :: [(String,a)] -> Map.Map String [a]
20fieldMap fields =
18fieldMap fields =
compiler/Transform/Check.hs+26−8
@@ -8,12 +8,10 @@ import Data.List as List
8import qualified Data.Map as Map
8import qualified Data.Map as Map
9import qualified Data.Maybe as Maybe
9import qualified Data.Maybe as Maybe
10import qualified Data.Set as Set
10import qualified Data.Set as Set
11−import Data.Data
12−import Data.Generics.Uniplate.Data
13import Text.PrettyPrint as P
11import Text.PrettyPrint as P
14
12
15
13
16−mistakes :: (Data t, Data v) => [Declaration t v] -> [Doc]
14+mistakes :: [Declaration t v] -> [Doc]
17mistakes decls =
15mistakes decls =
18 concat [ infiniteTypeAliases decls
16 concat [ infiniteTypeAliases decls
19 , illFormedTypes decls
17 , illFormedTypes decls
@@ -22,15 +20,35 @@ mistakes decls =
22 where
20 where
23 findErrors defs = duplicates defs ++ badOrder defs
21 findErrors defs = duplicates defs ++ badOrder defs
24
22
25−getLets :: (Data t, Data v) => [Declaration t v] -> [[Def t v]]
23+getLets :: [Declaration t v] -> [[Def t v]]
26−getLets decls = defs : concatMap getSubLets defs
24+getLets decls = defs : concatMap defLets defs
27 where
25 where
28− defs = concatMap (\d -> case d of Definition d -> [d] ; _ -> []) decls
26+ defs = [ d | Definition d <- decls ]
29
27
30− getSubLets def =
28+ defLets def =
31 case def of
29 case def of
32− Def pattern expr -> [ defs | Let defs _ <- universeBi expr ]
33 TypeAnnotation _ _ -> []
30 TypeAnnotation _ _ -> []
31+ Def _ expr -> exprLets expr
32+
33+ exprLets (L _ expr) =
34+ case expr of
35+ Var _ -> []
36+ Lambda p e -> exprLets e
37+ Binop op e1 e2 -> exprLets e1 ++ exprLets e2
38+ Case e cases -> exprLets e ++ concatMap (exprLets . snd) cases
39+ Data name es -> concatMap exprLets es
40+ Literal _ -> []
41+ Range e1 e2 -> exprLets e1 ++ exprLets e2
42+ ExplicitList es -> concatMap exprLets es
43+ App e1 e2 -> exprLets e1 ++ exprLets e2
44+ MultiIf branches -> concatMap (\(b,e) -> exprLets b ++ exprLets e) branches
45+ Access e lbl -> exprLets e
46+ Remove e lbl -> exprLets e
47+ Insert e lbl v -> exprLets e ++ exprLets v
48+ Modify e fields -> exprLets e ++ concatMap (exprLets . snd) fields
49+ Record fields -> concatMap (exprLets . snd) fields
50+ Markdown uid md es -> []
51+ Let defs body -> [defs] ++ exprLets body
34
52
35dups :: Eq a => [a] -> [a]
53dups :: Eq a => [a] -> [a]
36dups = map head . filter ((>1) . length) . List.group
54dups = map head . filter ((>1) . length) . List.group