[GHC] #12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 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: -------------------------------------+------------------------------------- I've noticed it as a build failure on openbsd-6 but on linux behaviour is strange as well. Build failure: {{{ libraries/base/System/Posix/Types.hs:217:100: error: * No instance for (Fractional Int32) arising from the 'deriving' clause of a data type declaration Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself * When deriving the instance for (Fractional CTimer) }}} On openbsd-6.0 timer_t is an int32: {{{ # gcc -E /usr/include/time.h | grep timer_t typedef __int32_t __timer_t; typedef __timer_t timer_t; }}} On amd64-linux-glibc it's void*: {{{ $ gcc -E /usr/include/time.h | grep timer_t typedef void * __timer_t; typedef __timer_t timer_t; }}} But base's configure detects it as Double (by chance) on amd64-linux- glibc. {{{ System.Posix.Types> :t CTimer CTimer :: Double -> CTimer }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 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 slyfox): changeset:ffc2327070dbb664bdb407a804121eacb2a7c734 added instance as: {{{#!hs #if defined(HTYPE_TIMER_T) -- | @since 4.10.0.0 FLOATING_TYPE_WITH_CTYPE(CTimer,timer_t,HTYPE_TIMER_T) #endif }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 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 RyanGlScott): * cc: DanielG (added) Comment: As I note [https://phabricator.haskell.org/rGHCffc2327070dbb664bdb407a804121eacb2a7c734 here], a quick-and-dirty fix would be to introduce a macro `OPAQUE_TYPE_WITH_CTYPE` in `CTypes.h`: {{{#!hs #define OPAQUE_CLASSES Eq,Ord,Storable #define OPAQUE_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \ newtype {-# CTYPE "THE_CTYPE" #-} T = T B \ deriving (OPAQUE_CLASSES) \ deriving newtype (Read, Show); }}} And then use that on `CTimer` instead of `FLOATING_TYPE_WITH_CTYPE`. Of course, this doesn't fix the infelicity that the underlying representation of `CTimer` is still not a `Ptr ()`, which would require fixing the `FPTOOLS_CHECK_HTYPE_ELSE` [http://git.haskell.org/ghc.git/blob/ffc2327070dbb664bdb407a804121eacb2a7c734... M4 macro] in `libraries/base/aclocal.m4` to remedy. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #12795 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by DanielG): Ah looks like I trusted the assessments of `FPTOOLS_CHECK_HTYPE` a bit too much. Personally I'm not all that attached to `timer_t` specifically I just added it for completeness' sake. So I wouldn't mind just removing it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D2876 * milestone: => 8.2.1 Comment: Very well, I've opted to go down the "remove `CTimer`" route in Phab:D2876. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"513eb6a0638a1c64b9d76bcab39ed80cdd9dbb27/ghc" 513eb6a0/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="513eb6a0638a1c64b9d76bcab39ed80cdd9dbb27" Fix #12998 by removing CTimer Summary: CTimer is a wrapper around `timer_t`, which is a typedef for `void*` on most platforms. The issue is that GHC's `FPTOOLS_CHECK_HTYPE` is not robust enough to discern pointer types from non-pointer types, so it mistakenly labels `timer_t` as a `Double` or `Int32` (depending on how many bits a pointer takes up on your platform). This wreaks havoc when trying to give it certain type class instances, as noted in https://phabricator.haskell.org/rGHCffc2327070dbb664bdb407a804121eacb2a7c734. For now, the simplest thing to do would be removing `CTimer`, since: 1. The original author (@DanielG) didn't have a particular use in mind for `timer_t` when he fixed #12795. 2. `CTimer` hasn't appeared in a release of `base` yet. Fixes #12998. Reviewers: austin, hvr, bgamari, DanielG, trofi Reviewed By: bgamari, trofi Subscribers: thomie, DanielG, erikd Differential Revision: https://phabricator.haskell.org/D2876 GHC Trac Issues: #12795, #12998 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: closed => new * resolution: fixed => -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876, Wiki Page: | Phab:D2952 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D2876 => Phab:D2876, Phab:D2952 Comment: Since I was morbidly curious, I decided to see how much effort it would take to tweak the autoconf scripts to support detecting pointer types. To my surprise, it wasn't bad at all! I've opened to Phab:D2952 to add `CTimer` back to `System.Posix.Types`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876, Wiki Page: | Phab:D2952 -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"db91d17edfbe7deecb62bbb89c804249f9c4a4bd/ghc" db91d17e/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="db91d17edfbe7deecb62bbb89c804249f9c4a4bd" Properly introduce CTimer to System.Posix.Types Summary: In ffc2327070dbb664bdb407a804121eacb2a7c734, an attempt was made at adding a Haskell wrapper around the C `timer_t` type. Unfortunately, GHC's autoconf macros weren't sophisticated enough at the time to properly detect that `timer_t` is represented by a `void *` (i.e., a pointer) on most OSes. This is a second attempt at `CTimer`, this time using `AC_COMPILE_IFELSE` to detect if a type is a pointer type by compiling the following program: ``` type val; *val; ``` This also only derives a small subset of class instances for `CTimer` that are known to be compatible with `Ptr` using a new `OPAQUE_TYPE_WITH_CTYPE` macro. Test Plan: ./validate Reviewers: erikd, hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2952 GHC Trac Issues: #12795, #12998 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12998: libraries/base/System/Posix/Types.hs: tries to define Floating instance for opaque type -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12795 | Differential Rev(s): Phab:D2876, Wiki Page: | Phab:D2952 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * resolution: => fixed Comment: Fixed for real this time. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12998#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC