{-# OPTIONS -fno-warn-tabs #-}-- The above warning supression flag is a temporary kludge.-- While working on this module you are encouraged to remove it and-- detab the module (please do the detabbing in a separate patch). See-- http://ghc.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces-- for detailsmoduleNameSet(-- * Names set typeNameSet,-- ** Manipulating these setsemptyNameSet,unitNameSet,mkNameSet,unionNameSets,unionManyNameSets,minusNameSet,elemNameSet,nameSetToList,addOneToNameSet,addListToNameSet,delFromNameSet,delListFromNameSet,isEmptyNameSet,foldNameSet,filterNameSet,intersectsNameSet,intersectNameSet,-- * Free variablesFreeVars,-- ** Manipulating sets of free variablesisEmptyFVs,emptyFVs,plusFVs,plusFV,mkFVs,addOneFV,unitFV,delFV,delFVs,-- * Defs and usesDefs,Uses,DefUse,DefUses,-- ** Manipulating defs and usesemptyDUs,usesOnly,mkDUs,plusDU,findUses,duDefs,duUses,allUses)where#include "HsVersions.h"importNameimportUniqSet

-- | A set of names that are defined somewheretypeDefs=NameSet-- | A set of names that are used somewheretypeUses=NameSet-- | @(Just ds, us) =>@ The use of any member of the @ds@-- implies that all the @us@ are used too.-- Also, @us@ may mention @ds@.---- @Nothing =>@ Nothing is defined in this group, but-- nevertheless all the uses are essential.-- Used for instance declarations, for exampletypeDefUse=(MaybeDefs,Uses)-- | A number of 'DefUse's in dependency order: earlier 'Defs' scope over later 'Uses'-- In a single (def, use) pair, the defs also scope over the usestypeDefUses=[DefUse]emptyDUs::DefUsesemptyDUs=[]usesOnly::Uses->DefUsesusesOnlyuses=[(Nothing,uses)]mkDUs::[(Defs,Uses)]->DefUsesmkDUspairs=[(Justdefs,uses)|(defs,uses)<-pairs]plusDU::DefUses->DefUses->DefUsesplusDU=(++)duDefs::DefUses->DefsduDefsdus=foldrgetemptyNameSetduswhereget(Nothing,_u1)d2=d2get(Justd1,_u1)d2=d1`unionNameSets`d2allUses::DefUses->Uses-- ^ Just like 'duUses', but 'Defs' are not eliminated from the 'Uses' returnedallUsesdus=foldrgetemptyNameSetduswhereget(_d1,u1)u2=u1`unionNameSets`u2duUses::DefUses->Uses-- ^ Collect all 'Uses', regardless of whether the group is itself used,-- but remove 'Defs' on the wayduUsesdus=foldrgetemptyNameSetduswhereget(Nothing,rhs_uses)uses=rhs_uses`unionNameSets`usesget(Justdefs,rhs_uses)uses=(rhs_uses`unionNameSets`uses)`minusNameSet`defsfindUses::DefUses->Uses->Uses-- ^ Given some 'DefUses' and some 'Uses', find all the uses, transitively.-- The result is a superset of the input 'Uses'; and includes things defined -- in the input 'DefUses' (but only if they are used)findUsesdususes=foldrgetusesduswhereget(Nothing,rhs_uses)uses=rhs_uses`unionNameSets`usesget(Justdefs,rhs_uses)uses|defs`intersectsNameSet`uses-- Used||any(startsWithUnderscore.nameOccName)(nameSetToListdefs)-- At least one starts with an "_", -- so treat the group as used=rhs_uses`unionNameSets`uses|otherwise-- No def is used=uses