From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1A9sgJ1013588 for ; Thu, 10 Feb 2011 10:54:42 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvAAAJREU03Nm0HimWdsb2JhbACXTAKLA4MaFQEBAQEBCAsKBxEkukGFXASFAYZ4gzg X-IronPort-AV: E=Sophos;i="4.60,451,1291590000"; d="scan'208";a="91030940" Received: from diamond.nps.edu ([205.155.65.226]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Feb 2011 10:54:36 +0100 Received: from virginia.nps.edu ([205.155.65.15]) by diamond.nps.edu with Microsoft SMTPSVC(6.0.3790.4675); Thu, 10 Feb 2011 01:54:33 -0800 Received: from Adric.ern.nps.edu ([172.20.216.170]) by virginia.nps.edu with Microsoft SMTPSVC(6.0.3790.4675); Thu, 10 Feb 2011 01:54:32 -0800 Received: by Adric.ern.nps.edu (Postfix, from userid 760) id E9EE817196; Thu, 10 Feb 2011 01:50:43 -0800 (PST) From: oleg@okmij.org To: la@iki.fi CC: caml-list@inria.fr Message-Id: <20110210095043.E9EE817196@Adric.ern.nps.edu> Date: Thu, 10 Feb 2011 01:50:43 -0800 (PST) X-OriginalArrivalTime: 10 Feb 2011 09:54:32.0827 (UTC) FILETIME=[84642CB0:01CBC908] Subject: [Caml-list] Re: Closure marshalling inconsistency Lauri Alanko wrote: > Marshalling closures with references to globals is precarious > business. Indeed. I would not blame OCaml though: OCaml serialization functions (when invoked with the right flags) ensure the preservation of sharing of components _within_ a serialized value. There are no guarantees about the preservation of sharing _between_ separately serialized values. The documentation explicitly says so: ``Sharing between values marshaled by successive calls to Marshal.to_channel is not detected, though.'' That is, if v1 and v2 share a component, the results of pickling/unpickling v1 and separately v2 may not share the component. If the preservation of that sharing is important, one could either serialize v1 and v2 together (that is, serialize the pair (v1,v2)), or declare the component whose sharing is important to be serialized by reference. The delimited control library delimcc provides the latter facility. It is used internally for serializing captured delimited continuations (which contain many closures, some containing important data whose sharing must be preserved). The facility can be used outside of delimcc. It consists of two functions, relativitize and absolutize, to call before serialization (resp, after deserialization) and the facility to declare the data whose sharing is to be preserved across separate serializations. The (long) title comments in the file delimcc.ml (the implementation of the delimcc library) describe this facility in detail. > Since the environment is marshalled by value and code is marshalled by > reference, this again makes an observable difference. I'd consider > this a bug. I might agree that this is a bug -- but not that it is a bug in OCaml. I might agree with the argument that it is a global mutable variable that is the bug, in programmer's code. Once we have serialization, we are smack in the realm of distributed computing. The notion of a _global_ variable becomes ill-defined. So called global mutable variables have always been evil; they become even more so in the distributed environment.