on master help sign in
Get rid of dependency on uniplate so AST does not need to derive Data or Typeable

This is motivated by wanting to add things to the AST that cannot derive Data or Typeable

commit7b20993869b26f08d2a445782d2a483215efbf8a authorEvan Czaplicki <info@elm-lang.org> dateFri 20 Dec 2013, 16:41 (13 years ago) parent39769b7
9 files changed+38−33
Elm.cabal−2 compiler/SourceSyntax/Declaration.hs−2 compiler/SourceSyntax/Expression.hs+5−4 compiler/SourceSyntax/Literal.hs+1−3 compiler/SourceSyntax/Location.hs+3−5 compiler/SourceSyntax/Module.hs+1−3 compiler/SourceSyntax/Pattern.hs+1−3 compiler/SourceSyntax/Type.hs+1−3 compiler/Transform/Check.hs+26−8
Elm.cabal−2
@@ -109,7 +109,6 @@ Library
109109 text,
110110 transformers >= 0.2,
111111 union-find,
112− uniplate,
113112 unordered-containers
114113
115114Executable elm
@@ -188,7 +187,6 @@ Executable elm
188187 text,
189188 transformers >= 0.2,
190189 union-find,
191− uniplate,
192190 unordered-containers
193191
194192Executable elm-doc
compiler/SourceSyntax/Declaration.hs−2
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Declaration where
32
4−import Data.Data
53import qualified SourceSyntax.Expression as Expr
64import SourceSyntax.Type
75import SourceSyntax.PrettyPrint
compiler/SourceSyntax/Expression.hs+5−4
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Expression where
32
4−import Data.Data
53import Data.List (intercalate)
64import SourceSyntax.PrettyPrint
75import Text.PrettyPrint as P
@@ -30,12 +28,12 @@ data Expr t v
3028 | Modify (LExpr t v) [(String, LExpr t v)]
3129 | Record [(String, LExpr t v)]
3230 | Markdown String String [LExpr t v]
33− deriving (Eq, Show, Data, Typeable)
31+ deriving (Eq)
3432
3533data Def tipe var
3634 = Def Pattern.Pattern (LExpr tipe var)
3735 | TypeAnnotation String Type.Type
38− deriving (Eq, Show, Data, Typeable)
36+ deriving (Eq, Show)
3937
4038tuple es = Data ("_Tuple" ++ show (length es)) es
4139
@@ -47,6 +45,9 @@ saveEnvName = "_save_the_environment!!!"
4745dummyLet defs =
4846 Location.none $ Let defs (Location.none $ Var saveEnvName)
4947
48+instance Show (Expr t v) where
49+ show = render . pretty
50+
5051instance Pretty (Expr t v) where
5152 pretty expr =
5253 case expr of
compiler/SourceSyntax/Literal.hs+1−3
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Literal where
32
4−import Data.Data
53import SourceSyntax.PrettyPrint
64import qualified Text.PrettyPrint as PP
75
@@ -10,7 +8,7 @@ data Literal = IntNum Int
108 | Chr Char
119 | Str String
1210 | Boolean Bool
13− deriving (Eq, Ord, Data, Typeable, Show)
11+ deriving (Eq, Ord, Show)
1412
1513instance Pretty Literal where
1614 pretty literal =
compiler/SourceSyntax/Location.hs+3−5
@@ -1,19 +1,17 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Location where
32
4−import Data.Data
53import Text.PrettyPrint
64import SourceSyntax.PrettyPrint
75import qualified Text.Parsec.Pos as Parsec
86
97data SrcPos = Pos { line :: Int, column :: Int }
10− deriving (Eq, Ord, Data, Typeable)
8+ deriving (Eq, Ord)
119
1210data SrcSpan = Span SrcPos SrcPos String | NoSpan String
13− deriving (Eq, Ord, Data, Typeable)
11+ deriving (Eq, Ord)
1412
1513data Located e = L SrcSpan e
16− deriving (Eq, Ord, Data, Typeable)
14+ deriving (Eq, Ord)
1715
1816none e = L (NoSpan (render $ pretty e)) e
1917noneNoDocs = L (NoSpan "")
compiler/SourceSyntax/Module.hs+1−3
@@ -1,7 +1,5 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Module where
32
4−import Data.Data
53import Data.Binary
64import Data.List (intercalate)
75import qualified Data.Map as Map
@@ -24,7 +22,7 @@ type Exports = [String]
2422
2523type Imports = [(String, ImportMethod)]
2624data ImportMethod = As String | Importing [String] | Hiding [String]
27− deriving (Eq, Ord, Show, Data, Typeable)
25+ deriving (Eq, Ord, Show)
2826
2927instance Binary ImportMethod where
3028 put (As s) = do put (0 :: Word8)
compiler/SourceSyntax/Pattern.hs+1−3
@@ -1,8 +1,6 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Pattern where
32
43import Data.List (intercalate)
5−import Data.Data
64import SourceSyntax.Helpers as Help
75import SourceSyntax.PrettyPrint
86import Text.PrettyPrint as PP
@@ -14,7 +12,7 @@ data Pattern = PData String [Pattern]
1412 | PVar String
1513 | PAnything
1614 | PLiteral Literal.Literal
17− deriving (Eq, Ord, Data, Typeable, Show)
15+ deriving (Eq, Ord, Show)
1816
1917cons h t = PData "::" [h,t]
2018nil = PData "[]" []
compiler/SourceSyntax/Type.hs+1−3
@@ -1,8 +1,6 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21module SourceSyntax.Type where
32
43import Data.Binary
5−import Data.Data
64import qualified Data.Map as Map
75import qualified SourceSyntax.Helpers as Help
86import Control.Applicative ((<$>), (<*>))
@@ -14,7 +12,7 @@ data Type = Lambda Type Type
1412 | Data String [Type]
1513 | EmptyRecord
1614 | Record [(String,Type)] Type
17− deriving (Eq, Show, Data, Typeable)
15+ deriving (Eq, Show)
1816
1917fieldMap :: [(String,a)] -> Map.Map String [a]
2018fieldMap fields =
compiler/Transform/Check.hs+26−8
@@ -8,12 +8,10 @@ import Data.List as List
88import qualified Data.Map as Map
99import qualified Data.Maybe as Maybe
1010import qualified Data.Set as Set
11−import Data.Data
12−import Data.Generics.Uniplate.Data
1311import Text.PrettyPrint as P
1412
1513
16−mistakes :: (Data t, Data v) => [Declaration t v] -> [Doc]
14+mistakes :: [Declaration t v] -> [Doc]
1715mistakes decls =
1816 concat [ infiniteTypeAliases decls
1917 , illFormedTypes decls
@@ -22,15 +20,35 @@ mistakes decls =
2220 where
2321 findErrors defs = duplicates defs ++ badOrder defs
2422
25−getLets :: (Data t, Data v) => [Declaration t v] -> [[Def t v]]
26−getLets decls = defs : concatMap getSubLets defs
23+getLets :: [Declaration t v] -> [[Def t v]]
24+getLets decls = defs : concatMap defLets defs
2725 where
28− defs = concatMap (\d -> case d of Definition d -> [d] ; _ -> []) decls
26+ defs = [ d | Definition d <- decls ]
2927
30− getSubLets def =
28+ defLets def =
3129 case def of
32− Def pattern expr -> [ defs | Let defs _ <- universeBi expr ]
3330 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
3452
3553dups :: Eq a => [a] -> [a]
3654dups = map head . filter ((>1) . length) . List.group