[GHC] #8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size)

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) ----------------------------------------------+---------------------------- Reporter: carter | Owner: Type: feature request | Status: new Priority: high | Milestone: 7.10.1 Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Project (more than a week) | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: 8287 ----------------------------------------------+---------------------------- currently GHC's internals and code gen don't provide a strong distinction between Ints as data, and Ints for pointer / address arithmetic. This also comes up as being problematical in a number of ways. 1. We wind up having many portability issues around Int and pointer / address sizes. 2. adds some inessential complexity / problems to adding new architectures to ghc. eg x32 ABI which has 32bit pointers and 64bit ints somewhat breaks current assumptions in the GHC primops (because arrays are indexed by a byte offset, and the valid range for those is determined by the ABI pointer size!) 3. this Ints and Ptrs confusion we currently have, also means we can't leverage the Integer support in SIMD registers that is in most modern CPUs! If we could have those two separated better, theres a lot of low leve optimizations we could do for Int/Word data that we currently cant do! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) ----------------------------+---------------------------------------------- Reporter: carter | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: | Keywords: Compiler | Architecture: Unknown/Multiple Resolution: | Difficulty: Project (more than a week) Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: 8287 | ----------------------------+---------------------------------------------- Comment (by rwbarton): On point 2: It seems to me that the current Foreign.Ptr API {{{ plusPtr :: Ptr a -> Int -> Ptr b minusPtr :: Ptr a -> Ptr b -> Int }}} pretty much forces `Int` to be the same size as a C pointer, on any architecture. For a real x32 executable, this would mean 32-bit `Int`, while for a "fake x32" mode which maintains a heap below 4G and stores heap pointers as 4 bytes, but otherwise is a normal x86_64 executable, this would mean 64-bit `Int`. There doesn't seem to be a good reason why the `Int` used for normal arithmetic, and used to count things in data structures like `Map`, should be tied to that C pointer size. As a matter of fact, an appropriate replacement for those `Int`s in Foreign.Ptr already exists in Foreign.C.Types: `CPtrdiff`, "Haskell type representing the C `ptrdiff_t` type". -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) ----------------------------+---------------------------------------------- Reporter: carter | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: | Keywords: Compiler | Architecture: Unknown/Multiple Resolution: | Difficulty: Project (more than a week) Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: 8287 | ----------------------------+---------------------------------------------- Comment (by carter): agreed with Reid. its worth remarking though, that internally that CPtrdiff type is just Int64 on x86_64. It really needs to be a distinguished type internally, not just a newtype wrapper around an Int (at least for a satisfactory analogue for GHC and correct code gen) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) ----------------------------+---------------------------------------------- Reporter: carter | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: | Keywords: Compiler | Architecture: Unknown/Multiple Resolution: | Difficulty: Project (more than a week) Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: 8287 | ----------------------------+---------------------------------------------- Comment (by simonpj): Presumably an `Addr#` is wide enough to contain an offset? So perhaps we should use `Addr#` instead of `Int#` for address differences? We could have and `AddrDiff#` type, but then we'd need arithmetic over it etc. Maybe just a type synonym for `Addr#`? Anyway feel free to propose a concrete design. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) ----------------------------+---------------------------------------------- Reporter: carter | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: high | Version: 7.6.3 Component: | Keywords: Compiler | Architecture: Unknown/Multiple Resolution: | Difficulty: Project (more than a week) Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: 8287 | ----------------------------+---------------------------------------------- Comment (by carter): @simon I think so! (though i could be wrong). I'll have to mull over it a bit as I have time on the associated api: would motivate adding Torsors to GHC Base I think. http://www.reddit.com/r/haskell/comments/166iju/subtractable_values_are_tors... http://ro-che.info/articles/2013-01-08-torsors.html and http://hackage.haskell.org/packages/archive/vector-space/latest/doc/html /Data-AffineSpace.html with the key bits being {{{ class AdditiveGroup (Diff p) => AffineSpace p whereSource Associated Types type Diff p Source Associated vector space Methods (.-.) :: p -> p -> Diff pSource Subtract points (.+^) :: p -> Diff p -> pSource Point plus vector }}} in this case, the Addr would the the "points", and the offset type would be type Diff Addr = AddrDiff or something like that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d
Int_ptr_diff and Int_ptr_size)
----------------------------+----------------------------------------------
Reporter: carter | Owner:
Type: feature | Status: new
request | Milestone: 7.10.1
Priority: high | Version: 7.6.3
Component: | Keywords:
Compiler | Architecture: Unknown/Multiple
Resolution: | Difficulty: Project (more than a week)
Operating System: | Blocked By:
Unknown/Multiple | Related Tickets:
Type of failure: |
None/Unknown |
Test Case: |
Blocking: 8287 |
----------------------------+----------------------------------------------
Comment (by carter):
Reid Barton (who's been experimenting with an x32 ABI) made an observation
yesterday evening on IRC #ghc about address vs int sizes for ghc
{{{
[09:24:34] <rwbarton> ugh, I didn't think about the fact that integer-
gmp exposes its representation to the world
[09:24:43] <rwbarton> that means potentially anybody is assuming that
Int is the same size as mp_limb_t
[09:24:47]

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: feature | Status: new request | Milestone: 7.12.1 Priority: high | Version: 7.6.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Project (more Unknown/Multiple | than a week) Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: 8287 | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by carter): * milestone: 7.10.1 => 7.12.1 Comment: this is still an issue, but should be punted to 7.12 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: 8287 Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * priority: high => normal * milestone: 8.0.1 => 8.2.1 Comment: This won't be happening for 8.0 I'm afraid. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8299: Add richer data model address arithmetic: AddrDiff and AddrInt (ie d Int_ptr_diff and Int_ptr_size) -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: 8287 Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.2.1 => Comment: Un-milestoning due to lack of progress. Feel free to pick it up though! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8299#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC