This goes with the patch for #1839, #1463
[ghc-hetmet.git] / compiler / basicTypes / Id.lhs
index edaeb7a..7ae75da 100644 (file)
@@ -5,6 +5,13 @@
 \section[Id]{@Ids@: Value and constructor identifiers}
 
 \begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module Id (
        Id, DictId,
 
@@ -22,10 +29,10 @@ module Id (
        -- Modifying an Id
        setIdName, setIdUnique, Id.setIdType, setIdExported, setIdNotExported, 
        setIdInfo, lazySetIdInfo, modifyIdInfo, maybeModifyIdInfo,
-       zapLamIdInfo, zapDemandIdInfo, 
+       zapLamIdInfo, zapDemandIdInfo, zapFragileIdInfo,
 
        -- Predicates
-       isImplicitId, isDeadBinder, isDictId,
+       isImplicitId, isDeadBinder, isDictId, isStrictId,
        isExportedId, isLocalId, isGlobalId,
        isRecordSelector, isNaughtyRecordSelector,
        isClassOpId_maybe,
@@ -33,6 +40,7 @@ module Id (
        isFCallId, isFCallId_maybe,
        isDataConWorkId, isDataConWorkId_maybe, isDataConId_maybe, idDataCon,
        isBottomingId, idIsFrom,
+        isTickBoxOp, isTickBoxOp_maybe,
        hasNoBinding, 
 
        -- Inline pragma stuff
@@ -153,7 +161,7 @@ mkSysLocal fs uniq ty = mkLocalId (mkSystemVarName uniq fs) ty
 
 
 -- UserLocal: an Id with a name the user might recognize...
-mkUserLocal :: OccName -> Unique -> Type -> SrcLoc -> Id
+mkUserLocal :: OccName -> Unique -> Type -> SrcSpan -> Id
 mkVanillaGlobal :: Name -> Type -> IdInfo -> Id
 
 mkUserLocal occ uniq ty loc = mkLocalId (mkInternalName    uniq occ loc) ty
@@ -174,7 +182,7 @@ mkWorkerId :: Unique -> Id -> Type -> Id
 mkWorkerId uniq unwrkr ty
   = mkLocalId wkr_name ty
   where
-    wkr_name = mkInternalName uniq (mkWorkerOcc (getOccName unwrkr)) (getSrcLoc unwrkr)
+    wkr_name = mkInternalName uniq (mkWorkerOcc (getOccName unwrkr)) (getSrcSpan unwrkr)
 
 -- "Template locals" typically used in unfoldings
 mkTemplateLocals :: [Type] -> [Id]
@@ -213,9 +221,10 @@ idPrimRep id = typePrimRep (idType id)
 
 \begin{code}
 recordSelectorFieldLabel :: Id -> (TyCon, FieldLabel)
-recordSelectorFieldLabel id = case globalIdDetails id of
-                                RecordSelId tycon lbl _ -> (tycon,lbl)
-                                other -> panic "recordSelectorFieldLabel"
+recordSelectorFieldLabel id
+  = case globalIdDetails id of
+       RecordSelId { sel_tycon = tycon, sel_label = lbl } -> (tycon,lbl)
+       other -> panic "recordSelectorFieldLabel"
 
 isRecordSelector id = case globalIdDetails id of
                        RecordSelId {}  -> True
@@ -280,7 +289,7 @@ isDictId id = isDictTy (idType id)
 -- them at the CorePrep stage. 
 -- EXCEPT: unboxed tuples, which definitely have no binding
 hasNoBinding id = case globalIdDetails id of
-                       PrimOpId _       -> True
+                       PrimOpId _       -> True        -- See Note [Primop wrappers]
                        FCallId _        -> True
                        DataConWorkId dc -> isUnboxedTupleCon dc
                        other            -> False
@@ -307,12 +316,40 @@ idIsFrom :: Module -> Id -> Bool
 idIsFrom mod id = nameIsLocalOrFrom mod (idName id)
 \end{code}
 
+Note [Primop wrappers]
+~~~~~~~~~~~~~~~~~~~~~~
+Currently hasNoBinding claims that PrimOpIds don't have a curried
+function definition.  But actually they do, in GHC.PrimopWrappers,
+which is auto-generated from prelude/primops.txt.pp.  So actually, hasNoBinding
+could return 'False' for PrimOpIds.
+
+But we'd need to add something in CoreToStg to swizzle any unsaturated
+applications of GHC.Prim.plusInt# to GHC.PrimopWrappers.plusInt#.
+
+Nota Bene: GHC.PrimopWrappers is needed *regardless*, because it's
+used by GHCi, which does not implement primops direct at all.
+
+
+
 \begin{code}
 isDeadBinder :: Id -> Bool
 isDeadBinder bndr | isId bndr = isDeadOcc (idOccInfo bndr)
                  | otherwise = False   -- TyVars count as not dead
 \end{code}
 
+\begin{code}
+isTickBoxOp :: Id -> Bool
+isTickBoxOp id = 
+  case globalIdDetails id of
+    TickBoxOpId tick -> True
+    _                -> False
+
+isTickBoxOp_maybe :: Id -> Maybe TickBoxOp
+isTickBoxOp_maybe id = 
+  case globalIdDetails id of
+    TickBoxOpId tick -> Just tick
+    _                -> Nothing
+\end{code}
 
 %************************************************************************
 %*                                                                     *
@@ -354,6 +391,20 @@ setIdNewStrictness id sig = modifyIdInfo (`setNewStrictnessInfo` Just sig) id
 
 zapIdNewStrictness :: Id -> Id
 zapIdNewStrictness id = modifyIdInfo (`setNewStrictnessInfo` Nothing) id
+\end{code}
+
+This predicate says whether the id has a strict demand placed on it or
+has a type such that it can always be evaluated strictly (e.g., an
+unlifted type, but see the comment for isStrictType).  We need to
+check separately whether <id> has a so-called "strict type" because if
+the demand for <id> hasn't been computed yet but <id> has a strict
+type, we still want (isStrictId <id>) to be True.
+\begin{code}
+isStrictId :: Id -> Bool
+isStrictId id
+  = ASSERT2( isId id, text "isStrictId: not an id: " <+> ppr id )
+           (isStrictDmd (idNewDemandInfo id)) || 
+           (isStrictType (idType id))
 
        ---------------------------------
        -- WORKER ID
@@ -513,9 +564,15 @@ clearOneShotLambda id
 \end{code}
 
 \begin{code}
+zapInfo :: (IdInfo -> Maybe IdInfo) -> Id -> Id
+zapInfo zapper id = maybeModifyIdInfo (zapper (idInfo id)) id
+
 zapLamIdInfo :: Id -> Id
-zapLamIdInfo id = maybeModifyIdInfo (zapLamInfo (idInfo id)) id
+zapLamIdInfo = zapInfo zapLamInfo
+
+zapDemandIdInfo = zapInfo zapDemandInfo
 
-zapDemandIdInfo id = maybeModifyIdInfo (zapDemandInfo (idInfo id)) id
+zapFragileIdInfo :: Id -> Id
+zapFragileIdInfo = zapInfo zapFragileInfo 
 \end{code}