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 CC63D8239C for ; Mon, 15 Jan 2018 11:35:14 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=leo@lpw25.net; spf=None smtp.mailfrom=leo@lpw25.net; spf=None smtp.helo=postmaster@out1-smtp.messagingengine.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of leo@lpw25.net) identity=pra; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="leo@lpw25.net"; x-sender="leo@lpw25.net"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of leo@lpw25.net) identity=mailfrom; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="leo@lpw25.net"; x-sender="leo@lpw25.net"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@out1-smtp.messagingengine.com) identity=helo; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="leo@lpw25.net"; x-sender="postmaster@out1-smtp.messagingengine.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A+i9YQhEsAjj7MkNUWAm8b51GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ79ocywAkXT6L1XgUPTWs2DsrQY07OQ6/iocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZr?= =?us-ascii?q?KeTpAI7SiNm82/yv95HJbAhEmCexbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+?= =?us-ascii?q?NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjD?= =?us-ascii?q?QhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VDK/5KlpVRDokj?= =?us-ascii?q?8KOT05/m/JhcN+g75UrhWvpxJizYDbYpqYNOZnfq7HYd8XX3ZNU8RXWidcAo28?= =?us-ascii?q?dYwPD+8ZMOhesYb9oEYFohu+BQmtGOPg1CJDi3jy3aIk1OQsCgXG3BQuHt4QsH?= =?us-ascii?q?nYttP1O7kOUe2syqTD0DbNb+tO1Dr86YXEaA0treyRUb5qfsfd01cjGgPDg16N?= =?us-ascii?q?s4LqJSmV2f4Is2WD7+pvS+avi2k/pgF2vziv2toghpDShoIQ1lDE7T91wIMrKt?= =?us-ascii?q?2jU050e9GkEJpWtyGVKYR2RMwiQ2BuuCkk0LEJpZm7fC0SxJQmwR7QdeCHfpCJ?= =?us-ascii?q?7x/iTuqdPCp0iG9/dL+wnRq+70itxvX5Vsau0VZKqiRFksPLtnAIzxHT7taISv?= =?us-ascii?q?xm80elwTaO2R7f5+FeLUAyi6XbN4YtwqQsmZoLrUTDAij2lV3qg6CMc0Uk/vGk?= =?us-ascii?q?6+DmYrX9up+RLJR0iwH7MqQ2gMOzG+U4Mg4UX2ia4+uwzrPj/VeqCIlN2/Y/l6?= =?us-ascii?q?2ctJHBOewaoLS4CklbyNUN8RG6WhOr15wnnXgbIRoRfB+Ap4zxJAuTZvb1EaHs?= =?us-ascii?q?0ByXjD53yqWebfXaCZLXIy2byeazTfNG80dZjTEL45Va7pNQBKsGJauqCEvpq4?= =?us-ascii?q?aFSBk0L17smrq1OJBGzoobHFm3LOqBKqqL6A2M/v11fq+KaZNH4G+gechg3Obn?= =?us-ascii?q?iDoCoXFYfaSt2sBOOnelAq0jOECFeTzpj8waGGgLuAUzSuPrjlDEWjlWNS6/?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CTDQBIg1xahxkEb0JdHAEBAQQBAQoBA?= =?us-ascii?q?YUbJ4QTixiNaYFbJ5ctghUKhTsChE1IDwEBAQEBAQEBAQESAQEBCA0JCCgvgjg?= =?us-ascii?q?igkoBAgIBIx0BATgECwsaAiYCAiwbEIpECKsmboIngwoBAQWFXIFGAQEIAQEBA?= =?us-ascii?q?RwIgQ+DLYIVg0A1gnmFboJLMYI0k0GQJwGpW5clgTxIAYFfTC4KPYIqgkUfghE?= =?us-ascii?q?jN4w7AQEB?= X-IPAS-Result: =?us-ascii?q?A0CTDQBIg1xahxkEb0JdHAEBAQQBAQoBAYUbJ4QTixiNaYF?= =?us-ascii?q?bJ5ctghUKhTsChE1IDwEBAQEBAQEBAQESAQEBCA0JCCgvgjgigkoBAgIBIx0BA?= =?us-ascii?q?TgECwsaAiYCAiwbEIpECKsmboIngwoBAQWFXIFGAQEIAQEBARwIgQ+DLYIVg0A?= =?us-ascii?q?1gnmFboJLMYI0k0GQJwGpW5clgTxIAYFfTC4KPYIqgkUfghEjN4w7AQEB?= X-IronPort-AV: E=Sophos;i="5.46,363,1511823600"; d="scan'208";a="309076093" Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 11:34:59 +0100 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2EDF420B4D for ; Mon, 15 Jan 2018 05:34:57 -0500 (EST) Received: from web1 ([10.202.2.211]) by compute5.internal (MEProxy); Mon, 15 Jan 2018 05:34:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lpw25.net; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=WtwmGXVIqWyShRyIyZAB2mpKzy 63P0rbtCPOWzF3mkE=; b=L+Tbo9sg4bSywW1Mx2rUw+/HMxFJiH3pSyUCLQ1dNT TuXK6+e+tBRPmwSZ5duq0rjyAPtUInfISNBAet5ryONt5FBE+vCrRDTl5GtUBmKM SH+ufA3CgKooSDwgpBVo0AUF4KnX8CdUAZG4TU5VvF4YGAMh/+SuBoCRVXz3z4HV s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=WtwmGX VIqWyShRyIyZAB2mpKzy63P0rbtCPOWzF3mkE=; b=buLsOwZCdMSOZ+mYO2Qv02 cvroTOaifzTZdUZmxd0RcN/PpU8ietD7NmVJzeiZtjCdoXveMSSFHGnVCyRnHiBV OuQaV5pUH2wlrZTvMKi4jCMZ1xgs0xqeIsa1rnbQt+cBTfmNom2jOdc+a1moPGRh Rx2VWH8905waYXa05b3xsKcmA0EK39RtnpkKlaGTcz7A0Xi4iEblrBVs3sBr/by+ iPd4jCPm2dR5GxYH+rigw7zhc5aguuoos2bv0JO09zHJEg39WrLnRSVND7TpLmq8 huDvTVEZSWmU4LkKZHRy4zvW1P0benHoqZl+S10tYvrAxDLu6vk6ibpZRyEUA7zQ == X-ME-Sender: Received: by mailuser.nyi.internal (Postfix, from userid 99) id 1195F9420D; Mon, 15 Jan 2018 05:34:57 -0500 (EST) Message-Id: <1516012497.2168791.1235601456.5B7510E5@webmail.messagingengine.com> From: Leo White To: caml-list@inria.fr MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-75de3051 References: <1515782196.604079108@f381.i.mail.ru> <937c674a-bf63-b2be-44eb-9ad331aa622f@ocamlpro.com> Date: Mon, 15 Jan 2018 05:34:57 -0500 In-Reply-To: <937c674a-bf63-b2be-44eb-9ad331aa622f@ocamlpro.com> Subject: Re: [Caml-list] flambda for bytecode backend > The best we could do (without doing some magic) would look like: >=20 > let f x =3D > =C2=A0 let y =3D x + 1 in > =C2=A0 let g z =3D z + y in > =C2=A0 g >=20 > compiled to: >=20 > function f_code(x, env) { > =C2=A0 let y =3D x + 1; > =C2=A0 function g_code(y, env) { > =C2=A0=C2=A0=C2=A0 return(z + env.y); > =C2=A0 } > =C2=A0 let g =3D { code : g_code, env : { y: y }; > =C2=A0 return(g); > } >=20 > let f =3D { code : f_code, env : { } } Pierre is right about the reason we don't use flambda with bytecode, although I don't think that is the best JavaScript we could produce. It would not be to difficult to undo closure conversion within the function body itself. This still leaves references to the closure outside of the function body. These aren't shown in Pierre's example but they are produced during inlining and are the main thing that flambda uses which bytecode doesn't support. For these we can take advantage of the fact that JavaScript functions are also ordinary objects, attaching the environment to the function as fields: function f(x) { let y =3D x + 1; function g(z) { return(z + y); } g.y =3D y; return(g); } Of course, this could still have an adverse effect on how the JIT of different browsers deals with these functions, so some benchmarking would be needed to confirm the viability of this approach. Regards, Leo