on master help sign in
Introduce Canonical module nms with pkg info
commit0d89d62f82e29fafb8a125f70af66fda3ee5be45 authorJoeyEremondi <joey@eremondi.com> dateThu 27 Aug 2015, 17:02 (11 years ago) parent803e56b
5 files changed+74−18
src/AST/Module.hs+10−1 src/Compile.hs+27−6 src/Elm/Compiler.hs+8−4 src/Elm/Compiler/Module.hs+22−1 src/Type/Inference.hs+7−6
src/AST/Module.hs+10−1
@@ -1,11 +1,12 @@
11module AST.Module
2− ( Interfaces
2+ ( Interfaces, CanonicalInterfaces
33 , Types, Aliases, ADTs
44 , AdtInfo, CanonicalAdt
55 , SourceModule, ValidModule, CanonicalModule, Optimized
66 , Module(..), Body(..)
77 , Header(..)
88 , Name, nameToString, nameIsNative
9+ , CanonicalName(..), canonPkg, canonModul
910 , Interface(..), toInterface
1011 , UserImport, DefaultImport, ImportMethod(..)
1112 ) where
@@ -29,6 +30,7 @@ import qualified Reporting.Annotation as A
2930-- HELPFUL TYPE ALIASES
3031
3132type Interfaces = Map.Map Name Interface
33+type CanonicalInterfaces = Map.Map CanonicalName Interface
3234
3335type Types = Map.Map String Type.Canonical
3436type Aliases = Map.Map String ([String], Type.Canonical)
@@ -98,6 +100,13 @@ data Header imports = Header
98100type Name = [String] -- must be non-empty
99101
100102
103+data CanonicalName =
104+ CanonicalName
105+ { canonPkg :: Package.Name
106+ , canonModul :: Name
107+ }
108+
109+
101110nameToString :: Name -> String
102111nameToString =
103112 List.intercalate "."
src/Compile.hs+27−6
@@ -17,19 +17,23 @@ import qualified Type.Inference as TI
1717
1818
1919compile
20− :: Package.Name
20+ :: Map.Map Module.Name Package.Name
21+ -> Package.Name
2122 -> Bool
22− -> Module.Interfaces
23+ -> Module.CanonicalInterfaces
2324 -> String
2425 -> Result.Result Warning.Warning Error.Error Module.CanonicalModule
2526
26−compile packageName isRoot interfaces source =
27+compile importedPackages packageName isRoot interfaces source =
2728 do
2829 -- determine if default imports should be added
2930 -- only elm-lang/core is exempt
3031 let needsDefaults =
3132 not (packageName == Package.coreName)
3233
34+ let normalInterfaces =
35+ unCanonicalizeInterfaces importedPackages interfaces
36+
3337 -- Parse the source code
3438 validModule <-
3539 Result.mapError Error.Syntax $
@@ -37,7 +41,7 @@ compile packageName isRoot interfaces source =
3741
3842 -- Canonicalize all variables, pinning down where they came from.
3943 canonicalModule <-
40− Canonicalize.module' interfaces validModule
44+ Canonicalize.module' normalInterfaces validModule
4145
4246 -- Run type inference on the program.
4347 types <-
@@ -48,7 +52,7 @@ compile packageName isRoot interfaces source =
4852 Result.mapError Error.Type $
4953 Nitpick.topLevelTypes types (Module.body validModule)
5054
51− Nitpick.patternMatches interfaces canonicalModule
55+ Nitpick.patternMatches normalInterfaces canonicalModule
5256
5357 -- Add the real list of types
5458 let body = (Module.body canonicalModule) { Module.types = types }
@@ -56,9 +60,26 @@ compile packageName isRoot interfaces source =
5660 return $ canonicalModule { Module.body = body }
5761
5862
59−getOpTable :: Module.Interfaces -> Parse.OpTable
63+getOpTable :: Module.CanonicalInterfaces -> Parse.OpTable
6064getOpTable interfaces =
6165 Map.elems interfaces
6266 |> concatMap Module.iFixities
6367 |> map (\(assoc,lvl,op) -> (op,(lvl,assoc)))
6468 |> 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 =
6363compile
6464 :: Context
6565 -> String
66− -> Map.Map PublicModule.Name PublicModule.Interface
66+ -> Map.Map PublicModule.CanonicalName PublicModule.Interface
6767 -> (Dealiaser, [Warning], Either [Error] Result)
6868
6969compile context source interfaces =
7070 let
71− (Context packageName isRoot isExposed) =
71+ (Context packageName isRoot isExposed modulePackages) =
7272 context
7373
7474 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
7679
7780 (Result.Result (dealiaser, warnings) rawResult) =
78− do modul <- Compile.compile packageName isRoot unwrappedInterfaces source
81+ do modul <- Compile.compile unwrappedPackages packageName isRoot unwrappedInterfaces source
7982 docs <- docsGen isExposed modul
8083
8184 let interface = Module.toInterface modul
@@ -94,6 +97,7 @@ data Context = Context
9497 { _packageName :: Package.Name
9598 , _isRoot :: Bool
9699 , _isExposed :: Bool
100+ , _modulePackages :: Map.Map PublicModule.Name Package.Name
97101 }
98102
99103
src/Elm/Compiler/Module.hs+22−1
@@ -1,5 +1,6 @@
11module Elm.Compiler.Module
2− ( Interface, Name(Name)
2+ ( Interface, Name(Name), name
3+ , CanonicalName(CanonicalName), canonicalName, canonPkg, canonModul, fromCanonicalName
34 , nameToPath
45 , nameToString, nameFromString
56 , hyphenate, dehyphenate
@@ -22,6 +23,7 @@ import qualified AST.Module as Module
2223import qualified Elm.Compiler.Imports as Imports
2324import qualified Elm.Compiler.Type as Type
2425import qualified Elm.Compiler.Type.Extract as Extract
26+import qualified Elm.Package as Package
2527
2628
2729-- EXPOSED TYPES
@@ -32,6 +34,25 @@ type Interface = Module.Interface
3234newtype Name = Name [String]
3335 deriving (Eq, Ord)
3436
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+
3556
3657defaultImports :: [Name]
3758defaultImports =
src/Type/Inference.hs+7−6
@@ -22,7 +22,7 @@ import System.IO.Unsafe
2222
2323
2424infer
25− :: Interfaces
25+ :: CanonicalInterfaces
2626 -> Module.CanonicalModule
2727 -> Except [A.Located Error.Error] (Map.Map String Type.Canonical)
2828infer interfaces modul =
@@ -39,7 +39,7 @@ infer interfaces modul =
3939
4040
4141genConstraints
42− :: Interfaces
42+ :: CanonicalInterfaces
4343 -> Module.CanonicalModule
4444 -> IO (Env.TypeDict, T.TypeConstraint)
4545genConstraints interfaces modul =
@@ -69,15 +69,15 @@ genConstraints interfaces modul =
6969
7070canonicalizeValues
7171 :: Env.Environment
72− -> (Module.Name, Interface)
72+ -> (Module.CanonicalName, Interface)
7373 -> IO [(String, ([T.Variable], T.Type))]
7474canonicalizeValues env (moduleName, iface) =
7575 forM (Map.toList (iTypes iface)) $ \(name,tipe) ->
7676 do tipe' <- Env.instantiateType env tipe Map.empty
77− return (Module.nameToString moduleName ++ "." ++ name, tipe')
77+ return ((Module.nameToString $ Module.canonModul moduleName) ++ "." ++ name, tipe')
7878
7979
80−canonicalizeAdts :: Interfaces -> Module.CanonicalModule -> [CanonicalAdt]
80+canonicalizeAdts :: CanonicalInterfaces -> Module.CanonicalModule -> [CanonicalAdt]
8181canonicalizeAdts interfaces modul =
8282 localAdts ++ importedAdts
8383 where
@@ -85,7 +85,8 @@ canonicalizeAdts interfaces modul =
8585 localAdts = format (Module.names modul, datatypes (body modul))
8686
8787 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)
8990
9091 format :: (Module.Name, Module.ADTs) -> [CanonicalAdt]
9192 format (home, adts) =