@@ -107,7 +107,7 @@ desugarImports externs modules = do
107 let (_, imps, exps) = fromMaybe (internalError "Module is missing in renameInModule'") $ M.lookup mn env
107 let (_, imps, exps) = fromMaybe (internalError "Module is missing in renameInModule'") $ M.lookup mn env
108 (m', used) <- flip runStateT M.empty $ renameInModule env imps (elaborateExports exps m)
108 (m', used) <- flip runStateT M.empty $ renameInModule env imps (elaborateExports exps m)
109 findUnusedImports m env used
109 findUnusedImports m env used
110− return $ elaborateImports imps m'
110+ return m'
113-- Make all exports for a module explicit. This may still effect modules that
113-- Make all exports for a module explicit. This may still effect modules that
@@ -127,23 +127,6 @@ elaborateExports exps (Module ss coms mn decls refs) =
127 my :: (Exports -> [(a, ModuleName)]) -> [a]
127 my :: (Exports -> [(a, ModuleName)]) -> [a]
128 my f = fst `map` filter ((== mn) . snd) (f exps)
128 my f = fst `map` filter ((== mn) . snd) (f exps)
131−-- Add `import X ()` for any modules where there are only fully qualified references to members.
132−-- This ensures transitive instances are included when using a member from a module.
134−elaborateImports :: Imports -> Module -> Module
135−elaborateImports imps (Module ss coms mn decls exps) = Module ss coms mn decls' exps
137− decls' :: [Declaration]
139− let (f, _, _, _, _) = everythingOnValues (++) (const []) fqValues (const []) (const []) (const [])
140− in mkImport `map` nub (f `concatMap` decls) ++ decls
141− fqValues :: Expr -> [ModuleName]
142− fqValues (Var (Qualified (Just mn') _)) | mn' `notElem` importedModules imps = [mn']
144− mkImport :: ModuleName -> Declaration
145− mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing False
148-- Replaces all local names with qualified names within a module and checks that all existing
131-- Replaces all local names with qualified names within a module and checks that all existing
149-- qualified names are valid.
132-- qualified names are valid.
@@ -171,7 +154,7 @@ renameInModule env imports (Module ss coms mn decls exps) =
171 updateDecl (pos, bound) (ExternDeclaration name ty) =
154 updateDecl (pos, bound) (ExternDeclaration name ty) =
172 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
155 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
173 updateDecl s d = return (s, d)
156 updateDecl s d = return (s, d)
175 updateValue :: (Maybe SourceSpan, [Ident]) -> Expr -> m ((Maybe SourceSpan, [Ident]), Expr)
158 updateValue :: (Maybe SourceSpan, [Ident]) -> Expr -> m ((Maybe SourceSpan, [Ident]), Expr)
176 updateValue (_, bound) v@(PositionedValue pos' _ _) =
159 updateValue (_, bound) v@(PositionedValue pos' _ _) =
177 return ((Just pos', bound), v)
160 return ((Just pos', bound), v)
@@ -192,7 +175,7 @@ renameInModule env imports (Module ss coms mn decls exps) =
192 updateValue s@(pos, _) (TypedValue check val ty) =
175 updateValue s@(pos, _) (TypedValue check val ty) =
193 (,) s <$> (TypedValue check val <$> updateTypesEverywhere pos ty)
176 (,) s <$> (TypedValue check val <$> updateTypesEverywhere pos ty)
194 updateValue s v = return (s, v)
177 updateValue s v = return (s, v)
196 updateBinder :: (Maybe SourceSpan, [Ident]) -> Binder -> m ((Maybe SourceSpan, [Ident]), Binder)
179 updateBinder :: (Maybe SourceSpan, [Ident]) -> Binder -> m ((Maybe SourceSpan, [Ident]), Binder)
197 updateBinder (_, bound) v@(PositionedBinder pos _ _) =
180 updateBinder (_, bound) v@(PositionedBinder pos _ _) =
198 return ((Just pos, bound), v)
181 return ((Just pos, bound), v)
@@ -204,7 +187,7 @@ renameInModule env imports (Module ss coms mn decls exps) =
204 return (s', TypedBinder t' b')
187 return (s', TypedBinder t' b')
205 updateBinder s v =
188 updateBinder s v =
206 return (s, v)
189 return (s, v)
208 updateCase :: (Maybe SourceSpan, [Ident]) -> CaseAlternative -> m ((Maybe SourceSpan, [Ident]), CaseAlternative)
191 updateCase :: (Maybe SourceSpan, [Ident]) -> CaseAlternative -> m ((Maybe SourceSpan, [Ident]), CaseAlternative)
209 updateCase (pos, bound) c@(CaseAlternative bs _) =
192 updateCase (pos, bound) c@(CaseAlternative bs _) =
210 return ((pos, concatMap binderNames bs ++ bound), c)
193 return ((pos, concatMap binderNames bs ++ bound), c)