@@ -26,6 +26,8 @@ import Data.List (nub, intersect)
26import Data.Maybe (isJust, mapMaybe)
26import Data.Maybe (isJust, mapMaybe)
27import Control.Applicative ((<$>), (<*>), pure)
27import Control.Applicative ((<$>), (<*>), pure)
29+import qualified Data.Set as S
29import Language.PureScript.Declarations
31import Language.PureScript.Declarations
30import Language.PureScript.Names
32import Language.PureScript.Names
31import Language.PureScript.Types
33import Language.PureScript.Types
@@ -91,13 +93,19 @@ collapseBindingGroupsForValue other = other
92usedIdents :: ModuleName -> Declaration -> [Ident]
94usedIdents :: ModuleName -> Declaration -> [Ident]
93usedIdents moduleName =
95usedIdents moduleName =
94− let (f, _, _, _, _) = everythingOnValues (++) (const []) usedNames (const []) (const []) (const [])
96+ let (f, _, _, _, _) = everythingWithContextOnValues S.empty [] (++) def usedNamesE usedNamesB def def
95 in nub . f
97 in nub . f
97− usedNames :: Expr -> [Ident]
99+ def s _ = (s, [])
101+ usedNamesE :: S.Set Ident -> Expr -> (S.Set Ident, [Ident])
98− usedNames (Var (Qualified Nothing name)) = [name]
102+ usedNamesE scope (Var (Qualified Nothing name)) | name `S.notMember` scope = (scope, [name])
99− usedNames (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
103+ usedNamesE scope (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' && name `S.notMember` scope = (scope, [name])
100− usedNames _ = []
104+ usedNamesE scope (Abs (Left name) _) = (name `S.insert` scope, [])
105+ usedNamesE scope _ = (scope, [])
107+ usedNamesB :: S.Set Ident -> Binder -> (S.Set Ident, [Ident])
108+ usedNamesB scope binder = (scope `S.union` S.fromList (binderNames binder), [])
102usedProperNames :: ModuleName -> Declaration -> [ProperName]
110usedProperNames :: ModuleName -> Declaration -> [ProperName]
103usedProperNames moduleName =
111usedProperNames moduleName =