@@ -40,7 +40,6 @@ import CodeGen.IL.Optimizer
4040import CodeGen.IL.Printer
4141
4242data DeclType = ModuleDecl | LetDecl | RecLetDecl deriving (Eq)
43−data ImportType = Imported | Ignored
4443
4544-- | Generate code in the simplified intermediate representation for all declarations in a
4645-- module.
@@ -55,9 +54,6 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
5554 do
5655 let usedNames = concatMap getNames decls
5756 let mnLookup = renameImports usedNames imps
58− imports <- traverse (importToIL Imported mnLookup) . (\\ (mn : C.primModules)) . (\\ [mn]) $ ordNub $ map snd imps
59− ignoredImports <- traverse (importToIL Ignored mnLookup) . delete (ModuleName [ProperName C.prim]) . (\\ (mn : C.primModules)) $ ordNub $ map snd imps
60− interfaceImport <- importToIL Imported (renameImports [] [(emptyAnn, mn)]) mn
6157 let decls' = renameModules mnLookup decls
6258 ilDecls <- mapM (bindToIL ModuleDecl) decls'
6359 optimized <- traverse (traverse (optimize modName')) ilDecls
@@ -65,7 +61,8 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
6561 values = annotValue <$> optimized'
6662 foreigns' = moduleIdentToIL <$> foreigns
6763 interface = interfaceSource modName values foreigns
68− implHeader = implHeaderSource modName (imports ++ ignoredImports) interfaceImport
64+ imports = nub . concat $ importToIL <$> optimized'
65+ implHeader = implHeaderSource modName imports ""
6966 implFooter = implFooterSource modName foreigns
7067 return $ (interface, foreigns', optimized', implHeader, implFooter)
7168 where
@@ -104,15 +101,14 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) _ =
104101 then freshModuleName (i + 1) mn' used
105102 else newName
106103
107− -- | Generates IL code for a module import, binding the required module
108− -- to the alternative
109− importToIL :: ImportType -> M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m Text
110− importToIL t mnLookup mn' = do
111− let ((_, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
112− mname = moduleNameToIL mnSafe
113− pure $ case t of
114− Imported -> "import \"" <> mname <> "\"\n"
115− Ignored -> "type _ = " <> mname <> ".IGNORE_UNUSED_IMPORTS\n"
104+ -- | Generates IL code for a module import
105+ --
106+ importToIL :: AST -> [Text]
107+ importToIL = AST.everything (++) modRef
108+ where
109+ modRef (AST.Indexer _ (AST.Var _ _) (AST.Var _ mname))
110+ | not $ T.null mname = [mname]
111+ modRef _ = []
116112
117113 -- | Replaces the `ModuleName`s in the AST so that the generated code refers to
118114 -- the collision-avoiding renamed module imports.