Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k9Zz3-0005hj-9t for pljava-dev@arkaria.postgresql.org; Sat, 22 Aug 2020 20:19:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k9Zz2-0006J3-97 for pljava-dev@arkaria.postgresql.org; Sat, 22 Aug 2020 20:19:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k9Zz2-0006Ia-47 for pljava-dev@lists.postgresql.org; Sat, 22 Aug 2020 20:19:24 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k9Zyz-0004Oh-SX for pljava-dev@lists.postgresql.org; Sat, 22 Aug 2020 20:19:23 +0000 Received: by mail-ej1-x62e.google.com with SMTP id oz20so1958396ejb.5 for ; Sat, 22 Aug 2020 13:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ACwiX6SkChrVRviDP0Hkk4Xu1hUfWgwnd9w5z5cJMRo=; b=seRSz9HadmzeHpTDwUjMI9l/hKEUjkNjoiDBFo+M88USwSdBKD5+PO6qzgfF03g6nn jzzOCVmiEMbZnodE4HVtuP8IUay9eIUS6Qa7eDgiGS8JHCabEEY861Zo2oimtWgC8a46 FnDHEYwvzpTeqGtPgDE/gliiDwoD8pXDvDgAgGWXOONwp5R5zSON1gBR5sr+V5MHRHOb 8t7qYMjutnSB/xMkx69poDIkdu9XEiDj+nzp0X/5F6SZkqm3YiTObHooJ4KRFVppQmv2 Y/OH266vsFskin8b8pgQW7Ltbt8usC8rxe1MAyoptFR/sqPYxYYeig4ja5yhl1XGbKCs uNSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ACwiX6SkChrVRviDP0Hkk4Xu1hUfWgwnd9w5z5cJMRo=; b=T1FfBrAw8G9lKHW//gICNa+buETCRxeK0AswVTGMwj/WpCr9loz6YPMrV0/G3jmeGD 8ykWB+8bAYLgu9w98UGJYi8EJe7SKcBjKGAY2BLsuWAIop4mTwytaEXhFCb+eE68ILea FMAyeI9FaAjmZm7fqk+Dzo5kxxzet/Gh//H62afYIh6bTqomxbjagO6L8Tx3U2zJRyR4 t7H651+6GiiGZRGwUssrtGp9dXjun8L/5JV7Q9KdCiIZ36sat6xEsEG6TRwCscjLyI4D vvvLURiXtDHT1GWpjPN0HmUFEMsUHOaP/5KBXhw1bGioWrY2Hk083cDMj08RdcW6GgAC NGcg== X-Gm-Message-State: AOAM531/pk4dClJupAyv5YTr2Ph8+5hkEH74bc3aJ9rJVa7M3D+35kkJ XIJrNYrUf4HeNfDsjO/OXLMyYaUvZLOBetGnA20= X-Google-Smtp-Source: ABdhPJzkx2uoUknoc7XkWg6jl7zIPgV58VwIsuh/ixD+mag/1Z18jPGGEiRWceT775pSXKFhGL4WIHnPCnyglmzZ56E= X-Received: by 2002:a17:906:c310:: with SMTP id s16mr8813922ejz.466.1598127559604; Sat, 22 Aug 2020 13:19:19 -0700 (PDT) MIME-Version: 1.0 References: <5F2EC4F4.3080608@anastigmatix.net> <5F31EFEC.1080609@anastigmatix.net> <5F368380.9070203@anastigmatix.net> <5F368A99.6070709@anastigmatix.net> <5F36965C.60707@anastigmatix.net> <5F3A7DC6.8090905@anastigmatix.net> <5F3D32E9.80504@anastigmatix.net> <5F3D36BE.70703@anastigmatix.net> <5F3D38F8.7050907@anastigmatix.net> <5F3D3A75.5010304@anastigmatix.net> <5F3D3D2E.4070109@anastigmatix.net> <5F3D43BD.4020900@anastigmatix.net> <5F3DA48D.7090408@anastigmatix.net> <5F4172F9.4060608@anastigmatix.net> <5F417C68.50702@anastigmatix.net> In-Reply-To: <5F417C68.50702@anastigmatix.net> From: Kartik Ohri Date: Sun, 23 Aug 2020 01:49:08 +0530 Message-ID: Subject: Re: the ScriptingMojo To: Chapman Flack Cc: pljava-dev@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000007efd1d05ad7d1133" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000007efd1d05ad7d1133 Content-Type: text/plain; charset="UTF-8" On Sun, Aug 23, 2020 at 1:43 AM Chapman Flack wrote: > On 08/22/20 15:33, Chapman Flack wrote: > > Ok, I removed the parallel() and now graal also complains about the SAM > > cast. This puzzles me because I thought both engines were intended to > > support that, so I'll keep playing with it a bit. > > If I make the attached changes, both nashorn and graal seem to be happy. > > It appears that, when invoking a method /of a Java object/, they > recognize when its parameter type is a SAM interface, and do the magic > to present a JavaScript function as an implementation of that. > > We might just be asking for too many layers of magic when we start by > binding a Java lambda into the script engine (which probably wraps one > layer of magic over it to make it look like a JS function), and then try > to pass a JS function as a parameter needing its own magic wrapping to > appear as a Java SAM interface, and the engine may not see through the > first layer of magic to realize it needs to add the second. > > "Thing" as a class name is just proof-of-concept of course. :) I had > been wondering earlier if it might be useful to make PGXSUtils instantiable > and bind an instance of it into the script; its constructor could take the > MavenProject and Log and those wouldn't have to be passed around as much. > It would still be possible to bind selected methods of it directly with > names of their own for convenience, but other methods could just be > accessible as utils.method() and I think that would solve this casting > issue. > > Regards, > -Chap > Sounds good to me. I'll make the changes to the PGXSUtils class. Regards, Kartik --0000000000007efd1d05ad7d1133 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Aug 23, 2020 at 1:43 AM Chapman F= lack <chap@anastigmatix.net= > wrote:
On 08/22/20 15:33, Chapman Flack wrote:
> Ok, I removed the parallel() and now graal also complains about the SA= M
> cast. This puzzles me because I thought both engines were intended to<= br> > support that, so I'll keep playing with it a bit.

If I make the attached changes, both nashorn and graal seem to be happy.
It appears that, when invoking a method /of a Java object/, they
recognize when its parameter type is a SAM interface, and do the magic
to present a JavaScript function as an implementation of that.

We might just be asking for too many layers of magic when we start by
binding a Java lambda into the script engine (which probably wraps one
layer of magic over it to make it look like a JS function), and then try to pass a JS function as a parameter needing its own magic wrapping to
appear as a Java SAM interface, and the engine may not see through the
first layer of magic to realize it needs to add the second.

"Thing" as a class name is just proof-of-concept of course. :) I = had
been wondering earlier if it might be useful to make PGXSUtils instantiable=
and bind an instance of it into the script; its constructor could take the<= br> MavenProject and Log and those wouldn't have to be passed around as muc= h.
It would still be possible to bind selected methods of it directly with
names of their own for convenience, but other methods could just be
accessible as utils.method() and I think that would solve this casting
issue.

Regards,
-Chap

Sounds good to me. I'll make = the changes to the PGXSUtils class.=C2=A0
Regards,
Kart= ik
--0000000000007efd1d05ad7d1133--