diff options
author | Richard Eisenberg <rae@cs.brynmawr.edu> | 2016-12-14 21:37:43 -0500 |
---|---|---|
committer | Richard Eisenberg <rae@cs.brynmawr.edu> | 2017-01-19 10:31:52 -0500 |
commit | e7985ed23ddc68b6a2e4af753578dc1d9e8ab4c9 (patch) | |
tree | ba8c4016e218710f8165db92d4b4c10e5559245a /libraries/integer-gmp | |
parent | 38374caa9d6e1373d1b9d335d0f99f3664931fd9 (diff) | |
download | haskell-e7985ed23ddc68b6a2e4af753578dc1d9e8ab4c9.tar.gz |
Update levity polymorphism
This commit implements the proposal in
https://github.com/ghc-proposals/ghc-proposals/pull/29 and
https://github.com/ghc-proposals/ghc-proposals/pull/35.
Here are some of the pieces of that proposal:
* Some of RuntimeRep's constructors have been shortened.
* TupleRep and SumRep are now parameterized over a list of RuntimeReps.
* This
means that two types with the same kind surely have the same
representation.
Previously, all unboxed tuples had the same kind, and thus the fact
above was
false.
* RepType.typePrimRep and friends now return a *list* of PrimReps. These
functions can now work successfully on unboxed tuples. This change is
necessary because we allow abstraction over unboxed tuple types and so
cannot
always handle unboxed tuples specially as we did before.
* We sometimes have to create an Id from a PrimRep. I thus split PtrRep
* into
LiftedRep and UnliftedRep, so that the created Ids have the right
strictness.
* The RepType.RepType type was removed, as it didn't seem to help with
* much.
* The RepType.repType function is also removed, in favor of typePrimRep.
* I have waffled a good deal on whether or not to keep VoidRep in
TyCon.PrimRep. In the end, I decided to keep it there. PrimRep is *not*
represented in RuntimeRep, and typePrimRep will never return a list
including
VoidRep. But it's handy to have in, e.g., ByteCodeGen and friends. I can
imagine another design choice where we have a PrimRepV type that is
PrimRep
with an extra constructor. That seemed to be a heavier design, though,
and I'm
not sure what the benefit would be.
* The last, unused vestiges of # (unliftedTypeKind) have been removed.
* There were several pretty-printing bugs that this change exposed;
* these are fixed.
* We previously checked for levity polymorphism in the types of binders.
* But we
also must exclude levity polymorphism in function arguments. This is
hard to check
for, requiring a good deal of care in the desugarer. See Note [Levity
polymorphism
checking] in DsMonad.
* In order to efficiently check for levity polymorphism in functions, it
* was necessary
to add a new bit of IdInfo. See Note [Levity info] in IdInfo.
* It is now safe for unlifted types to be unsaturated in Core. Core Lint
* is updated
accordingly.
* We can only know strictness after zonking, so several checks around
* strictness
in the type-checker (checkStrictBinds, the check for unlifted variables
under a ~
pattern) have been moved to the desugarer.
* Along the way, I improved the treatment of unlifted vs. banged
* bindings. See
Note [Strict binds checks] in DsBinds and #13075.
* Now that we print type-checked source, we must be careful to print
* ConLikes correctly.
This is facilitated by a new HsConLikeOut constructor to HsExpr.
Particularly troublesome
are unlifted pattern synonyms that get an extra void# argument.
* Includes a submodule update for haddock, getting rid of #.
* New testcases:
typecheck/should_fail/StrictBinds
typecheck/should_fail/T12973
typecheck/should_run/StrictPats
typecheck/should_run/T12809
typecheck/should_fail/T13105
patsyn/should_fail/UnliftedPSBind
typecheck/should_fail/LevPolyBounded
typecheck/should_compile/T12987
typecheck/should_compile/T11736
* Fixed tickets:
#12809
#12973
#11736
#13075
#12987
* This also adds a test case for #13105. This test case is
* "compile_fail" and
succeeds, because I want the testsuite to monitor the error message.
When #13105 is fixed, the test case will compile cleanly.
Diffstat (limited to 'libraries/integer-gmp')
-rw-r--r-- | libraries/integer-gmp/src/GHC/Integer/Logarithms.hs | 3 | ||||
-rw-r--r-- | libraries/integer-gmp/src/GHC/Integer/Type.hs | 32 |
2 files changed, 18 insertions, 17 deletions
diff --git a/libraries/integer-gmp/src/GHC/Integer/Logarithms.hs b/libraries/integer-gmp/src/GHC/Integer/Logarithms.hs index cbcc860002..76467e18a7 100644 --- a/libraries/integer-gmp/src/GHC/Integer/Logarithms.hs +++ b/libraries/integer-gmp/src/GHC/Integer/Logarithms.hs @@ -3,6 +3,7 @@ {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE UnliftedFFITypes #-} {-# LANGUAGE CPP #-} +{-# LANGUAGE BangPatterns #-} module GHC.Integer.Logarithms ( wordLog2# @@ -43,7 +44,7 @@ integerLogBase# :: Integer -> Integer -> Int# integerLogBase# (S# 2#) m = integerLog2# m integerLogBase# b m = e' where - (# _, e' #) = go b + !(# _, e' #) = go b go pw | m `ltInteger` pw = (# m, 0# #) go pw = case go (sqrInteger pw) of diff --git a/libraries/integer-gmp/src/GHC/Integer/Type.hs b/libraries/integer-gmp/src/GHC/Integer/Type.hs index 9800f55692..035cb1e7ba 100644 --- a/libraries/integer-gmp/src/GHC/Integer/Type.hs +++ b/libraries/integer-gmp/src/GHC/Integer/Type.hs @@ -762,7 +762,7 @@ divModInteger n d in (# q', r' #) | True = qr where - qr@(# q, r #) = quotRemInteger n d + !qr@(# q, r #) = quotRemInteger n d {-# CONSTANT_FOLDED divModInteger #-} divInteger :: Integer -> Integer -> Integer @@ -1036,7 +1036,7 @@ timesBigNatWord !_ 0## = zeroBigNat timesBigNatWord x 1## = x timesBigNatWord x@(BN# x#) y# | isTrue# (nx# ==# 1#) = - let (# !h#, !l# #) = timesWord2# (bigNatToWord x) y# + let !(# !h#, !l# #) = timesWord2# (bigNatToWord x) y# in wordToBigNat2 h# l# | True = runS $ do mbn@(MBN# mba#) <- newBigNat# nx# @@ -1066,7 +1066,7 @@ bitBigNat i# _ <- svoid (writeBigNat# mbn li# (uncheckedShiftL# 1## bi#)) unsafeFreezeBigNat# mbn where - (# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# + !(# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# testBitBigNat :: BigNat -> Int# -> Bool testBitBigNat bn i# @@ -1074,7 +1074,7 @@ testBitBigNat bn i# | isTrue# (li# <# nx#) = isTrue# (testBitWord# (indexBigNat# bn li#) bi#) | True = False where - (# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# + !(# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# nx# = sizeofBigNat# bn testBitNegBigNat :: BigNat -> Int# -> Bool @@ -1085,7 +1085,7 @@ testBitNegBigNat bn i# (indexBigNat# bn li# `minusWord#` 1##) bi#) ==# 0#) | True = isTrue# ((testBitWord# (indexBigNat# bn li#) bi#) ==# 0#) where - (# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# + !(# li#, bi# #) = quotRemInt# i# GMP_LIMB_BITS# nx# = sizeofBigNat# bn allZ 0# = True @@ -1108,7 +1108,7 @@ shiftLBigNat x@(BN# xba#) n# = runS $ do where xn# = sizeofBigNat# x yn# = xn# +# nlimbs# +# (nbits# /=# 0#) - (# nlimbs#, nbits# #) = quotRemInt# n# GMP_LIMB_BITS# + !(# nlimbs#, nbits# #) = quotRemInt# n# GMP_LIMB_BITS# @@ -1693,7 +1693,7 @@ resizeMutBigNat# (MBN# mba0#) nsz# s (# s'', mba# #) -> (# s'', MBN# mba# #) where bsz# = nsz# `uncheckedIShiftL#` GMP_LIMB_SHIFT# - (# s', n# #) = getSizeofMutableByteArray# mba0# s + !(# s', n# #) = getSizeofMutableByteArray# mba0# s shrinkMutBigNat# :: MutBigNat s -> GmpSize# -> State# s -> State# s shrinkMutBigNat# (MBN# mba0#) nsz# s @@ -1701,13 +1701,13 @@ shrinkMutBigNat# (MBN# mba0#) nsz# s | True = shrinkMutableByteArray# mba0# bsz# s' where bsz# = nsz# `uncheckedIShiftL#` GMP_LIMB_SHIFT# - (# s', n# #) = getSizeofMutableByteArray# mba0# s + !(# s', n# #) = getSizeofMutableByteArray# mba0# s unsafeSnocFreezeBigNat# :: MutBigNat s -> GmpLimb# -> S s BigNat unsafeSnocFreezeBigNat# mbn0@(MBN# mba0#) limb# s = go s' where n# = nb0# `uncheckedIShiftRL#` GMP_LIMB_SHIFT# - (# s', nb0# #) = getSizeofMutableByteArray# mba0# s + !(# s', nb0# #) = getSizeofMutableByteArray# mba0# s go = do (MBN# mba#) <- resizeMutBigNat# mbn0 (n# +# 1#) _ <- svoid (writeWordArray# mba# n# limb#) @@ -1721,8 +1721,8 @@ unsafeRenormFreezeBigNat# mbn s | isTrue# (n# ==# n0#) = (unsafeFreezeBigNat# mbn) s'' | True = (unsafeShrinkFreezeBigNat# mbn n#) s'' where - (# s', n0# #) = getSizeofMutBigNat# mbn s - (# s'', n# #) = normSizeofMutBigNat'# mbn n0# s' + !(# s', n0# #) = getSizeofMutBigNat# mbn s + !(# s'', n# #) = normSizeofMutBigNat'# mbn n0# s' -- | Shrink MBN unsafeShrinkFreezeBigNat# :: MutBigNat s -> GmpSize# -> S s BigNat @@ -1752,7 +1752,7 @@ copyWordArray# src src_ofs dst dst_ofs len normSizeofMutBigNat# :: MutBigNat s -> State# s -> (# State# s, Int# #) normSizeofMutBigNat# mbn@(MBN# mba) s = normSizeofMutBigNat'# mbn sz# s' where - (# s', n# #) = getSizeofMutableByteArray# mba s + !(# s', n# #) = getSizeofMutableByteArray# mba s sz# = n# `uncheckedIShiftRA#` GMP_LIMB_SHIFT# -- | Find most-significant non-zero limb and return its index-position @@ -1783,13 +1783,13 @@ byteArrayToBigNat# ba# n0# | isTrue# (baszr# ==# 0#) -- i.e. ba# is multiple of limb-size , isTrue# (baszq# ==# n#) = (BN# ba#) | True = runS $ \s -> - let (# s', mbn@(MBN# mba#) #) = newBigNat# n# s - (# s'', ba_sz# #) = getSizeofMutableByteArray# mba# s' + let !(# s', mbn@(MBN# mba#) #) = newBigNat# n# s + !(# s'', ba_sz# #) = getSizeofMutableByteArray# mba# s' go = do _ <- svoid (copyByteArray# ba# 0# mba# 0# ba_sz# ) unsafeFreezeBigNat# mbn in go s'' where - (# baszq#, baszr# #) = quotRemInt# (sizeofByteArray# ba#) GMP_LIMB_BYTES# + !(# baszq#, baszr# #) = quotRemInt# (sizeofByteArray# ba#) GMP_LIMB_BYTES# n# = fmssl (n0# -# 1#) @@ -1914,7 +1914,7 @@ isValidBigNat# (BN# ba#) sz# = sizeofByteArray# ba# - (# szq#, szr# #) = quotRemInt# sz# GMP_LIMB_BYTES# + !(# szq#, szr# #) = quotRemInt# sz# GMP_LIMB_BYTES# -- | Version of 'nextPrimeInteger' operating on 'BigNat's -- |