From: simonmar Date: Fri, 24 Jan 2003 14:04:41 +0000 (+0000) Subject: [project @ 2003-01-24 14:04:41 by simonmar] X-Git-Tag: nhc98-1-18-release~751 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=ff719fd9d3b8dc30cff887beca7d2c0d823781e0;p=haskell-directory.git [project @ 2003-01-24 14:04:41 by simonmar] - Generalise seq to allow an unlifted type in its second argument. This works because seq is *always* inlined and replaced by a case. - Remove getTag, a wired-in Id with an unfolding, with a definition in GHC.Base: getTag x = x `seq` dataToTag# x this is why we required the above generalisation to seq (dataToTag# returns an Int#). See the comments in GHC.Base for more details. - As a side-effect, this fixes a bug in the interpreter, where the compiler optimised away the evaluation of the argument to dataToTag#, but the interpreter ended up passing it an unevaluated thunk (nullary constructors aren't always evaluated in GHCi, but the simplifier assumes they are). Now, in the interpreter, getTag won't be inlined so the compiler can't optimise away the evaluation, and we're saved. The real bug here is either (a) dataToTag# requires an evaluated argument or (b) the interpreter doesn't supply it with one, take your pick. --- diff --git a/GHC/Base.lhs b/GHC/Base.lhs index fe42991..9cdd755 100644 --- a/GHC/Base.lhs +++ b/GHC/Base.lhs @@ -667,6 +667,28 @@ data (:*:) a b = a :*: b #endif \end{code} +%********************************************************* +%* * +\subsection{@getTag@} +%* * +%********************************************************* + +Returns the 'tag' of a constructor application; this function is used +by the deriving code for Eq, Ord and Enum. + +The primitive dataToTag# requires an evaluated constructor application +as its argument, so we provide getTag as a wrapper that performs the +evaluation before calling dataToTag#. We could have dataToTag# +evaluate its argument, but we prefer to do it this way because (a) +dataToTag# can be an inline primop if it doesn't need to do any +evaluation, and (b) we want to expose the evaluation to the +simplifier, because it might be possible to eliminate the evaluation +in the case when the argument is already known to be evaluated. + +\begin{code} +{-# INLINE getTag #-} +getTag x = x `seq` dataToTag# x +\end{code} %********************************************************* %* * diff --git a/GHC/IOBase.lhs b/GHC/IOBase.lhs index 0626870..72cf045 100644 --- a/GHC/IOBase.lhs +++ b/GHC/IOBase.lhs @@ -751,7 +751,7 @@ instance Eq IOErrorType where x == y = case x of DynIOError{} -> False -- from a strictness POV, compatible with a derived Eq inst? - _ -> getTag# x ==# getTag# y + _ -> getTag x ==# getTag y instance Show IOErrorType where showsPrec _ e =