on master help sign in
Hold less in Interface / add "privatize" to shrink memory
542c763Evan Czaplicki
src/AST/Module.hs+24−16
@@ -13,7 +13,7 @@ module AST.Module
13 , Aliases
13 , Aliases
14 , Unions, UnionInfo, CanonicalUnion
14 , Unions, UnionInfo, CanonicalUnion
15
15
16− , Interfaces, Interface(..), toInterface
16+ , Interfaces, Interface(..), toInterface, privatize
17 )
17 )
18 where
18 where
19
19
@@ -29,8 +29,6 @@ import qualified AST.Module.Name as Name
29import qualified AST.Type as Type
29import qualified AST.Type as Type
30import qualified AST.Variable as Var
30import qualified AST.Variable as Var
31import qualified Docs.AST as Docs
31import qualified Docs.AST as Docs
32−import qualified Elm.Package as Package
33−import qualified Elm.Compiler.Version as Compiler
34import qualified Reporting.Annotation as A
32import qualified Reporting.Annotation as A
35import qualified Reporting.Region as R
33import qualified Reporting.Region as R
36
34
@@ -191,10 +189,8 @@ type Interfaces =
191{-| Key facts about a module, used when reading info from .elmi files. -}
189{-| Key facts about a module, used when reading info from .elmi files. -}
192data Interface =
190data Interface =
193 Interface
191 Interface
194− { iVersion :: Package.Version
195− , iPackage :: Package.Name
196− , iExports :: [Var.Value]
192+ { iExports :: [Var.Value]
197− , iImports :: [Name.Raw]
193+ , iImports :: [Name.Raw] -- TODO perhaps use this to crawl faster
198 , iTypes :: Types
194 , iTypes :: Types
199 , iUnions :: Unions
195 , iUnions :: Unions
200 , iAliases :: Aliases
196 , iAliases :: Aliases
@@ -202,16 +198,14 @@ data Interface =
202 }
198 }
203
199
204
200
205−toInterface :: Package.Name -> Optimized -> Interface
201+toInterface :: Optimized -> Interface
206−toInterface pkgName modul =
202+toInterface modul =
207 let
203 let
208 myInfo =
204 myInfo =
209 info modul
205 info modul
210 in
206 in
211 Interface
207 Interface
212− { iVersion = Compiler.version
213− , iPackage = pkgName
214− , iExports = exports myInfo
208+ { iExports = exports myInfo
215 , iImports = imports myInfo
209 , iImports = imports myInfo
216 , iTypes = types myInfo
210 , iTypes = types myInfo
217 , iUnions = unions myInfo
211 , iUnions = unions myInfo
@@ -220,14 +214,28 @@ toInterface pkgName modul =
220 }
214 }
221
215
222
216
217+privatize :: Interface -> Maybe Interface
218+privatize (Interface _ _ _ myUnions myAliases _) =
219+ if Map.null myUnions && Map.null myAliases then
220+ Nothing
221+
222+ else
223+ Just $ Interface
224+ { iExports = []
225+ , iImports = []
226+ , iTypes = Map.empty
227+ , iUnions = myUnions
228+ , iAliases = myAliases
229+ , iFixities = []
230+ }
231+
232+
223instance Binary Interface where
233instance Binary Interface where
224 get =
234 get =
225− Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
235+ Interface <$> get <*> get <*> get <*> get <*> get <*> get
226
236
227 put modul =
237 put modul =
228− do put (iVersion modul)
229− put (iPackage modul)
230− put (iExports modul)
238+ do put (iExports modul)
231 put (iImports modul)
239 put (iImports modul)
232 put (iTypes modul)
240 put (iTypes modul)
233 put (iUnions modul)
241 put (iUnions modul)
src/Elm/Compiler.hs+1−1
@@ -98,7 +98,7 @@ compile context source =
98 do modul <- Compile.compile packageName importDict interfaces source
98 do modul <- Compile.compile packageName importDict interfaces source
99 docs <- Result.format id (docsGen exposed modul)
99 docs <- Result.format id (docsGen exposed modul)
100
100
101− let interface = Module.toInterface packageName modul
101+ let interface = Module.toInterface modul
102 let javascript = {-# SCC elm_compiler_generate #-} JS.generate modul
102 let javascript = {-# SCC elm_compiler_generate #-} JS.generate modul
103
103
104 return (Result docs interface javascript)
104 return (Result docs interface javascript)
src/Elm/Compiler/Module.hs+3−9
@@ -1,7 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Module
3module Elm.Compiler.Module
4− ( Interface, Interfaces
4+ ( Module.Interface, Module.Interfaces, Module.privatize
5 , ModuleName.Raw
5 , ModuleName.Raw
6 , nameToPath
6 , nameToPath
7 , nameToString, nameFromText
7 , nameToString, nameFromText
@@ -31,18 +31,12 @@ import qualified Generate.JavaScript.Variable as Gen
31-- INTERFACES
31-- INTERFACES
32
32
33
33
34−type Interface = Module.Interface
35−
36−
37−type Interfaces = Module.Interfaces
38−
39−
40−interfaceAliasedTypes :: Interface -> Map.Map Text PublicType.Type
34+interfaceAliasedTypes :: Module.Interface -> Map.Map Text PublicType.Type
41interfaceAliasedTypes interface =
35interfaceAliasedTypes interface =
42 Map.map Extract.extract (Module.iTypes interface)
36 Map.map Extract.extract (Module.iTypes interface)
43
37
44
38
45−programTypes :: Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
39+programTypes :: Module.Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
46programTypes =
40programTypes =
47 Extract.extractProgram
41 Extract.extractProgram
48
42