Opened 6 years ago

Closed 6 years ago

#4936 closed feature request (duplicate)

Unbox sum types without fields

Reported by: tibbe Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.1
Keywords: Cc: johan.tibell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In the new I/O manager we use newtyped Ints instead of an ADT to squeeze out every drop of performance GHC can give us. It's a bit unfortunate that we have to make a choice between performance and safety here. Using an ADT have many benefits. For example, all possible values are grouped together neatly under the data type and the compiler can make sure we check all possible cases in case statements.

Pointer tagging helps quite a bit here, if you have fewer than 4 (or 8) constructors. If you have more you don't get the benefit.

Given a simple sum type like this:

data Color = Red | Green | Blue | Yellow

change its representation to an Int, allowing it to be unboxed into data types.

Change History (3)

comment:2 Changed 6 years ago by simonpj

Can you give a small program that doesn't optimise as well as you'd like, and a hand-optimised version that does better?

Concerning #2289, unboxing a pure enumeration (as you propose here) is much easier than unboing a general sum type such as lists (which is what Don's comment in #2289 asked for). In any case, #2289 is largly about another issue (nested CPR).


comment:3 Changed 6 years ago by simonmar

Resolution: duplicate
Status: newclosed

Duplicate of #605.

Note: See TracTickets for help on using tickets.