From 8fc898cb0b722e72c08dce3acadbc4b2aa2249ff Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 30 Oct 2003 09:03:16 +0000 Subject: [PATCH] [project @ 2003-10-30 09:03:15 by simonpj] Remove redundant param from allUses --- ghc/compiler/basicTypes/NameSet.lhs | 34 ++++++++++++++++++---------------- ghc/compiler/deSugar/Desugar.lhs | 2 +- ghc/compiler/rename/RnBinds.lhs | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ghc/compiler/basicTypes/NameSet.lhs b/ghc/compiler/basicTypes/NameSet.lhs index 305e80d..4474391 100644 --- a/ghc/compiler/basicTypes/NameSet.lhs +++ b/ghc/compiler/basicTypes/NameSet.lhs @@ -145,9 +145,23 @@ mkDUs pairs = [(Just defs, uses) | (defs,uses) <- pairs] plusDU :: DefUses -> DefUses -> DefUses plusDU = (++) -allUses :: DefUses -> Uses -> Uses --- Collect all uses, removing defs -allUses dus uses +duDefs :: DefUses -> Defs +duDefs dus = foldr get emptyNameSet dus + where + get (Nothing, u1) d2 = d2 + get (Just d1, u1) d2 = d1 `unionNameSets` d2 + +duUses :: DefUses -> Uses +-- Just like allUses, but defs are not eliminated +duUses dus = foldr get emptyNameSet dus + where + get (d1, u1) u2 = u1 `unionNameSets` u2 + +allUses :: DefUses -> Uses +-- Collect all uses, regardless of +-- whether the group is itself used, +-- but remove defs on the way +allUses dus = foldr get emptyNameSet dus where get (Nothing, rhs_uses) uses = rhs_uses `unionNameSets` uses @@ -159,7 +173,7 @@ findUses :: DefUses -> Uses -> Uses -- find all the uses, transitively. -- The result is a superset of the input uses; -- and includes things defined in the input DefUses --- (if they are used, of course) +-- (but only if they are used) findUses dus uses = foldr get uses dus where @@ -170,16 +184,4 @@ findUses dus uses = rhs_uses `unionNameSets` uses | otherwise -- No def is used = uses - -duDefs :: DefUses -> Defs -duDefs dus = foldr get emptyNameSet dus - where - get (Nothing, u1) d2 = d2 - get (Just d1, u1) d2 = d1 `unionNameSets` d2 - -duUses :: DefUses -> Uses --- Defs are not eliminated -duUses dus = foldr get emptyNameSet dus - where - get (d1, u1) u2 = u1 `unionNameSets` u2 \end{code} \ No newline at end of file diff --git a/ghc/compiler/deSugar/Desugar.lhs b/ghc/compiler/deSugar/Desugar.lhs index c2bfd69..153cc1a 100644 --- a/ghc/compiler/deSugar/Desugar.lhs +++ b/ghc/compiler/deSugar/Desugar.lhs @@ -96,7 +96,7 @@ deSugar hsc_env (printDump (ppr_ds_rules ds_rules)) ; dfun_uses <- readIORef dfun_uses_var -- What dfuns are used - ; let used_names = allUses dus emptyNameSet `unionNameSets` dfun_uses + ; let used_names = allUses dus `unionNameSets` dfun_uses ; usages <- mkUsageInfo hsc_env imports used_names ; let deps = Deps { dep_mods = moduleEnvElts (imp_dep_mods imports), diff --git a/ghc/compiler/rename/RnBinds.lhs b/ghc/compiler/rename/RnBinds.lhs index 3a72f3f..9f7e690 100644 --- a/ghc/compiler/rename/RnBinds.lhs +++ b/ghc/compiler/rename/RnBinds.lhs @@ -205,10 +205,10 @@ rnMonoBindsAndThen mbinds sigs thing_inside -- Non-empty monobinds warnUnusedLocalBinds unused_bndrs `thenM_` returnM (result, all_uses `minusNameSet` bndrs) - -- It's important to return all the uses, not the 'real uses' used for + -- duUses: It's important to return all the uses, not the 'real uses' used for -- warning about unused bindings. Otherwise consider: -- x = 3 - -- y = let p = x in 'x' + -- y = let p = x in 'x' -- NB: p not used -- If we don't "see" the dependency of 'y' on 'x', we may put the -- bindings in the wrong order, and the type checker will complain -- that x isn't in scope -- 1.7.10.4