Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,977
    • Issues 4,977
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 479
    • Merge requests 479
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9163
Closed
Open
Created Jun 03, 2014 by Simon Peyton Jones@simonpjDeveloper

Ptr should have a phantom role

In GHC.Ptr we see

type role Ptr representational
data Ptr a = Ptr Addr# deriving (Eq, Ord)

with no comments. Why is Ptr representational?

In the same module we have castPtr:

castPtr :: Ptr a -> Ptr b
castPtr (Ptr addr) = Ptr addr

which unpacks and repacks a Ptr. If Ptr was phantom, we could use coerce. And that in turn would actually make a lot of code more efficient – there are lots of calls to castPtr. Specifically, in nofib, I tried implementing castPtr with unsafeCoerce. Then I found:

  • 12% less allocation in reverse-complem
  • 7.3% less allocation in fasta.
  • Binary sizes fell 0.1%.

Both these benchmarks are ones that do a lot of I/O, and it turns out that GHC.IO.Handle.Text.$wa1 has a castPtr that (all by itself) accounts for 12% of reverse-complem's total allocation! So making castPtr free is good.

Trac metadata
Trac field Value
Version 7.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking