on master help sign in
Hold less in Interface / add "privatize" to shrink memory

Remove the compiler version and package name from the interface. This information will be captured by where the interface files live. The privatize function will drop everything except type information. This is nice for cases when the module is not actually accessible, but some of its types may flow into scope anyway.

commit542c7637b5adbf6e03538cbe74f76de0ed11434a authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 3 Mar 2017, 13:58 (10 years ago) parent65e6ff1
3 files changed+28−26
src/AST/Module.hs+24−16 src/Elm/Compiler.hs+1−1 src/Elm/Compiler/Module.hs+3−9
src/AST/Module.hs+24−16
@@ -13,7 +13,7 @@ module AST.Module
1313 , Aliases
1414 , Unions, UnionInfo, CanonicalUnion
1515
16− , Interfaces, Interface(..), toInterface
16+ , Interfaces, Interface(..), toInterface, privatize
1717 )
1818 where
1919
@@ -29,8 +29,6 @@ import qualified AST.Module.Name as Name
2929import qualified AST.Type as Type
3030import qualified AST.Variable as Var
3131import qualified Docs.AST as Docs
32−import qualified Elm.Package as Package
33−import qualified Elm.Compiler.Version as Compiler
3432import qualified Reporting.Annotation as A
3533import qualified Reporting.Region as R
3634
@@ -191,10 +189,8 @@ type Interfaces =
191189{-| Key facts about a module, used when reading info from .elmi files. -}
192190data Interface =
193191 Interface
194− { iVersion :: Package.Version
195− , iPackage :: Package.Name
196− , iExports :: [Var.Value]
197− , iImports :: [Name.Raw]
192+ { iExports :: [Var.Value]
193+ , iImports :: [Name.Raw] -- TODO perhaps use this to crawl faster
198194 , iTypes :: Types
199195 , iUnions :: Unions
200196 , iAliases :: Aliases
@@ -202,16 +198,14 @@ data Interface =
202198 }
203199
204200
205−toInterface :: Package.Name -> Optimized -> Interface
206−toInterface pkgName modul =
201+toInterface :: Optimized -> Interface
202+toInterface modul =
207203 let
208204 myInfo =
209205 info modul
210206 in
211207 Interface
212− { iVersion = Compiler.version
213− , iPackage = pkgName
214− , iExports = exports myInfo
208+ { iExports = exports myInfo
215209 , iImports = imports myInfo
216210 , iTypes = types myInfo
217211 , iUnions = unions myInfo
@@ -220,14 +214,28 @@ toInterface pkgName modul =
220214 }
221215
222216
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+
223233instance Binary Interface where
224234 get =
225− Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
235+ Interface <$> get <*> get <*> get <*> get <*> get <*> get
226236
227237 put modul =
228− do put (iVersion modul)
229− put (iPackage modul)
230− put (iExports modul)
238+ do put (iExports modul)
231239 put (iImports modul)
232240 put (iTypes modul)
233241 put (iUnions modul)
src/Elm/Compiler.hs+1−1
@@ -98,7 +98,7 @@ compile context source =
9898 do modul <- Compile.compile packageName importDict interfaces source
9999 docs <- Result.format id (docsGen exposed modul)
100100
101− let interface = Module.toInterface packageName modul
101+ let interface = Module.toInterface modul
102102 let javascript = {-# SCC elm_compiler_generate #-} JS.generate modul
103103
104104 return (Result docs interface javascript)
src/Elm/Compiler/Module.hs+3−9
@@ -1,7 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
33module Elm.Compiler.Module
4− ( Interface, Interfaces
4+ ( Module.Interface, Module.Interfaces, Module.privatize
55 , ModuleName.Raw
66 , nameToPath
77 , nameToString, nameFromText
@@ -31,18 +31,12 @@ import qualified Generate.JavaScript.Variable as Gen
3131-- INTERFACES
3232
3333
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
4135interfaceAliasedTypes interface =
4236 Map.map Extract.extract (Module.iTypes interface)
4337
4438
45−programTypes :: Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
39+programTypes :: Module.Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
4640programTypes =
4741 Extract.extractProgram
4842