This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
forked from elm/compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Summary.hs
107 lines (72 loc) · 2.31 KB
/
Summary.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{-# OPTIONS_GHC -Wall #-}
module Elm.Project.Summary
( Summary(..)
, ExposedModules
, DepsGraph
, init
, cheapInit
)
where
import Prelude hiding (init)
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Elm.Compiler.Module as Module
import Elm.Package (Package(..), Name, Version)
import Elm.Project.Json (Project(..), AppInfo(..), PkgInfo(..))
import qualified Elm.Project.Json as Project
-- SUMMARY
data Summary =
Summary
{ _root :: FilePath
, _project :: Project
, _exposed :: ExposedModules
, _ifaces :: Module.Interfaces
, _depsGraph :: DepsGraph
}
type ExposedModules =
Map.Map Module.Raw [Package]
type DepsGraph =
Map.Map Name ( Version, [Name] )
-- MAKE SUMMARY
init :: FilePath -> Project -> Map Name PkgInfo -> Module.Interfaces -> Summary
init root project deps ifaces =
let
exposed =
case project of
Project.App info ->
getExposed deps (_app_deps_direct info)
Project.Pkg info ->
getExposed deps (_pkg_deps info)
privatizedInterfaces =
Map.mapMaybeWithKey (privatize exposed) ifaces
depsGraph =
Map.foldr toNode Map.empty deps
in
Summary root project exposed privatizedInterfaces depsGraph
privatize :: ExposedModules -> Module.Canonical -> Module.Interface -> Maybe Module.Interface
privatize exposed (Module.Canonical _ name) iface =
case Map.lookup name exposed of
Just [_] ->
Just iface
_ ->
Nothing
toNode :: PkgInfo -> DepsGraph -> DepsGraph
toNode (PkgInfo name _ _ version _ deps _ _) graph =
Map.insert name (version, Map.keys deps) graph
-- MAKE CHEAP SUMMARY
cheapInit :: FilePath -> PkgInfo -> Map Name PkgInfo -> Module.Interfaces -> Summary
cheapInit root info deps ifaces =
Summary root (Pkg info) (getExposed deps (_pkg_deps info)) ifaces Map.empty
getExposed :: Map Name PkgInfo -> Map Name a -> ExposedModules
getExposed deps directs =
Map.foldl insertExposed Map.empty (Map.intersection deps directs)
insertExposed :: ExposedModules -> PkgInfo -> ExposedModules
insertExposed exposed info =
let
home =
Package (_pkg_name info) (_pkg_version info)
insertModule dict modul =
Map.insertWith (++) modul [home] dict
in
List.foldl' insertModule exposed (Project.getExposed info)