on master help sign in
Get rid of current canonicalization code
commiteb96d7ad8d93617a961003730dfe581ed9deef85 authorEvan Czaplicki <info@elm-lang.org> dateMon 29 Jul 2013, 11:53 (13 years ago) parente8ab1c2
2 files changed+2−58
compiler/SourceSyntax/Module.hs−49 compiler/Type/Inference.hs+2−9
compiler/SourceSyntax/Module.hs−49
@@ -50,52 +50,3 @@ data ModuleInterface = ModuleInterface {
5050instance Binary ModuleInterface where
5151 put modul = put (iTypes modul) >> put (iAdts modul) >> put (iAliases modul)
5252 get = ModuleInterface <$> get <*> get <*> get
53−
54−
55−canonicalize :: String -> [ImportMethod] -> ModuleInterface -> ModuleInterface
56−canonicalize prefix importMethods interface =
57− ModuleInterface { iTypes = Map.unions (map iTypes ifaces)
58− , iAdts = concatMap iAdts ifaces
59− , iAliases = concatMap iAliases ifaces }
60− where
61− ifaces = map (canonicalizeHelp prefix interface) importMethods
62−
63−
64−canonicalizeHelp :: String -> ModuleInterface -> ImportMethod -> ModuleInterface
65−canonicalizeHelp prefix interface importMethod =
66− ModuleInterface {
67− iTypes = renameNames $ Map.map (renameType rename) (iTypes interface),
68− iAdts = map renameADT (iAdts interface),
69− iAliases = iAliases interface
70− }
71− where
72− addPrefix name = prefix ++ "." ++ name
73−
74− newName (tipe,_,_) =
75− case importMethod of
76− As name -> (tipe, name ++ "." ++ tipe)
77− Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
78− Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
79− newNames = Map.fromList . map newName $ iAdts interface
80−
81− rename name = Map.findWithDefault name name newNames
82−
83− renameADT (name, tvars, ctors) =
84− (rename name, tvars, map (second (map (renameType rename))) ctors)
85−
86− renameNames tipes =
87− case importMethod of
88− As alias -> Map.mapKeys (\v -> alias ++ "." ++ v) tipes
89− Hiding hidens -> foldr Map.delete tipes hidens
90− Importing visibles ->
91− Map.intersection tipes (Map.fromList [ (v,()) | v <- visibles ])
92−
93−renameType :: (String -> String) -> Type -> Type
94−renameType find tipe =
95− let rnm = renameType find in
96− case tipe of
97− Lambda a b -> Lambda (rnm a) (rnm b)
98− Var x -> Var x
99− Data name ts -> Data (find name) (map rnm ts)
100− EmptyRecord -> EmptyRecord
101− Record fields ext -> Record (map (second rnm) fields) (rnm ext)
compiler/Type/Inference.hs+2−9
@@ -18,15 +18,11 @@ import Control.Arrow (second)
1818import Transform.SortDefinitions as Sort
1919
2020import System.IO.Unsafe -- Possible to switch over to the ST monad instead of
21− -- the IO monad. Not sure if that'd be worthwhile.
21+ -- the IO monad. I don't think that'd be worthwhile.
2222
2323
2424infer :: Interfaces -> MetadataModule t v -> Either [Doc] (Map.Map String T.Variable)
25−infer interfaces' modul = unsafePerformIO $ do
26− let insert (name,method) dict = Map.insertWith (++) name [method] dict
27− localImports = foldr insert Map.empty (imports modul)
28− interfaces = Map.intersectionWithKey Module.canonicalize localImports interfaces'
29−
25+infer interfaces modul = unsafePerformIO $ do
3026 env <- Env.initialEnvironment
3127 (datatypes modul ++ concatMap iAdts (Map.elems interfaces))
3228 (aliases modul ++ concatMap iAliases (Map.elems interfaces))
@@ -34,9 +30,6 @@ infer interfaces' modul = unsafePerformIO $ do
3430 do (_, vars, args, result) <- Env.freshDataScheme env name
3531 return (name, (vars, foldr (T.==>) result args))
3632
37−-- mapM print . Map.toList $ Env.aliases env
38−-- mapM print (imports modul)
39−
4033 importedVars <-
4134 forM (concatMap (Map.toList . iTypes) $ Map.elems interfaces) $ \(name,tipe) ->
4235 (,) name `fmap` Env.instantiateType env tipe Map.empty