X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FId.lhs;h=b1a4a1a5d7223b210f7574524b603a3b23f600c8;hb=7d841483081735f5f906a6bb5e80249d97f3226b;hp=b21292005f7a4f7d0fe8f89f099269a0766a5d63;hpb=713b32a591db467a8e9e266ffa3a3bf453b7d4c3;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/Id.lhs b/ghc/compiler/basicTypes/Id.lhs index b212920..b1a4a1a 100644 --- a/ghc/compiler/basicTypes/Id.lhs +++ b/ghc/compiler/basicTypes/Id.lhs @@ -44,37 +44,45 @@ module Id ( -- IdInfo stuff setIdUnfolding, setIdArity, - setIdDemandInfo, setIdNewDemandInfo, - setIdStrictness, setIdNewStrictness, zapIdNewStrictness, + setIdNewDemandInfo, + setIdNewStrictness, zapIdNewStrictness, setIdTyGenInfo, setIdWorkerInfo, setIdSpecialisation, setIdCgInfo, - setIdCprInfo, setIdOccInfo, +#ifdef OLD_STRICTNESS + idDemandInfo, + idStrictness, + idCprInfo, + setIdStrictness, + setIdDemandInfo, + setIdCprInfo, +#endif + idArity, - idDemandInfo, idNewDemandInfo, - idStrictness, idNewStrictness, idNewStrictness_maybe, getNewStrictness, + idNewDemandInfo, + idNewStrictness, idNewStrictness_maybe, idTyGenInfo, idWorkerInfo, idUnfolding, - idSpecialisation, + idSpecialisation, idCoreRules, idCgInfo, idCafInfo, - idCgArity, - idCprInfo, idLBVarInfo, idOccInfo, +#ifdef OLD_STRICTNESS newStrictnessFromOld -- Temporary +#endif ) where #include "HsVersions.h" -import CoreSyn ( Unfolding, CoreRules ) +import CoreSyn ( Unfolding, CoreRules, IdCoreRule, rulesRules ) import BasicTypes ( Arity ) import Var ( Id, DictId, isId, isExportedId, isSpecPragmaId, isLocalId, @@ -91,14 +99,12 @@ import Type ( Type, typePrimRep, addFreeTyVars, import IdInfo import qualified Demand ( Demand ) -import NewDemand ( Demand, DmdResult(..), StrictSig, topSig, isBotRes, - isBottomingSig, splitStrictSig, strictSigResInfo - ) +import NewDemand ( Demand, StrictSig, topSig, isBottomingSig ) import Name ( Name, OccName, - mkSysLocalName, mkLocalName, + mkSystemName, mkInternalName, getOccName, getSrcLoc ) -import OccName ( UserFS, mkWorkerOcc ) +import OccName ( EncodedFS, UserFS, mkWorkerOcc ) import PrimRep ( PrimRep ) import TysPrim ( statePrimTyCon ) import FieldLabel ( FieldLabel ) @@ -107,20 +113,21 @@ import SrcLoc ( SrcLoc ) import Outputable import Unique ( Unique, mkBuiltinUnique ) +-- infixl so you can say (id `set` a `set` b) infixl 1 `setIdUnfolding`, `setIdArity`, - `setIdDemandInfo`, - `setIdStrictness`, `setIdNewDemandInfo`, `setIdNewStrictness`, `setIdTyGenInfo`, `setIdWorkerInfo`, `setIdSpecialisation`, `setInlinePragma`, - `idCafInfo`, - `idCprInfo` - - -- infixl so you can say (id `set` a `set` b) + `idCafInfo` +#ifdef OLD_STRICTNESS + ,`idCprInfo` + ,`setIdStrictness` + ,`setIdDemandInfo` +#endif \end{code} @@ -139,10 +146,8 @@ where it can easily be found. mkLocalIdWithInfo :: Name -> Type -> IdInfo -> Id mkLocalIdWithInfo name ty info = Var.mkLocalId name (addFreeTyVars ty) info -mkSpecPragmaId :: OccName -> Unique -> Type -> SrcLoc -> Id -mkSpecPragmaId occ uniq ty loc = Var.mkSpecPragmaId (mkLocalName uniq occ loc) - (addFreeTyVars ty) - vanillaIdInfo +mkSpecPragmaId :: Name -> Type -> Id +mkSpecPragmaId name ty = Var.mkSpecPragmaId name (addFreeTyVars ty) vanillaIdInfo mkGlobalId :: GlobalIdDetails -> Name -> Type -> IdInfo -> Id mkGlobalId details name ty info = Var.mkGlobalId details name (addFreeTyVars ty) info @@ -155,11 +160,13 @@ mkLocalId name ty = mkLocalIdWithInfo name ty vanillaIdInfo -- SysLocal: for an Id being created by the compiler out of thin air... -- UserLocal: an Id with a name the user might recognize... mkUserLocal :: OccName -> Unique -> Type -> SrcLoc -> Id -mkSysLocal :: UserFS -> Unique -> Type -> Id +mkSysLocal :: EncodedFS -> Unique -> Type -> Id mkVanillaGlobal :: Name -> Type -> IdInfo -> Id -mkSysLocal fs uniq ty = mkLocalId (mkSysLocalName uniq fs) ty -mkUserLocal occ uniq ty loc = mkLocalId (mkLocalName uniq occ loc) ty +-- for SysLocal, we assume the base name is already encoded, to avoid +-- re-encoding the same string over and over again. +mkSysLocal fs uniq ty = mkLocalId (mkSystemName uniq fs) ty +mkUserLocal occ uniq ty loc = mkLocalId (mkInternalName uniq occ loc) ty mkVanillaGlobal = mkGlobalId VanillaGlobal \end{code} @@ -170,14 +177,14 @@ instantiated before use. \begin{code} -- "Wild Id" typically used when you need a binder that you don't expect to use mkWildId :: Type -> Id -mkWildId ty = mkSysLocal SLIT("wild") (mkBuiltinUnique 1) ty +mkWildId ty = mkSysLocal FSLIT("wild") (mkBuiltinUnique 1) ty mkWorkerId :: Unique -> Id -> Type -> Id --- A worker gets a local name. CoreTidy will globalise it if necessary. +-- A worker gets a local name. CoreTidy will externalise it if necessary. mkWorkerId uniq unwrkr ty = mkLocalId wkr_name ty where - wkr_name = mkLocalName uniq (mkWorkerOcc (getOccName unwrkr)) (getSrcLoc unwrkr) + wkr_name = mkInternalName uniq (mkWorkerOcc (getOccName unwrkr)) (getSrcLoc unwrkr) -- "Template locals" typically used in unfoldings mkTemplateLocals :: [Type] -> [Id] @@ -188,7 +195,7 @@ mkTemplateLocalsNum :: Int -> [Type] -> [Id] mkTemplateLocalsNum n tys = zipWith mkTemplateLocal [n..] tys mkTemplateLocal :: Int -> Type -> Id -mkTemplateLocal i ty = mkSysLocal SLIT("tpl") (mkBuiltinUnique i) ty +mkTemplateLocal i ty = mkSysLocal FSLIT("tpl") (mkBuiltinUnique i) ty \end{code} @@ -266,11 +273,12 @@ isDataConWrapId id = case globalIdDetails id of DataConWrapId con -> True other -> False - -- hasNoBinding returns True of an Id which may not have a - -- binding, even though it is defined in this module. Notably, - -- the constructors of a dictionary are in this situation. +-- hasNoBinding returns True of an Id which may not have a +-- binding, even though it is defined in this module. +-- Data constructor workers used to be things of this kind, but +-- they aren't any more. Instead, we inject a binding for +-- them at the CorePrep stage. hasNoBinding id = case globalIdDetails id of - DataConId _ -> True PrimOpId _ -> True FCallId _ -> True other -> False @@ -315,17 +323,15 @@ idArity id = arityInfo (idInfo id) setIdArity :: Id -> Arity -> Id setIdArity id arity = modifyIdInfo (`setArityInfo` arity) id +#ifdef OLD_STRICTNESS --------------------------------- - -- STRICTNESS + -- (OLD) STRICTNESS idStrictness :: Id -> StrictnessInfo -idStrictness id = case strictnessInfo (idInfo id) of - NoStrictnessInfo -> case idNewStrictness_maybe id of - Just sig -> oldStrictnessFromNew sig - Nothing -> NoStrictnessInfo - strictness -> strictness +idStrictness id = strictnessInfo (idInfo id) setIdStrictness :: Id -> StrictnessInfo -> Id setIdStrictness id strict_info = modifyIdInfo (`setStrictnessInfo` strict_info) id +#endif -- isBottomingId returns true if an application to n args would diverge isBottomingId :: Id -> Bool @@ -337,20 +343,6 @@ idNewStrictness :: Id -> StrictSig idNewStrictness_maybe id = newStrictnessInfo (idInfo id) idNewStrictness id = idNewStrictness_maybe id `orElse` topSig -getNewStrictness :: Id -> StrictSig --- First tries the "new-strictness" field, and then --- reverts to the old one. This is just until we have --- cross-module info for new strictness -getNewStrictness id = idNewStrictness_maybe id `orElse` newStrictnessFromOld id - -newStrictnessFromOld :: Id -> StrictSig -newStrictnessFromOld id = mkNewStrictnessInfo id (idArity id) (idStrictness id) (idCprInfo id) - -oldStrictnessFromNew :: StrictSig -> StrictnessInfo -oldStrictnessFromNew sig = mkStrictnessInfo (map oldDemand dmds, isBotRes res_info) - where - (dmds, res_info) = splitStrictSig sig - setIdNewStrictness :: Id -> StrictSig -> Id setIdNewStrictness id sig = modifyIdInfo (`setNewStrictnessInfo` Just sig) id @@ -381,13 +373,15 @@ idUnfolding id = unfoldingInfo (idInfo id) setIdUnfolding :: Id -> Unfolding -> Id setIdUnfolding id unfolding = modifyIdInfo (`setUnfoldingInfo` unfolding) id +#ifdef OLD_STRICTNESS --------------------------------- - -- DEMAND + -- (OLD) DEMAND idDemandInfo :: Id -> Demand.Demand idDemandInfo id = demandInfo (idInfo id) setIdDemandInfo :: Id -> Demand.Demand -> Id setIdDemandInfo id demand_info = modifyIdInfo (`setDemandInfo` demand_info) id +#endif idNewDemandInfo :: Id -> NewDemand.Demand idNewDemandInfo id = newDemandInfo (idInfo id) @@ -400,13 +394,16 @@ setIdNewDemandInfo id dmd = modifyIdInfo (`setNewDemandInfo` dmd) id idSpecialisation :: Id -> CoreRules idSpecialisation id = specInfo (idInfo id) +idCoreRules :: Id -> [IdCoreRule] +idCoreRules id = [(id,rule) | rule <- rulesRules (idSpecialisation id)] + setIdSpecialisation :: Id -> CoreRules -> Id setIdSpecialisation id spec_info = modifyIdInfo (`setSpecInfo` spec_info) id --------------------------------- -- CG INFO idCgInfo :: Id -> CgInfo -#ifdef DEBUG +#ifdef OLD_STRICTNESS idCgInfo id = case cgInfo (idInfo id) of NoCgInfo -> pprPanic "idCgInfo" (ppr id) info -> info @@ -420,36 +417,22 @@ setIdCgInfo id cg_info = modifyIdInfo (`setCgInfo` cg_info) id --------------------------------- -- CAF INFO idCafInfo :: Id -> CafInfo -#ifdef DEBUG +#ifdef OLD_STRICTNESS idCafInfo id = case cgInfo (idInfo id) of NoCgInfo -> pprPanic "idCafInfo" (ppr id) info -> cgCafInfo info #else idCafInfo id = cgCafInfo (idCgInfo id) #endif - - --------------------------------- - -- CG ARITY -idCgArity :: Id -> Arity -#ifdef DEBUG -idCgArity id = case cgInfo (idInfo id) of - NoCgInfo -> pprPanic "idCgArity" (ppr id) - info -> cgArity info -#else -idCgArity id = cgArity (idCgInfo id) -#endif - --------------------------------- -- CPR INFO +#ifdef OLD_STRICTNESS idCprInfo :: Id -> CprInfo -idCprInfo id = case cprInfo (idInfo id) of - NoCPRInfo -> case strictSigResInfo (idNewStrictness id) of - RetCPR -> ReturnsCPR - other -> NoCPRInfo - ReturnsCPR -> ReturnsCPR +idCprInfo id = cprInfo (idInfo id) setIdCprInfo :: Id -> CprInfo -> Id setIdCprInfo id cpr_info = modifyIdInfo (`setCprInfo` cpr_info) id +#endif --------------------------------- -- Occcurrence INFO