Ptr should have a phantom role
|Reported by:||simonpj||Owned by:|
|Type of failure:||None/Unknown||Test Case:||roles/should_compile/Roles2|
|Related Tickets:||#9164||Differential Rev(s):|
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.
Change History (29)
comment:18 Changed 16 months ago by nomeata
- Resolution set to fixed
- Status changed from new to closed
comment:20 Changed 16 months ago by nomeata
- Resolution fixed deleted
- Status changed from closed to new
comment:26 Changed 16 months ago by goldfire
- Milestone set to 7.8.4
- Status changed from new to merge
comment:27 Changed 16 months ago by goldfire
- Owner goldfire deleted
- Status changed from merge to new