From b6ed8e7c95e4f159f011a488316d473798a33195 Mon Sep 17 00:00:00 2001 From: sewardj Date: Thu, 7 Feb 2002 16:11:42 +0000 Subject: [PATCH] [project @ 2002-02-07 16:11:42 by sewardj] Describe ultrakludge^Hclever engineering which makes IO types work in the interpreter. --- ghc/docs/comm/the-beast/ghci.html | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/ghc/docs/comm/the-beast/ghci.html b/ghc/docs/comm/the-beast/ghci.html index 5ee2f21..b893acd 100644 --- a/ghc/docs/comm/the-beast/ghci.html +++ b/ghc/docs/comm/the-beast/ghci.html @@ -342,9 +342,10 @@

We therefore employ a second family of magic infotables, indexed, like the first, on the return representation, and therefore with - names of the form stg_itoc_ret_REP_info. This is - pushed onto the stack (note, tagged values have their tag zapped), - giving: + names of the form stg_itoc_ret_REP_info. (Note: + itoc; the previous bunch were ctoi). + This is pushed onto the stack (note, tagged values have their tag + zapped), giving:

    |        |
    +--------+
@@ -364,7 +365,37 @@
     return register, and returns to the itbl to which we were trying
     to return in the first place.  
     

- Amazingly enough, this stuff all actually works! + Amazingly enough, this stuff all actually works! Well, mostly ... +

+ Unboxed tuples: a Right Royal Spanner In The Works +

+ The above scheme depends crucially on having magic infotables + stg_{itoc,ctoi}_ret_REP_info for each return + representation REP. It unfortunately fails miserably + in the face of unboxed tuple returns, because the set of required + tables would be infinite; this despite the fact that for any given + unboxed tuple return type, the scheme could be made to work fine. +

+ This is a serious problem, because it prevents interpreted + code from doing IO-typed returns, since IO + t is implemented as (# t, RealWorld# #) or + thereabouts. This restriction in turn rules out FFI stuff in the + interpreter. Not good. +

+ Although we have no way to make general unboxed tuples work, we + can at least make IO-types work using the following + ultra-kludgey observation: RealWorld# doesn't really + exist and so has zero size, in compiled code. In turn this means + that a type of the form (# t, RealWorld# #) has the + same representation as plain t does. So the bytecode + generator, whilst rejecting code with general unboxed tuple + returns, recognises and accepts this special case. Which means + that IO-typed stuff works in the interpreter. Just. +

+ If anyone asks, I will claim I was out of radio contact, on a + 6-month walking holiday to the south pole, at the time this was + ... er ... dreamt up. +

-- 1.7.10.4