summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Bits.hs
Commit message (Collapse)AuthorAgeFilesLines
* Add @since annotations to base instancesSeraphime Kirkovski2016-06-061-1/+9
| | | | | | | | | | | | | | | | | | Add @since annotations to instances in `base`. Test Plan: * ./validate # some commets shouldn't break the build * review the annotations for absurdities. Reviewers: ekmett, goldfire, RyanGlScott, austin, hvr, bgamari Reviewed By: RyanGlScott, hvr, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2277 GHC Trac Issues: #11767
* Allow CallStacks to be frozenEric Seidel2015-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces "freezing," an operation which prevents further locations from being appended to a CallStack. Library authors may want to prevent CallStacks from exposing implementation details, as a matter of hygiene. For example, in ``` head [] = error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` including the call-site of `error` in `head` is not strictly necessary as the error message already specifies clearly where the error came from. So we add a function `freezeCallStack` that wraps an existing CallStack, preventing further call-sites from being pushed onto it. In other words, ``` pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack ``` Now we can define `head` to not produce a CallStack at all ``` head [] = let ?callStack = freezeCallStack emptyCallStack in error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` --- 1. We add the `freezeCallStack` and `emptyCallStack` and update the definition of `CallStack` to support this functionality. 2. We add `errorWithoutStackTrace`, a variant of `error` that does not produce a stack trace, using this feature. I think this is a sensible wrapper function to provide in case users want it. 3. We replace uses of `error` in base with `errorWithoutStackTrace`. The rationale is that base does not export any functions that use CallStacks (except for `error` and `undefined`) so there's no way for the stack traces (from Implicit CallStacks) to include user-defined functions. They'll only contain the call to `error` itself. As base already has a good habit of providing useful error messages that name the triggering function, the stack trace really just adds noise to the error. (I don't have a strong opinion on whether we should include this third commit, but the change was very mechanical so I thought I'd include it anyway in case there's interest) 4. Updates tests in `array` and `stm` submodules Test Plan: ./validate, new test is T11049 Reviewers: simonpj, nomeata, goldfire, austin, hvr, bgamari Reviewed By: simonpj Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1628 GHC Trac Issues: #11049
* Keep `shift{L,R}` on `Integer` from segfaultingBen Gamari2015-10-101-8/+0
| | | | | | | | | | | | | | | | | | | | | | | This can happen because the underlying primitive operations in `integer-gmp` don't support negative shift-amounts, and since `integer-gmp` can't throw proper exceptions and just provides a low-level API, it simply segfaults instead... This patch simply removes the `shift{L,R}` method definitions (and defines `unsafeShift{L,R}` instead) whose default-impls fallback on using `shift` which properly handles negative shift arguments. This addresses #10571 Test Plan: harbormaster can do it Reviewers: hvr, austin, rwbarton Subscribers: rwbarton, thomie, bgamari Differential Revision: https://phabricator.haskell.org/D1018 GHC Trac Issues: #10571
* Ensure shiftL/shiftR arguments aren't negativeBen Gamari2015-10-071-2/+6
| | | | Fixes #10571.
* Convert `/Since: .../` to new `@since ...` syntaxHerbert Valerio Riedel2014-12-161-14/+14
| | | | | | Starting with Haddock 2.16 there's a new built-in support for since-annotations Note: This exposes a bug in the `@since` implementation (see e.g. `Data.Bits`)
* Use {bit,popCount}Integer for `Bits Integer`Herbert Valerio Riedel2014-11-261-0/+14
| | | | | | The primops are implemented in the `integer-gmp2` (#9281) backend and are already used for the `Bits Natural` instance but aren't used yet for the `Bits Integer` instace. This commit fixes that.
* Add function for size-checked conversion of Integral typesSean Leather2014-11-211-1/+104
| | | | | | | | | | | | | | | | The new function `Data.Bits.toIntegralSized` provides a similar functionality to `fromIntegral` but adds validation that the argument fits in the result type's size. The implementation of `toIntegralSized` has been derived from `intCastMaybe` (which is part of Herbert Valerio Riedel's `int-cast` package, see http://hackage.haskell.org/package/int-cast) Addresses #9816 Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D512
* Refactor Haddock comments in Data.BitsHerbert Valerio Riedel2014-11-041-17/+18
| | | | | | | | | | | This removes the redundant "Minimal complete definition"-block included in the Haddock comment since Haddock renders the `MINIMAL`-pragma as well (which has is moved to the start of `class` definition for better readability of the source code) Morever, the references to `testBitDefault`, `bitDefault`, and `popCountDefault` have been moved to the respective methods' Haddock strings for which they can be used.
* Remove incorrect property in docstring (re #9532)Herbert Valerio Riedel2014-09-011-1/+0
| | | | | | | | | | | | | The property countLeadingZeros . negate = const 0 doesn't generally hold and it's not such a useful property to state, as it simply follows from "sign-bit == most-significant-bit" for FiniteBits types which use twos-complement representation for negative values, and even then it breaks down for 0... TLDR, remove thinko from documentation of `countLeadingZeros`
* `M-x delete-trailing-whitespace` & `M-x untabify`...Herbert Valerio Riedel2014-08-311-4/+3
| | | | | | ...some files more or less recently touched by me [ci skip]
* Add `FiniteBits(count{Leading,Trailing}Zeros)`Herbert Valerio Riedel2014-08-311-2/+70
| | | | | | | | | | | | | | | | | | | This exposes the newly added CLZ/CTZ primops from e0c1767d0ea8d12e0a4badf43682a08784e379c6 (re #9340) via two new methods `countLeadingZeros` and `countTrailingZeros` in the `Data.Bits.FiniteBits` class. The original proposal can be found at http://www.haskell.org/pipermail/libraries/2014-August/023567.html Test Plan: successful validate Reviewers: ekmett, tibbe GHC Trac Issues: #9532 Differential Revision: https://phabricator.haskell.org/D158
* Add shiftR and shiftL implementations to instance Bits IntegerSimon Peyton Jones2014-03-131-0/+3
| | | | | | | Apart from simply making sense (avoid the conditional in 'shift'), this makes left and right shifts on Integer more likely to inline (plain 'shift' is just too large); and this in turn is important when fixing the Integer case of #8832
* Workaround failed constant-folding for zeroBitsHerbert Valerio Riedel2014-03-011-0/+3
| | | | | | | | | | | | | | | For some reason GHC fails to constant fold `zeroBits :: Int` and `zeroBits :: Integer`; `ghc -show-iface` shows $fBitsInt_$czeroBits :: GHC.Types.Int {- Strictness: m, Unfolding: (GHC.Types.I# (GHC.Prim.andI# 1 (GHC.Prim.notI# 1))) -} Otoh, constant-folding works as expected, reducing `zeroBits` to 0 constant for the other integer-types (= {Word,Int}{8,16,32,64}` and `Word`). So this quickfix is actually just treating the symptom rather than the cause. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add new Data.Bits.Bits(zeroBits) methodHerbert Valerio Riedel2014-02-281-1/+21
| | | | | | | | | This adds a new method to `Bits` which completes the Bits API with a direct way to introduce a value with all bits cleared. See also original proposal at http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/21157
* Minor fixes to Haddock markupHerbert Valerio Riedel2014-02-211-1/+1
| | | | Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Use new bitwise Int# primops in Data.Bits (re #8791)Chris Dueck2014-02-191-13/+7
| | | | | | | | | The new primops (see also #7689) allow to optimize `instance Bits Int` by allowing to operate directly on Int# instead of having to convert to Word# and back to Int# again. Authored-by: Chris Dueck <crdueck@uwaterloo.ca> Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Improve Haddock markupHerbert Valerio Riedel2014-01-301-1/+1
| | | | | | | | | | | This fixes the markup at the top of `Control.Arrow`, and improves the markup inside DEPRECATED strings. (Haddock supports markup inside DEPRECATED messages, which allows to turn references to Haskell entities into hyperlinks by using the usual Haddock markup.) Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add `instance {Bits,FiniteBits} Bool`Herbert Valerio Riedel2013-11-241-0/+35
| | | | | | | | | | | This interprets `Bool` as an 1-bit "unsigned" bit-field and provides a simple (not particularily optimized) implementation to that end. See "Proposal: Add `instance Bits Bool`" by @ekmett, Nov 2013, http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/20663 Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.5.[01].0/` comments to symbolsHerbert Valerio Riedel2013-09-221-3/+9
| | | | | | | | | | This commit retroactively adds `/Since: 4.5.[01].0/` annotations to symbols newly added/exposed in `base-4.5.[01].0` (as shipped with GHC 7.4.[12]). See also 6368362f which adds the respective annotation for symbols newly added in `base-4.7.0.0` (that goes together with GHC 7.8.1). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.6.0.0/` comments to symbolsHerbert Valerio Riedel2013-09-211-0/+6
| | | | | | | | | | This commit retroactively adds `/Since: 4.6.0.0/` annotations to symbols newly added/exposed in `base-4.6.0.0` (as shipped with GHC 7.6.1). See also 6368362f which adds the respective annotation for symbols newly added in `base-4.7.0.0` (that goes together with GHC 7.8.1). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.7.0.0/` comments to new symbolsHerbert Valerio Riedel2013-09-211-0/+2
| | | | | | | | | | | | | | | | | | These annotations were added in such a way, that the line {{{ /Since: 4.7.0.0/ }}} represents the last paragraph of the Haddock comment. Maybe Haddock will have support for this meta-syntax at some point, and be able to inherited the since-version property to the children of an annotated symbol and display the since-version property in the rendered documentation only in cases when it's not visually obvious (for instance, when re-exporting documentation strings). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock docs for new `class FiniteBits`Herbert Valerio Riedel2013-09-211-0/+13
|
* Follow changes in comparison primops (see #6135)Jan Stolarek2013-09-181-9/+9
|
* Trailing whitespacesJan Stolarek2013-09-181-4/+4
|
* Add `{-# MINIMAL #-}` annotations to typeclassesHerbert Valerio Riedel2013-09-181-0/+5
| | | | | | | | | | | | | | | | | This makes use of the new `{-# MINIMAL #-}` facility (see #7633) for the following typeclasses - `Bits` - `Foldable` - `Fractional` - `Num` - `MonadZip` - `Read` - `Show` - `Storable` - `Traversable` Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Constant-fold `__GLASGOW_HASKELL__` CPP conditionalsHerbert Valerio Riedel2013-09-171-74/+0
| | | | | | | | | | Now that HUGS and NHC specific code has been removed, this commit "folds" the now redundant `#if((n)def)`s containing `__GLASGOW_HASKELL__`. This renders `base` officially GHC only. This commit also removes redundant `{-# LANGUAGE CPP #-}`. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Remove Hugs98 specific codeHerbert Valerio Riedel2013-09-171-16/+1
| | | | | | | For rationale. see http://permalink.gmane.org/gmane.comp.lang.haskell.ghc.devel/2349 Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Mark DEPRECATED pragmas with when they were addedIan Lynagh2013-02-161-1/+1
|
* Remove nhc98-specific files and contentIan Lynagh2013-02-151-20/+1
|
* Remove commented types in module export listsIan Lynagh2012-10-271-17/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These comments are rather less useful now that haddock can give docs with the same informatino in the module synopsis. Having to maintain them when making changes to the library is a pain, and when people forget about doing so there is nothing that checks that the comments are right, so mistakes tend to linger. Of the comments that my script detected, 78 of 684 were already incorrect in one way or another, e.g. missing context: Text.Show.showsPrec Comment type: Int -> a -> ShowS Actual type: Show a => Int -> a -> ShowS wrong context: Numeric.readInt Comment type: Integral a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a Actual type: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a not following a class change (e.g. Num losing its Eq superclass): Text.Read.Lex.readOctP Comment type: Num a => ReadP a Actual type: (Eq a, Num a) => ReadP a not following the Exceptions change: GHC.Conc.childHandler Comment type: Exception -> IO () Actual type: SomeException -> IO () or just always been wrong: GHC.Stable.deRefStablePtr Comment type: StablePtr a -> a Actual type: StablePtr a -> IO a
* Make sure testBit and bit get inlined; fixes #7292Ian Lynagh2012-10-251-2/+6
|
* Deprecate bitSizeIan Lynagh2012-09-231-0/+2
|
* Add bitSizeMaybe to Bits, and add FiniteBits classIan Lynagh2012-09-231-2/+23
|
* Use testBitInteger; part of #3489. patch from pumpkingod@gmail.comIan Lynagh2012-08-051-1/+2
|
* Move the Word type from base to ghc-primIan Lynagh2012-05-211-0/+32
|
* Fix documentation of minimal complete definition of Bits instancesJohan Tibell2012-02-141-1/+3
| | | | | | Added testBit, bit, and popCount to the required set. They no longer have default implementations as the Num constraint was removed from the Bits class.
* Fix bug in popCountDefault. Fixes #5872Johan Tibell2012-02-141-1/+2
| | | | | Also add an INLINABLE pragma so that the function can be specialized at the call site.
* Remove Num superclass of Bits Add and export bitDefault, testBitDefault and ↵Bas van Dijk2012-01-141-13/+43
| | | | popCountDefault from Data.Bits.
* Add unsafeShift to Data.BitsJohan Tibell2011-11-081-2/+28
| | | | | This allows shifting by a non-statically known amount without introducing a branch (to check for "overflow").
* Update base for latest Safe Haskell.David Terei2011-10-251-1/+0
|
* Remove the Eq superclass of NumIan Lynagh2011-10-121-1/+1
|
* Add Data.Bits.popCountJohan Tibell2011-08-251-1/+15
|
* Data.Bits: specialise shift[LR] for instance BitsLiyang HU2011-07-281-0/+2
| | | | | | Documentation notes that the second arg of shift[LR] must be positive, yet many definitions of instance Bits rely on the class default, which performs an unnecessary sign check.
* SafeHaskell: Added SafeHaskell to baseDavid Terei2011-06-181-0/+1
|
* Use explicit language extensions & remove extension fields from base.cabalsimonpj@microsoft.com2011-01-281-2/+2
| | | | | | | | | | Add explicit {-# LANGUAGE xxx #-} pragmas to each module, that say what extensions that module uses. This makes it clearer where different extensions are used in the (large, variagated) base package. Now base.cabal doesn't need any extensions field Thanks to Bas van Dijk for doing all the work.
* Add LANGUAGE BangPatterns to modules that use bang patternssimonpj@microsoft.com2010-11-121-0/+1
|
* clarify meaning of bitSimon Marlow2010-07-141-1/+1
|
* Exploit now-working default-method INLINE pragmas for Data.Bitssimonpj@microsoft.com2009-10-291-3/+9
| | | | | | | * Add INLINE pragmas to default methods for class Bits * Remove redundant instance methods elsewhere, now that the default method will do the job
* Fix gratuitous breakage for non-GHC in Data.Bits.Malcolm.Wallace@cs.york.ac.uk2009-10-091-3/+4
|
* Use shift[LR]Integer in the Bits Integer instanceIan Lynagh2009-07-211-3/+2
|