
http://hackage.haskell.org/trac/ghc/ticket/2532 Discussion deadline: Sept 7 Jim

Jim Apple wrote:
http://hackage.haskell.org/trac/ghc/ticket/2532
Discussion deadline: Sept 7
I believe that the combination of this instance, the behaviour of Data.Unique, and the behaviour of hs-plugins is broken. In particular, as I understand the behaviour of hs-plugins, it is already possible to generate Unique values inside a plugin that conflict with Unique values generated in the main program, and this instance will allow those values to be passed across the plugin boundary. It's not clear to me what is to blame here. hs-plugins does something dodgy, in that it hacks the behaviour of Data.Typeable instances so that the same types get identical instances on both sides of the plugin boundary. Data.Unique is doing something dodgy by using a global variable. (There's a long discussion about this on haskell-café at the moment.) The combination is what leads to the brokenness. I will test this to confirm as soon as I can, but as the deadline is approaching I thought I should raise the issue immediately. Cheers, Ganesh ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================

On Fri, Sep 5, 2008 at 5:23 AM, Sittampalam, Ganesh
(There's a long discussion about this on haskell-café at the moment.)
I tried to find this thread (by searching for "unique" and "plug" on http://www.haskell.org/pipermail/haskell-cafe/ ), but couldn't. What is the subject line? Thanks, Jim

On 2008 Sep 7, at 11:13, Jim Apple wrote:
On Fri, Sep 5, 2008 at 5:23 AM, Sittampalam, Ganesh
wrote: (There's a long discussion about this on haskell-café at the moment.)
I tried to find this thread (by searching for "unique" and "plug" on http://www.haskell.org/pipermail/haskell-cafe/ ), but couldn't. What is the subject line?
"Top-level <-" -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

I'm afraid I haven't time to read the whole thread and come up with a
good answer about whether or not adding Typeable to Data.Unique is
dangerous.
Given that, I'm no longer, er, proposing this proposal.
Jim
On Sun, Sep 7, 2008 at 9:26 AM, Brandon S. Allbery KF8NH
On 2008 Sep 7, at 11:13, Jim Apple wrote:
On Fri, Sep 5, 2008 at 5:23 AM, Sittampalam, Ganesh
wrote: (There's a long discussion about this on haskell-café at the moment.)
I tried to find this thread (by searching for "unique" and "plug" on http://www.haskell.org/pipermail/haskell-cafe/ ), but couldn't. What is the subject line?
"Top-level <-"

Sorry, I didn't intend to scare you into submission. I'm not even necessarily opposing this proposal, just warning of some consequences.
I'll try to summarise the issue below. The linked thread isn't of all that much relevance except in that it led to me realising that this issue probably exists.
Data.Unique uses a "top-level global variable" (an IORef) as a counter for the Integer underlying Unique values. This is initialised to 0 via a {-# NOINLINE -#} unsafePerformIO the first time it is needed.
If you load something via hs-plugins, any modules it uses are loaded into the process, even if they are already loaded via the static part of the program. This only happens once, i.e. the most copies of the module you can end up with is two - although another dynamic loading architecture might well do something different.
So any Unique values created in the plugin will be created with the counter starting from 0 again, so will collide with any Unique values created in the static part of the process.
hs-plugins uses special knowledge of how Data.Typeable works (another global variable!) to ensure that the "same" types have the same type reps in both the static and dynamic sides of the process.
So, adding Data.Typeable to Unique will allow these colliding Unique values to be passed between the static and dynamic sides, causing two separately generated Unique values to potentially compare equal.
As I said in my original comment, it could well be reasonable to blame hs-plugins for hacking around with Typeable instances. On the other hand, it's hard to see what else it can do if people are to actually use plugins from the main process, and Data.Unique is clearly using an unsafe hack. (In the thread referred to below, I'm mainly opposing the formalisation of that hack into the top-level <- operation.)
It doesn't really strike me as the end of the world if a module that is already doing something dodgy turns out to be broken in the dynamic loading world, as long as people are aware of this. Presumably the Typeable instance will be useful for many things other than dynamic loading.
Any further questions, please do ask. Also, Brandon or someone else who is in favour of top-level <- might be able to cast what Data.Unique is doing in a more positive light :-)
I've been trying to build a recent GHC HEAD and then hs-plugins (hackage package "plugins") all weekend so I can try this out for real, but haven't got far enough yet.
Ganesh
-----Original Message-----
From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Jim Apple
Sent: 07 September 2008 17:55
To: libraries@haskell.org
Subject: Re: #2532: Add Typeable instance to Data.Unique
I'm afraid I haven't time to read the whole thread and come up with a good answer about whether or not adding Typeable to Data.Unique is dangerous.
Given that, I'm no longer, er, proposing this proposal.
Jim
On Sun, Sep 7, 2008 at 9:26 AM, Brandon S. Allbery KF8NH
On 2008 Sep 7, at 11:13, Jim Apple wrote:
On Fri, Sep 5, 2008 at 5:23 AM, Sittampalam, Ganesh
wrote: (There's a long discussion about this on haskell-café at the moment.)
I tried to find this thread (by searching for "unique" and "plug" on http://www.haskell.org/pipermail/haskell-cafe/ ), but couldn't. What is the subject line?
"Top-level <-"
Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================
participants (3)
-
Brandon S. Allbery KF8NH
-
Jim Apple
-
Sittampalam, Ganesh