@@ -36,7 +36,7 @@ import Language.PureScript.Types
36-- Replace all sets of mutually-recursive declarations in a module with binding groups
36-- Replace all sets of mutually-recursive declarations in a module with binding groups
38createBindingGroupsModule :: [Module] -> Either String [Module]
38createBindingGroupsModule :: [Module] -> Either String [Module]
39−createBindingGroupsModule = mapM $ \(Module name ds) -> Module name <$> createBindingGroups ds
39+createBindingGroupsModule = mapM $ \(Module name ds) -> Module name <$> createBindingGroups (ModuleName name) ds
42-- Collapse all binding groups in a module to individual declarations
42-- Collapse all binding groups in a module to individual declarations
@@ -47,15 +47,15 @@ collapseBindingGroupsModule = map $ \(Module name ds) -> Module name (collapseBi
48-- Replace all sets of mutually-recursive declarations with binding groups
48-- Replace all sets of mutually-recursive declarations with binding groups
50−createBindingGroups :: [Declaration] -> Either String [Declaration]
50+createBindingGroups :: ModuleName -> [Declaration] -> Either String [Declaration]
51−createBindingGroups ds = do
51+createBindingGroups moduleName ds = do
52 let values = filter isValueDecl ds
52 let values = filter isValueDecl ds
53 dataDecls = filter isDataDecl ds
53 dataDecls = filter isDataDecl ds
54 allProperNames = map getProperName dataDecls
54 allProperNames = map getProperName dataDecls
55 dataVerts = map (\d -> (d, getProperName d, usedProperNames d `intersect` allProperNames)) dataDecls
55 dataVerts = map (\d -> (d, getProperName d, usedProperNames d `intersect` allProperNames)) dataDecls
56 dataBindingGroupDecls <- mapM toDataBindingGroup $ stronglyConnComp dataVerts
56 dataBindingGroupDecls <- mapM toDataBindingGroup $ stronglyConnComp dataVerts
57 let allIdents = map getIdent values
57 let allIdents = map getIdent values
58− valueVerts = map (\d -> (d, getIdent d, usedIdents d `intersect` allIdents)) values
58+ valueVerts = map (\d -> (d, getIdent d, usedIdents moduleName d `intersect` allIdents)) values
59 bindingGroupDecls = map toBindingGroup $ stronglyConnComp valueVerts
59 bindingGroupDecls = map toBindingGroup $ stronglyConnComp valueVerts
60 return $ filter isImportDecl ds ++
60 return $ filter isImportDecl ds ++
61 filter isExternDataDecl ds ++
61 filter isExternDataDecl ds ++
@@ -75,11 +75,12 @@ collapseBindingGroups ds = concatMap go ds
75 go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
75 go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
76 go other = [other]
76 go other = [other]
78−usedIdents :: (Data d) => d -> [Ident]
78+usedIdents :: (Data d) => ModuleName -> d -> [Ident]
79−usedIdents = nub . everything (++) (mkQ [] names)
79+usedIdents moduleName = nub . everything (++) (mkQ [] names)
81 names :: Value -> [Ident]
81 names :: Value -> [Ident]
82 names (Var (Qualified Nothing name)) = [name]
82 names (Var (Qualified Nothing name)) = [name]
83+ names (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
83 names _ = []
84 names _ = []
85usedProperNames :: (Data d) => d -> [ProperName]
86usedProperNames :: (Data d) => d -> [ProperName]