Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
1435eef2
Commit
1435eef2
authored
Dec 07, 2012
by
tibbe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor primitive field unpacking check
parent
7bf6eb9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
22 deletions
+25
-22
compiler/typecheck/TcTyClsDecls.lhs
compiler/typecheck/TcTyClsDecls.lhs
+25
-22
No files found.
compiler/typecheck/TcTyClsDecls.lhs
View file @
1435eef2
...
...
@@ -37,7 +37,6 @@ import TcClassDcl
import TcHsType
import TcMType
import TcType
import qualified TysPrim
import TysWiredIn( unitTy )
import Type
import Kind
...
...
@@ -1251,8 +1250,8 @@ chooseBoxingStrategy dflags arg_ty bang
Just (arg_tycon, _)
| isAbstractTyCon arg_tycon -> False
-- See Note [Don't complain about UNPACK on abstract TyCons]
| isPrimTyCon arg_tycon &&
arg_tycon `elem` ptrSizedPrimTyCons
-> True
| isPrimTyCon arg_tycon &&
hasPtrSizedRep (tyConPrimRep arg_tycon)
-> True
-- TODO: Check that the PrimTyCon corresponds to a type
-- with pointer-sized representation.
| isEmptyDataTyCon arg_tycon -> True
...
...
@@ -1261,25 +1260,22 @@ chooseBoxingStrategy dflags arg_ty bang
-> can_unbox_prim ty
| otherwise -> False
ptrSizedPrimTyCons :: [TyCon]
ptrSizedPrimTyCons =
[ TysPrim.addrPrimTyCon
, TysPrim.arrayPrimTyCon
, TysPrim.byteArrayPrimTyCon
, TysPrim.arrayArrayPrimTyCon
, TysPrim.charPrimTyCon
, TysPrim.doublePrimTyCon
, TysPrim.floatPrimTyCon
, TysPrim.intPrimTyCon
, TysPrim.int32PrimTyCon
, TysPrim.int64PrimTyCon
, TysPrim.mutableArrayPrimTyCon
, TysPrim.mutableByteArrayPrimTyCon
, TysPrim.mutableArrayArrayPrimTyCon
, TysPrim.wordPrimTyCon
, TysPrim.word32PrimTyCon
, TysPrim.word64PrimTyCon
]
-- | Return True if representation can be considered pointer-sized (or
-- smaller) in the context of unpacking.
hasPtrSizedRep :: PrimRep -> Bool
-- We explicitly enumerate the PrimReps so that if another PrimRep is
-- ever added we'll get a pattern match warning which will make sure
-- we consider the new case here:
hasPtrSizedRep IntRep = True
hasPtrSizedRep WordRep = True
hasPtrSizedRep Int64Rep = True -- See Note [Primitive size exception]
hasPtrSizedRep Word64Rep= True -- See Note [Primitive size exception]
hasPtrSizedRep FloatRep = True -- NB. might not take a full word
hasPtrSizedRep DoubleRep= True -- See Note [Primitive size exception]
hasPtrSizedRep AddrRep = True
hasPtrSizedRep PtrRep = True
hasPtrSizedRep VoidRep = True
\end{code}
...
...
@@ -1307,6 +1303,13 @@ But it's the *argument* type that matters. This is fine:
data S = MkS S !Int
because Int is non-recursive.
Note [Primitive size exception]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For consistency reasons we make an exception to the size requirement
for Doubles, Word64s, and Int64s on 32-bit architectures. Not doing so
might have surprising performance implications if code is moved from a
64-bit to a 32-bit architecture.
%************************************************************************
%* *
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment