[GHC] #13203: Implement Bits Natural clearBit
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 8.0.2 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The current Bits Natural implementation says: {{{TODO: setBit, clearBit, complementBit (needs more primitives)}}}. The default implementations of setBit and complementBit work fine, but clearBit relies on complement, and so fails. Even if it had to use a conditional complementBit on testBit, it would be better than nothing. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dylex): * priority: normal => lowest -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: (none) Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vlopez): At least it should be documented that `clearBit` is undefined. For implementing `clearBit`, instead of doing a conditional `complementBit` on `testBit`, I suggest doing a `complementBit` after `setBit`. This avoids branching entirely. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by supersven): * owner: (none) => supersven -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by supersven): Hey, I did a small experiment to check that GHC.Natural behaves as expected. How to reproduce (that `clearBit` doesn't work): {{{ [nix-shell:~/src/ghc]$ inplace/bin/ghc-stage2 --interactive GHCi, version 8.3.20170930: http://www.haskell.org/ghc/ :? for help Prelude> import GHC.Natural Prelude GHC.Natural> import Data.Bits Prelude GHC.Natural Data.Bits> clearBit (naturalFromInteger 1) 0 *** Exception: Bits.complement: Natural complement undefined }}} `setBit` and `complementBit` work as expected: {{{ Prelude GHC.Natural Data.Bits> setBit (naturalFromInteger 0) 0 1 Prelude GHC.Natural Data.Bits> setBit (naturalFromInteger 1) 0 1 Prelude GHC.Natural Data.Bits> complementBit (naturalFromInteger 0) 0 1 Prelude GHC.Natural Data.Bits> complementBit (naturalFromInteger 1) 0 0 }}} == Plan == - Implement `clearBit` as proposed by vlopez. - Remove the todo. - Add test. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): *cough* D3415 *cough* -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by supersven): Just a few details if someone else reads this ticket: phab:D3415 would supersede this ticket as it implements `clearBit` in a more sophisticated way. I think under these circumstances it wouldn't make much sense to finish this ticket. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"5984a698fc2974b719365a9647a7cae1bed51eec/ghc" 5984a698/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="5984a698fc2974b719365a9647a7cae1bed51eec" Override default `clearBit` method impl for `Natural` The default implementation of `clearBit` is in terms of `complement`. However, `complement` is not well-defined for `Natural` and this consequently renders the default implementation of `clearBit` dysfunctional. This implements `clearBit` in terms of `testBit` and `setBit` which are both well-defined for `Natural`s. This addresses #13203 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: new Priority: lowest | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"843772b86b62df686a9e57648fa9d3ed06b13973/ghc" 843772b8/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="843772b86b62df686a9e57648fa9d3ed06b13973" Enable testing 'Natural' type in TEST=arith011 This now passes thanks to 5984a698fc2974b719365a9647a7cae1bed51eec (re #13203) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: merge Priority: high | Milestone: 8.2.2 Component: libraries/base | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by hvr): * status: new => merge * failure: None/Unknown => Incorrect result at runtime * priority: lowest => high * version: 8.0.2 => 7.10.1 * milestone: => 8.2.2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: merge Priority: high | Milestone: 8.2.2 Component: libraries/base | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): An implementation of `clearBit` for `Natural` has been merged to `ghc-8.2` with 3de07dcf221548e73c3623a085cae99d0b519c8b. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13203: Implement Bits Natural clearBit -------------------------------------+------------------------------------- Reporter: dylex | Owner: supersven Type: bug | Status: closed Priority: high | Milestone: 8.2.2 Component: libraries/base | Version: 7.10.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13203#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC