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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 06EBB7EE9C for ; Thu, 1 Dec 2016 15:32:59 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=dmitry.bely@gmail.com; spf=Pass smtp.mailfrom=dmitry.bely@gmail.com; spf=None smtp.helo=postmaster@mail-qk0-f182.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dmitry.bely@gmail.com) identity=pra; client-ip=209.85.220.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dmitry.bely@gmail.com"; x-sender="dmitry.bely@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of dmitry.bely@gmail.com designates 209.85.220.182 as permitted sender) identity=mailfrom; client-ip=209.85.220.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dmitry.bely@gmail.com"; x-sender="dmitry.bely@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qk0-f182.google.com) identity=helo; client-ip=209.85.220.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dmitry.bely@gmail.com"; x-sender="postmaster@mail-qk0-f182.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AFTjlCBc3NjHv4p3PHSe7LewilGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc2zZx7h7PlgxGXEQZ/co6odzbGH6Oa8ACdbut7B6ClEK8McEUddyI?= =?us-ascii?q?0/pE8JPo2sMQXDNvnkbig3ToxpdWRO2DWFC3VTA9v0fFbIo3e/vnY4ExT7Mhdp?= =?us-ascii?q?dKyuQtaBx+z+7e25+oXSbgNUn3L9JOoqdFTlqATKrcgQjsNeDe4/yxbNrjMIIL?= =?us-ascii?q?wXlitGP1WWyjr559uq7dZJ/iBB86Yt8s9cS7S8dak8XJRXCT0nNyY+48i95kqL?= =?us-ascii?q?dheG+nZJCjZeqRFPGQWQqU6iUw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A1AQBSNEBYf7bcVdFdHAEBBAEBCgEBF?= =?us-ascii?q?wEBBAEBCgEBgw0BAQEBAYFxDAeINZwUiGKKCIIOggWGIgImgVsHQRIBAQEBAQE?= =?us-ascii?q?BAQEBARIBAQkLCwkbMoIzBAEVBYIOCQEBBBIRBBkBGx0BAwwGBQsNAgImAgIiA?= =?us-ascii?q?REBBQEcGSKFUIJgAQMXnUmBMj8yi1CBbBgFAR+DDQWDYAoZJw1UgzQBAQEHAh0?= =?us-ascii?q?CBhJ5hTOEW4dNEYJMBY9xim2BeI8YkDaNeoJIEx6BEyUHgSFEES+CaoILOzSHd?= =?us-ascii?q?IFPAQEF?= X-IPAS-Result: =?us-ascii?q?A0A1AQBSNEBYf7bcVdFdHAEBBAEBCgEBFwEBBAEBCgEBgw0?= =?us-ascii?q?BAQEBAYFxDAeINZwUiGKKCIIOggWGIgImgVsHQRIBAQEBAQEBAQEBARIBAQkLC?= =?us-ascii?q?wkbMoIzBAEVBYIOCQEBBBIRBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcGSKFUIJ?= =?us-ascii?q?gAQMXnUmBMj8yi1CBbBgFAR+DDQWDYAoZJw1UgzQBAQEHAh0CBhJ5hTOEW4dNE?= =?us-ascii?q?YJMBY9xim2BeI8YkDaNeoJIEx6BEyUHgSFEES+CaoILOzSHdIFPAQEF?= X-IronPort-AV: E=Sophos;i="5.33,282,1477954800"; d="scan'208";a="247659930" Received: from mail-qk0-f182.google.com ([209.85.220.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 01 Dec 2016 15:32:37 +0100 Received: by mail-qk0-f182.google.com with SMTP id x190so246182786qkb.0 for ; Thu, 01 Dec 2016 06:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=OpIWkM53XNiHFWunXMbhJTDXxvqf3aKQRCOMTjQDvXQ=; b=fN54tQAHBRfBYA2cOk26P/2qZSKRh/JyUHWhJOK5O625DA+N10XnAZKWrA4VTHEZ8s BezPe9cDcx9KP03rFTx5ZPRNR8VlE+vduJRs+59RuAMHLf35Vti+SPseg76xYqcsZMw7 OLLG/OdiZ4596ruDlkvZdydVE0zEx03xf8dg6TRhgDaI7rryjq3i9eb1t3RxG6g2cWmG F8E0ZHh0uxYnlZp9VgGO2I2VVMZfd/9WZQhRrXA9WiNupziNfErO+suTUrDmTKot9/xS v5qdnwVekWO9JDcB6EAZylvGmX+VhAXd68b9396gKdg9NMeUope6tw7UdcIdtXOIfJ9g 0VhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=OpIWkM53XNiHFWunXMbhJTDXxvqf3aKQRCOMTjQDvXQ=; b=U2Mj6oXt/LARcxb5A+YCBx/SazH6AHOShZhUBFLqkGb/2o5ZMLypUqdfQqDgaDphGb YqB3PrFiQgaCWMWAp9OOfa+vTr82Qs7SjBk9cHGupKNAo1wghvfI6/VCPEi4pVSiaAAg JPUealyEntNy8ZeIM4YIipQ97pTYRoacjAsRKFBKPQW3/pdtGoonk+q/GaLDQmpHac2n 4GOwXaxF1dc8HcwJGGzQ/RM6IwGvJvn+LlWS24o9YHwXH8SfpISxtqXLZu86n1aXNzcy Eqd5VfUMrS2bTxDs75BWedtVG52VuLqvtmDUQWhmuNviIxjSlWep3xqt2U4qO7eZ+0Lr ejQg== X-Gm-Message-State: AKaTC01CfVLhDNrnThftHhMxigf+zN3tHTVwK+eY0cw3EyKB+JQuMo2L/o0CkN65qk2oIh5NH1+5X2gTTBWbBw== X-Received: by 10.55.6.14 with SMTP id 14mr33792574qkg.167.1480602756086; Thu, 01 Dec 2016 06:32:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.173.164 with HTTP; Thu, 1 Dec 2016 06:32:35 -0800 (PST) In-Reply-To: <3f89d13a-14f0-090b-be96-d3f67fcb95f3@lexifi.com> References: <3f89d13a-14f0-090b-be96-d3f67fcb95f3@lexifi.com> From: Dmitry Bely Date: Thu, 1 Dec 2016 17:32:35 +0300 Message-ID: Cc: Caml List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] GADT memory representation On Thu, Dec 1, 2016 at 2:51 PM, Alain Frisch wrote: > On 01/12/2016 10:52, David Allsopp wrote: >> >> Dmitry Bely wrote: >>> >>> I need to access/modify GADT data from C glue code. What is their memory >>> representation? Is there any difference from ordinary sum types? >> >> >> It's the same - GADTs are "just" add a lot of clever typing stuff on top >> of a normal sum type - they don't affect the runtime operation of the code. >> >>> Unfortunately OCaml manual doesn't even mention GADTs in section >>> "Interfacing C with OCaml". >> >> >> That's worth a GPR/Mantis issue. > > > I'm not sure we want to document the memory layout of GADTs. I don't think > there are concrete plans to do so, but it might be considered to change the > representation of GADTs so that they cannot be used to compare values of > different types with the polymorphic comparison function. Today you can > write: > > type t = E: 'a -> t > > let () = assert(E 1 = E true) > > A similar "bad" behavior used to be available for exceptions and this was > "fixed" by changing their representation (their "slot" now has object_tag > and a (per process) unique id). We might want to do the same for GADTs (not > an easy decision since it would add a lot of overhead) and for first-class > modules as well. So if I need to return a GADT value for C code, what would be the best (working) option? Oversimplifying the problem, is it possible to implement the following safely w.r.t future runtime changes? type _ gadt = | Int : int -> int gadt | Float : float -> float gadt external get : unit -> 'a gadt = "get" - Dmitry Bely