From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA09865 for caml-red; Thu, 2 Nov 2000 18:52:14 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA16013 for ; Wed, 1 Nov 2000 02:00:33 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eA110V105353 for ; Wed, 1 Nov 2000 02:00:32 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (isdnppp2.kurims.kyoto-u.ac.jp [130.54.16.103]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA01877; Wed, 1 Nov 2000 10:00:28 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.9.3/8.9.3) with ESMTP id JAA32051; Wed, 1 Nov 2000 09:44:35 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: ocaml to c variant hashes In-Reply-To: Your message of "Sun, 29 Oct 2000 19:13:08 -0800" <4.3.2.7.2.20001029184954.00a8e3b0@shell16.ba.best.com> References: <4.3.2.7.2.20001029184954.00a8e3b0@shell16.ba.best.com> X-Mailer: Mew version 1.93 on Emacs 20.4 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20001101094435H.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 01 Nov 2000 09:44:35 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Sender: weis@pauillac.inria.fr From: Chris Hecker > Hi, I'm looking at the lablGL stuff, and came across a utility that > computes the ocaml hash value for a given variant name. The > var2def.ml file in the package preprocesses a variables file and > outputs a C header with the appropriate hash values. The ml file > contains a function, hash_variant that does this hash, but that > function is copied from the source code to the compiler. This > doesn't seem like a very robust way to do this, since the internal > hash function could change at any time (in fact, the comment in the > code says hash_variant is from ctype.ml, but it's now in btype.ml). > > What's the right way to do this? I can think of 3 ways: > > 1. Like var2def.ml, and just hope the internal hash function doesn't change. This is the right way. You can consider this as "the definition" of how to hash a variant. Basically it only assumes that all ocaml architectures support 31-bit integers efficiently. As I do not see any risk of this becoming false, and as 32-bit architectures are still around for a while, there is no compelling reason to change it. Only if 32-bit architectures disappear, and ocaml support 63-bit integers everywhere, there could be a discussion of changing this hashing function, but I suppose this would be publicized enough. As to whether you should use var2def.ml, or use the C hash_variant function, this is basically a question of efficiency: I prefer preprocessing because runtime cost is null, and you can put the values in static tables. You can also use switch, but beware of code size with gcc. You can see lablgtk for how to have conversion functions that are both efficient and small. By the way, you can ignore copyright issues on var2def.ml/var2conv.ml: anyway you have to use them with ocaml, so feel free to modify and distribute under any name. Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG