We add the non-reversed dependencies to the environment. (We already have the dependencies. The original version stores only the reversed version, so our change stores both).
data Env = Env
{ maxActiveThreads :: Int
-- ...
, dependencies :: Map.Map CanonicalModule [CanonicalModule]
, reverseDependencies :: Map.Map CanonicalModule [CanonicalModule]
-- ...
}
BuildModule gets the list of dependencies for this module. This is enough, since CanonicalModule stores the package name.
buildModule
:: Env
-> Map.Map CanonicalModule Module.Interface
-> [CanonicalModule]
-> (CanonicalModule, Location)
-> IO ()
We move the Package Name type into elm-compiler, so we can use it throughout for storing package names.
data Name = Name
{ user :: String
, project :: String
}
deriving (Eq, Ord, Show)
toString :: Name -> String
fromString :: String -> Maybe Name
fromString' :: (MonadError String m) => String -> m Name
instance Binary Name where
instance FromJSON Name where
instance ToJSON Name where
toJSON name =
toJSON (toString name)
errorMsg :: String -> String
In the context, we store a map from imported Module names to the packages we import those modules from.
data Context = Context
{ _user :: String
, _packageName :: String
, _isRoot :: Bool
, _isExposed :: Bool
, _modulePackages :: Map.Map PublicModule.Name Elm.Compiler.Package.Name
}
Our compile function then takes in a list of interfaces
compile
:: Context
-> String
-> Map.Map PublicModule.Name [PublicModule.Interface]
-> (Dealiaser, [Warning], Either [Error] Result)
We take the map of modules to their packagesas an argument.
In this function, we'll filter out non-imported interfaces when we call Canonicalize.module', but not when we call the typechecker.
compile
:: String
-> String
-> Bool
-> Map.Map PublicModule.Name Elm.Compiler.Package.Name
-> Module.Interfaces
-> String
-> Result.Result Warning.Warning Error.Error Module.CanonicalModule
filterImportedInterfaces
:: Map.Map PublicModule.Name Elm.Compiler.Package.Name
-> Module.Interfaces
-> Module.Interfaces
Since we moved the package Name
type to elm-compiler,
the API defined here is reduced.
type Name = CN.Name
dummyName :: Name
toUrl :: Name -> String
toFilePath :: Name -> FilePath