[Haskell-cafe] What code is generated for binary functions of data types with multiple constructors?

Clinton Mead clintonmead at gmail.com
Wed Aug 2 12:05:44 UTC 2017


Assume the following:

1. We have a type T with multiple constructors, but lets assume we're on a
64 bit machine and have at least 4 but no more than 7 constructors so we
can still use pointer tagging.
2. And a function "f :: T -> T -> T"
3. Each combination of constructors (16 in the 4 constructor case, 49 in
the 7 constructor case) has an implementation (naturally many of these will
call helper functions). There's no wildcard matches.

How will GHC generate the code for "f"? Will pushing through LLVM make any
difference?

Do we take the number of the first constructor, and then multiply the
number of the second constructor by say 7, and then do one jump via a jump
table?

Is there a bunch of nested jump tables, each with 7 options?

Is there a fall through if statement?

Something else?

I understand this probably a complex answer and perhaps doesn't have a
simple answer, but I just wanted to get some sort of idea in my head of how
GHC attempts to resolve code like this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170802/9c9e8b99/attachment.html>


More information about the Haskell-Cafe mailing list