on master help sign in
Introduce Canonical module nms with pkg info
0d89d62JoeyEremondi
src/AST/Module.hs+10−1
@@ -1,11 +1,12 @@
1module AST.Module
1module AST.Module
2− ( Interfaces
2+ ( Interfaces, CanonicalInterfaces
3 , Types, Aliases, ADTs
3 , Types, Aliases, ADTs
4 , AdtInfo, CanonicalAdt
4 , AdtInfo, CanonicalAdt
5 , SourceModule, ValidModule, CanonicalModule, Optimized
5 , SourceModule, ValidModule, CanonicalModule, Optimized
6 , Module(..), Body(..)
6 , Module(..), Body(..)
7 , Header(..)
7 , Header(..)
8 , Name, nameToString, nameIsNative
8 , Name, nameToString, nameIsNative
9+ , CanonicalName(..), canonPkg, canonModul
9 , Interface(..), toInterface
10 , Interface(..), toInterface
10 , UserImport, DefaultImport, ImportMethod(..)
11 , UserImport, DefaultImport, ImportMethod(..)
11 ) where
12 ) where
@@ -29,6 +30,7 @@ import qualified Reporting.Annotation as A
29-- HELPFUL TYPE ALIASES
30-- HELPFUL TYPE ALIASES
30
31
31type Interfaces = Map.Map Name Interface
32type Interfaces = Map.Map Name Interface
33+type CanonicalInterfaces = Map.Map CanonicalName Interface
32
34
33type Types = Map.Map String Type.Canonical
35type Types = Map.Map String Type.Canonical
34type Aliases = Map.Map String ([String], Type.Canonical)
36type Aliases = Map.Map String ([String], Type.Canonical)
@@ -98,6 +100,13 @@ data Header imports = Header
98type Name = [String] -- must be non-empty
100type Name = [String] -- must be non-empty
99
101
100
102
103+data CanonicalName =
104+ CanonicalName
105+ { canonPkg :: Package.Name
106+ , canonModul :: Name
107+ }
108+
109+
101nameToString :: Name -> String
110nameToString :: Name -> String
102nameToString =
111nameToString =
103 List.intercalate "."
112 List.intercalate "."
src/Compile.hs+27−6
@@ -17,19 +17,23 @@ import qualified Type.Inference as TI
17
17
18
18
19compile
19compile
20+ :: Map.Map Module.Name Package.Name
20− :: Package.Name
21+ -> Package.Name
21 -> Bool
22 -> Bool
22− -> Module.Interfaces
23+ -> Module.CanonicalInterfaces
23 -> String
24 -> String
24 -> Result.Result Warning.Warning Error.Error Module.CanonicalModule
25 -> Result.Result Warning.Warning Error.Error Module.CanonicalModule
25
26
26−compile packageName isRoot interfaces source =
27+compile importedPackages packageName isRoot interfaces source =
27 do
28 do
28 -- determine if default imports should be added
29 -- determine if default imports should be added
29 -- only elm-lang/core is exempt
30 -- only elm-lang/core is exempt
30 let needsDefaults =
31 let needsDefaults =
31 not (packageName == Package.coreName)
32 not (packageName == Package.coreName)
32
33
34+ let normalInterfaces =
35+ unCanonicalizeInterfaces importedPackages interfaces
36+
33 -- Parse the source code
37 -- Parse the source code
34 validModule <-
38 validModule <-
35 Result.mapError Error.Syntax $
39 Result.mapError Error.Syntax $
@@ -37,7 +41,7 @@ compile packageName isRoot interfaces source =
37
41
38 -- Canonicalize all variables, pinning down where they came from.
42 -- Canonicalize all variables, pinning down where they came from.
39 canonicalModule <-
43 canonicalModule <-
40− Canonicalize.module' interfaces validModule
44+ Canonicalize.module' normalInterfaces validModule
41
45
42 -- Run type inference on the program.
46 -- Run type inference on the program.
43 types <-
47 types <-
@@ -48,7 +52,7 @@ compile packageName isRoot interfaces source =
48 Result.mapError Error.Type $
52 Result.mapError Error.Type $
49 Nitpick.topLevelTypes types (Module.body validModule)
53 Nitpick.topLevelTypes types (Module.body validModule)
50
54
51− Nitpick.patternMatches interfaces canonicalModule
55+ Nitpick.patternMatches normalInterfaces canonicalModule
52
56
53 -- Add the real list of types
57 -- Add the real list of types
54 let body = (Module.body canonicalModule) { Module.types = types }
58 let body = (Module.body canonicalModule) { Module.types = types }
@@ -56,9 +60,26 @@ compile packageName isRoot interfaces source =
56 return $ canonicalModule { Module.body = body }
60 return $ canonicalModule { Module.body = body }
57
61
58
62
59−getOpTable :: Module.Interfaces -> Parse.OpTable
63+getOpTable :: Module.CanonicalInterfaces -> Parse.OpTable
60getOpTable interfaces =
64getOpTable interfaces =
61 Map.elems interfaces
65 Map.elems interfaces
62 |> concatMap Module.iFixities
66 |> concatMap Module.iFixities
63 |> map (\(assoc,lvl,op) -> (op,(lvl,assoc)))
67 |> map (\(assoc,lvl,op) -> (op,(lvl,assoc)))
64 |> Map.fromList
68 |> Map.fromList
69+
70+
71+unCanonicalizeInterfaces
72+ :: Map.Map Module.Name Package.Name
73+ -> Module.CanonicalInterfaces
74+ -> Module.Interfaces
75+unCanonicalizeInterfaces packageInfo ifaces =
76+ let
77+ foldFun canonName iface mapSoFar =
78+ case Map.lookup (Module.canonModul canonName) packageInfo of
79+ Just pkg | pkg == (error "TODO iface pkg") ->
80+ Map.insert (Module.canonModul canonName) iface mapSoFar
81+
82+ _ ->
83+ mapSoFar
84+ in
85+ Map.foldrWithKey foldFun Map.empty ifaces
src/Elm/Compiler.hs+8−4
@@ -63,19 +63,22 @@ parseDependencies sourceCode =
63compile
63compile
64 :: Context
64 :: Context
65 -> String
65 -> String
66− -> Map.Map PublicModule.Name PublicModule.Interface
66+ -> Map.Map PublicModule.CanonicalName PublicModule.Interface
67 -> (Dealiaser, [Warning], Either [Error] Result)
67 -> (Dealiaser, [Warning], Either [Error] Result)
68
68
69compile context source interfaces =
69compile context source interfaces =
70 let
70 let
71− (Context packageName isRoot isExposed) =
71+ (Context packageName isRoot isExposed modulePackages) =
72 context
72 context
73
73
74 unwrappedInterfaces =
74 unwrappedInterfaces =
75− Map.mapKeysMonotonic (\(PublicModule.Name name) -> name) interfaces
75+ Map.mapKeysMonotonic PublicModule.fromCanonicalName interfaces
76+
77+ unwrappedPackages =
78+ Map.mapKeysMonotonic (\(PublicModule.Name strs) -> strs ) modulePackages
76
79
77 (Result.Result (dealiaser, warnings) rawResult) =
80 (Result.Result (dealiaser, warnings) rawResult) =
78− do modul <- Compile.compile packageName isRoot unwrappedInterfaces source
81+ do modul <- Compile.compile unwrappedPackages packageName isRoot unwrappedInterfaces source
79 docs <- docsGen isExposed modul
82 docs <- docsGen isExposed modul
80
83
81 let interface = Module.toInterface modul
84 let interface = Module.toInterface modul
@@ -94,6 +97,7 @@ data Context = Context
94 { _packageName :: Package.Name
97 { _packageName :: Package.Name
95 , _isRoot :: Bool
98 , _isRoot :: Bool
96 , _isExposed :: Bool
99 , _isExposed :: Bool
100+ , _modulePackages :: Map.Map PublicModule.Name Package.Name
97 }
101 }
98
102
99
103
src/Elm/Compiler/Module.hs+22−1
@@ -1,5 +1,6 @@
1module Elm.Compiler.Module
1module Elm.Compiler.Module
2− ( Interface, Name(Name)
2+ ( Interface, Name(Name), name
3+ , CanonicalName(CanonicalName), canonicalName, canonPkg, canonModul, fromCanonicalName
3 , nameToPath
4 , nameToPath
4 , nameToString, nameFromString
5 , nameToString, nameFromString
5 , hyphenate, dehyphenate
6 , hyphenate, dehyphenate
@@ -22,6 +23,7 @@ import qualified AST.Module as Module
22import qualified Elm.Compiler.Imports as Imports
23import qualified Elm.Compiler.Imports as Imports
23import qualified Elm.Compiler.Type as Type
24import qualified Elm.Compiler.Type as Type
24import qualified Elm.Compiler.Type.Extract as Extract
25import qualified Elm.Compiler.Type.Extract as Extract
26+import qualified Elm.Package as Package
25
27
26
28
27-- EXPOSED TYPES
29-- EXPOSED TYPES
@@ -32,6 +34,25 @@ type Interface = Module.Interface
32newtype Name = Name [String]
34newtype Name = Name [String]
33 deriving (Eq, Ord)
35 deriving (Eq, Ord)
34
36
37+data CanonicalName =
38+ CanonicalName
39+ { canonPkg :: Package.Name
40+ , canonModul :: Name
41+ }
42+
43+
44+fromCanonicalName :: CanonicalName -> Module.CanonicalName
45+fromCanonicalName (CanonicalName p (Name n)) =
46+ Module.CanonicalName p n
47+
48+
49+canonicalName :: Package.Name -> Name -> CanonicalName
50+canonicalName = CanonicalName
51+
52+
53+name :: [String] -> Name
54+name = Name
55+
35
56
36defaultImports :: [Name]
57defaultImports :: [Name]
37defaultImports =
58defaultImports =
src/Type/Inference.hs+7−6
@@ -22,7 +22,7 @@ import System.IO.Unsafe
22
22
23
23
24infer
24infer
25− :: Interfaces
25+ :: CanonicalInterfaces
26 -> Module.CanonicalModule
26 -> Module.CanonicalModule
27 -> Except [A.Located Error.Error] (Map.Map String Type.Canonical)
27 -> Except [A.Located Error.Error] (Map.Map String Type.Canonical)
28infer interfaces modul =
28infer interfaces modul =
@@ -39,7 +39,7 @@ infer interfaces modul =
39
39
40
40
41genConstraints
41genConstraints
42− :: Interfaces
42+ :: CanonicalInterfaces
43 -> Module.CanonicalModule
43 -> Module.CanonicalModule
44 -> IO (Env.TypeDict, T.TypeConstraint)
44 -> IO (Env.TypeDict, T.TypeConstraint)
45genConstraints interfaces modul =
45genConstraints interfaces modul =
@@ -69,15 +69,15 @@ genConstraints interfaces modul =
69
69
70canonicalizeValues
70canonicalizeValues
71 :: Env.Environment
71 :: Env.Environment
72− -> (Module.Name, Interface)
72+ -> (Module.CanonicalName, Interface)
73 -> IO [(String, ([T.Variable], T.Type))]
73 -> IO [(String, ([T.Variable], T.Type))]
74canonicalizeValues env (moduleName, iface) =
74canonicalizeValues env (moduleName, iface) =
75 forM (Map.toList (iTypes iface)) $ \(name,tipe) ->
75 forM (Map.toList (iTypes iface)) $ \(name,tipe) ->
76 do tipe' <- Env.instantiateType env tipe Map.empty
76 do tipe' <- Env.instantiateType env tipe Map.empty
77− return (Module.nameToString moduleName ++ "." ++ name, tipe')
77+ return ((Module.nameToString $ Module.canonModul moduleName) ++ "." ++ name, tipe')
78
78
79
79
80−canonicalizeAdts :: Interfaces -> Module.CanonicalModule -> [CanonicalAdt]
80+canonicalizeAdts :: CanonicalInterfaces -> Module.CanonicalModule -> [CanonicalAdt]
81canonicalizeAdts interfaces modul =
81canonicalizeAdts interfaces modul =
82 localAdts ++ importedAdts
82 localAdts ++ importedAdts
83 where
83 where
@@ -85,7 +85,8 @@ canonicalizeAdts interfaces modul =
85 localAdts = format (Module.names modul, datatypes (body modul))
85 localAdts = format (Module.names modul, datatypes (body modul))
86
86
87 importedAdts :: [CanonicalAdt]
87 importedAdts :: [CanonicalAdt]
88− importedAdts = concatMap (format . second iAdts) (Map.toList interfaces)
88+ importedAdts = concatMap (format . second iAdts)
89+ (map (\(nm, iface) -> (Module.canonModul nm, iface )) $ Map.toList $ interfaces)
89
90
90 format :: (Module.Name, Module.ADTs) -> [CanonicalAdt]
91 format :: (Module.Name, Module.ADTs) -> [CanonicalAdt]
91 format (home, adts) =
92 format (home, adts) =