Opened 5 years ago

Last modified 19 months ago

#10016 new feature request

UNPACK support for existentials

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.4
Keywords: DataCons Cc: vagarenko, dfeuer
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)


data Foo = forall a. Show a => Foo !a !a

data Bar = Bar {-# UNPACK #-} !Foo

The UNPACK pragma should really be able to unpack the Foo field, so that (implementation-wise) it would be as if you'd declared Bar thus:

data Bar = forall a. Show a => Bar !a !a

But currently we get

Ignoring unusable UNPACK pragma on the first argument of ‘Bar’

Suggested by Nicholas Clarke here.

Vaguely related tickets: #7647, #9214. But unlike those ones, this one looks quite feasible to me.

Fixing this would require quite a bit of new plumbing. E.g. the existential type variable of the worker and wrapper would differ, which is not true today. But morally it's the Right Thing.

I'd be interested in actual use-cases.

Change History (6)

comment:1 Changed 4 years ago by vagarenko

Cc: vagarenko added

comment:2 Changed 4 years ago by thomie

Type of failure: None/UnknownRuntime performance bug

comment:3 Changed 3 years ago by simonpj

See also #1965

comment:4 Changed 19 months ago by simonpj

Description: modified (diff)
Keywords: DataCons added

comment:5 Changed 19 months ago by dfeuer

As far as I can tell, the only time this feature would be essential would be a situation where you want to unpack an existential and don't have access to its constructor. That makes the "killer app" a bit tricky to find. On the other hand, it would certainly support the sum-of-records pattern:

data Foo = This | That {-# UNPACK #-} !Bar
data Bar = Bar { ... }

This lets people use named fields in sum types without introducing partial functions. As it is, it won't be efficient if Bar has any existentials.

Last edited 19 months ago by dfeuer (previous) (diff)

comment:6 Changed 19 months ago by dfeuer

Cc: dfeuer added
Note: See TracTickets for help on using tickets.