From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id BF2127EE20 for ; Mon, 19 Nov 2012 18:49:57 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of darioteixeira@yahoo.com) identity=pra; client-ip=98.138.90.88; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of darioteixeira@yahoo.com) identity=mailfrom; client-ip=98.138.90.88; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@nm25.bullet.mail.ne1.yahoo.com) identity=helo; client-ip=98.138.90.88; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="postmaster@nm25.bullet.mail.ne1.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AisBAPJwqlBiilpYk2dsb2JhbAA4BAMGsCWTHSMBAQEBCQkLCRQDJIIZFxwEFQECFSIBFHoBDgEGGIgNAQECDwSebI8iCYJvhGMBIwMBIwOJVwEGCgEBjDkVhGcDiFqNKYVkLVCIEGyDbw X-IronPort-AV: E=Sophos;i="4.83,280,1352070000"; d="scan'208";a="163039494" Received: from nm25.bullet.mail.ne1.yahoo.com ([98.138.90.88]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Nov 2012 18:49:33 +0100 Received: from [98.138.90.52] by nm25.bullet.mail.ne1.yahoo.com with NNFMP; 19 Nov 2012 17:49:31 -0000 Received: from [98.138.89.164] by tm5.bullet.mail.ne1.yahoo.com with NNFMP; 19 Nov 2012 17:49:31 -0000 Received: from [127.0.0.1] by omp1020.mail.ne1.yahoo.com with NNFMP; 19 Nov 2012 17:49:31 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 613185.28682.bm@omp1020.mail.ne1.yahoo.com Received: (qmail 78824 invoked by uid 60001); 19 Nov 2012 17:49:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1353347369; bh=u5wcTuYpTShBF1J16bIj0PMWuyl/vHPC+75AymETRCw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=d1T9Y3Vg3jOW+Fp+WbOG/RNKmL1MQyGibjk1Sg9Puy4eG8ISQrHPKK+6My8KGj7xvHFuT7LJpYP/wNI1OqSI0gqwo2ynAV82rqsKTKQ87sv2R54DMUr0YEUBsTWRctvdsAvxmK69pNFeH3ViXuUnYjZYGHQhoV41vm56JCDml70= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=t6i+kh9PqHR8uSwww08aoAkBnRm5GcWq7ojBS/gPtCv/P15SDg379IjoPgja+RudddeYaasSOTvW1ynQXlmETT63XDbZoy7zjQZ6FPu/wSZ6GVn5UXqITYaBdCRuZDZiCA9ZjPT2Mp/sCM5c2C5u7ITFoQCzmb4O5J+TptBuA9o=; X-YMail-OSG: SVsDrkMVM1m4FHVxK3h7Ba0.jc23GYVXytLx6L7MCYKjHrc p_UBr..RmbsVp.P58btSKqaNRPgp1F4xik3mZzHJADUG54H3lZ66fKOLmOHa kfzsyYa6zu3cFPtUe9pMd4zdZ493o0NvchOhBW4biQPnFf9n8i9ZejWIy6lj saXSXRj6XDTMVzsOylrpK.9Z2hfAa.BxBUeknf78Fw04COmi6hWXjtXVCn5x rTg68l8RNMqxlBeqJSddmua60_d53SwHZ0ds5k4Mcnm5h_KLJwHkYAOeq1sW PSMRdwDeC0WgYnqMXknTTxhWEstMGrHUOKdMqiAoHkZs0mfO52Yo4CbnvKOV xn9HJFPyi7w6xTR0cTGeXsNVKwXtP10Rs09To14cMGTzlHdHJsbd8IhniaAi AaekWpFfmWpHT7NiXIMkTcPoEdbzWJOzsEoo.9Hzlb.dKudLcnrWEB4CwYB2 Lk4.fig6OurTwPH8c8EwnUvMWnr5MrDVsK8euTVWrqjDQSUpi75gmXjDAeIW qXrFv Received: from [195.23.39.71] by web111510.mail.gq1.yahoo.com via HTTP; Mon, 19 Nov 2012 09:49:29 PST X-Rocket-MIMEInfo: 001.001,SGksCgoKSSd2ZSBmb3VuZCBjb25mbGljdGluZyBpbmZvcm1hdGlvbiByZWdhcmRpbmcgdGhlIHVzZSBvZiAiJWlkZW50aXR5IiwKd2hpY2ggSSBob3BlIHRvIHNlZSBjbGFyaWZpZWQuCgpMZXQncyBjb25zaWRlciBhIHR5cGljYWwgZXhhbXBsZSB3aGVyZSBhIG1vZHVsZSBkZWZpbmVzIGFuIGFic3RyYWN0CnR5cGUgdCBhbmQgcHJvdmlkZXMgKGRlKXNlcmlhbGlzYXRpb24gZnVuY3Rpb25zIG9mX3N0cmluZy90b19zdHJpbmcuCk1vcmVvdmVyLCB0aGUgYWN0dWFsIGltcGxlbWVudGF0aW9uIG9mIHQgdXNlcyABMAEBAQE- X-Mailer: YahooMailWebService/0.8.126.470 Message-ID: <1353347369.78785.YahooMailNeo@web111510.mail.gq1.yahoo.com> Date: Mon, 19 Nov 2012 09:49:29 -0800 (PST) From: Dario Teixeira Reply-To: Dario Teixeira To: OCaml mailing-list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: [Caml-list] The verdict on "%identity" Hi, I've found conflicting information regarding the use of "%identity", which I hope to see clarified. Let's consider a typical example where a module defines an abstract type t and provides (de)serialisation functions of_string/to_string. Moreover, the actual implementation of t uses a string, and the (de)serialisation functions are just identities: =A0 module Foo: =A0 sig =A0=A0=A0=A0=A0=A0=A0 type t =A0=A0=A0=A0=A0=A0=A0 val of_string: string -> t =A0=A0=A0=A0=A0=A0=A0 val to_string: t -> string =A0 end =3D =A0 struct =A0=A0=A0=A0=A0=A0=A0 type t =3D string =A0=A0=A0=A0=A0=A0=A0 let of_string x =3D x =A0=A0=A0=A0=A0=A0=A0 let to_string x =3D x =A0 end In practice, it's not unusual for such code to be implemented using the compiler's "%identity" builtin, all in the name of performance: =A0 module Foo: =A0 sig =A0=A0=A0=A0=A0=A0=A0 type t =A0=A0=A0=A0=A0=A0=A0 external of_string: string -> t =3D "%identity" =A0=A0=A0=A0=A0=A0=A0 external to_string: t -> string =3D "%identity" =A0 end =3D =A0 struct =A0=A0=A0=A0=A0=A0=A0 type t =3D string =A0=A0=A0=A0=A0=A0=A0 external of_string: string -> t =3D "%identity" =A0=A0=A0=A0=A0=A0=A0 external to_string: t -> string =3D "%identity" =A0 end I realise that the use of "%identity" is dangerous.=A0 This is, after all, how Obj.magic is defined.=A0 Moreover, it uglifies interface definitions and makes a ridicule of the abstraction.=A0 However, on the assumption that ocamlopt won't otherwise optimise away the no-op across module boundaries, the use of "%identity" may well be justified for performance reasons. With all the above in mind, I have two questions: 1) Is the assumption correct that today's ocamlopt won't optimise no-ops =A0=A0 across module boundaries? (I know that ocamlopt does not generally e= ngage =A0=A0 in MLton-style whole programme optimisation, but is this also true f= or =A0=A0 low-hanging fruit such as the first example above?) 2) Consider the code below.=A0 For which modules can one expect of_string c= alls =A0=A0 to be optimised across module boundaries? =A0 module type SIG1 =3D sig type t val of_string: string -> t end =A0 module type SIG2 =3D sig type t external of_string: string -> t =3D "%i= dentity" end =A0 module Impl1 =3D struct type t =3D string let of_string x =3D x end =A0 module Impl2 =3D struct type t =3D string external of_string: string ->= t =3D "%identity" end =A0 module A: SIG1 =3D Impl1 =A0 module B: SIG1 =3D Impl2 =A0 module C: SIG2 =3D Impl1 =A0 module D: SIG2 =3D Impl2 Thank you in advance for your time! Best regards, Dario Teixeira