From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 27BBFBBCA for ; Fri, 29 Feb 2008 09:18:12 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANNOx0fAXQInh2dsb2JhbACQcQEBAQgKKZwg X-IronPort-AV: E=Sophos;i="4.25,425,1199660400"; d="scan'208";a="7841988" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Feb 2008 09:18:12 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1T8IBiF029616 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 29 Feb 2008 09:18:11 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANNOx0fBMVMQk2dsb2JhbACQcQEBAQEHBAYJIJwg X-IronPort-AV: E=Sophos;i="4.25,425,1199660400"; d="scan'208";a="7841986" Received: from minbis.univ-orleans.fr (HELO min.univ-orleans.fr) ([193.49.83.16]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Feb 2008 09:18:11 +0100 Received: from smtps.univ-orleans.fr (localhost [127.0.0.1]) by min.univ-orleans.fr (Postfix) with ESMTP id 84D4412B42E; Fri, 29 Feb 2008 09:18:10 +0100 (CET) Received: from [192.168.0.1] (lau18-1-82-246-197-195.fbx.proxad.net [82.246.197.195]) by smtps.univ-orleans.fr (Postfix) with ESMTP id E720B36E5B; Fri, 29 Feb 2008 09:18:10 +0100 (CET) Subject: Re: [Caml-list] Safe Obj.magic container ? From: David Teller To: Jacques Garrigue Cc: caml-list@inria.fr In-Reply-To: <20080229.105212.169552478.garrigue@math.nagoya-u.ac.jp> References: <37B36607-9F22-4537-B4DB-1E04348E2B90@inria.fr> <1204212586.11218.21.camel@Blefuscu> <20080229.105212.169552478.garrigue@math.nagoya-u.ac.jp> Content-Type: text/plain Date: Fri, 29 Feb 2008 09:18:09 +0100 Message-Id: <1204273089.6845.7.camel@Blefuscu> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 47C7BFC3.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; univ-orleans:01 variants:01 marshalling:01 untyped:01 cheers:01 univ-orleans:01 variants:01 non-uniform:01 non-uniform:01 annotations:01 untyped:01 lifo:01 persistant:98 liquidations:98 polymorphic:01 Thanks for the clarification. Again, I only have polymorphic variants, no functions, no floats, no lazy values, etc. The reason why I need to go through some Obj conversion is essentially the same reason safe marshalling needs to go through that conversion: storing typed information on an untyped medium (or, in this case, polymorphically typed information on a non-polymorphically typed medium) -- along with a type certificate. It just happens that this less-richly-typed medium is an exception. Cheers, David P.S.: I have tried alternative solutions but the best I can come up with involves something like 30% slowdown on my testsuite. Which is a bit too much for something which is supposed to be speed-critical. On Fri, 2008-02-29 at 10:52 +0900, Jacques Garrigue wrote: > From: David Teller > > > Interesting. Can I assume that, if my type is boxed (in this case, a > > polymorphic variant), I can successfully convert it to Obj.t and back ? > > Yes : polymorphic variants are either ints or normal blocks, so this > should work. This is also true for normal variants. Actually I don't > know of any non-uniform representation problem outside of floats. > > Note however that this problem of non-uniform representation is no the > only danger when using Obj.magic imprudently. I recall another problem > with functional values. I'm afraid only Xavier could explain that one. > > If you have only (polymorphic) variants, and if you keep the types > monomorphic (i.e. always add complete type annotations to Obj.magic or > Obj.obj), things should work properly in the current implementation. > > Of course you should limit that kind of uses to things like > persistant storage or C interfaces, where you have to go through an > untyped world anyway, and avoid it at all costs in plain ml programs. > > Jacques Garrigue > -- David Teller Security of Distributed Systems http://www.univ-orleans.fr/lifo/Members/David.Teller Angry researcher: French Universities need reforms, but the LRU act brings liquidations.