Skip to content

Instantly share code, notes, and snippets.

@JoeyEremondi
Last active August 26, 2015 21:41
Show Gist options
  • Save JoeyEremondi/90e84eb1565281ab9a7d to your computer and use it in GitHub Desktop.
Save JoeyEremondi/90e84eb1565281ab9a7d to your computer and use it in GitHub Desktop.
Changes to elm-make and elm-compiler to allow for name conflicts

elm-make

Pipeline.Compiler

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).

Original code

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.

Original Code

buildModule
    :: Env
    -> Map.Map CanonicalModule Module.Interface
    -> [CanonicalModule]
    -> (CanonicalModule, Location)
    -> IO ()

elm-compiler

Elm.Compiler.Package

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

Elm.Compiler

In the context, we store a map from imported Module names to the packages we import those modules from.

Original Code

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)

Compile.hs

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.

Original source

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

elm-package

Elm.Package.Name

Since we moved the package Name type to elm-compiler, the API defined here is reduced.

Original code

type Name = CN.Name


dummyName :: Name


toUrl :: Name -> String


toFilePath :: Name -> FilePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment