From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6117B4405A1; Tue, 6 Jun 2023 15:55:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6117B4405A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1686056132; bh=uQ/dp7MvwIZVikgkvQIJHkRmckAGjrnmCTQ+MZ+dMFI=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kepB5yugGwnaYShZZiXQz0lhkb4E/FJ/5+yxxtdf8UjeD/9JF439m26896zLrE6FS GHbbb4sDRiWQ+2rmgOs5PB0FWe1YfSZeiM5xuzCpd9pEfaj0FAvnmiUg3wNck0RphN bWoIvwnYUx0hW7K+JeDYzf1dXaXQe7N8PmH5n0ZI= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [95.163.41.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 3B9AF4405A1 for ; Tue, 6 Jun 2023 15:55:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B9AF4405A1 Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1q6WDi-004XHf-BI; Tue, 06 Jun 2023 15:55:30 +0300 Date: Tue, 6 Jun 2023 15:51:20 +0300 To: Sergey Bronnikov Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD93D74B10BAB639DE3EAF656F193F0678BFC1635858165C9A800894C459B0CD1B90C7C287DD22B00C77E7E2C6892887DF7B46696C49472843DC1F8F9D846F8CF10 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72E4E5201E1C2E308EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063750AD27396E031BA88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8599B52019BD74416E616871123F5814C117882F4460429728776938767073520F8AB6B2BE2218126117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFC1F32E4020076F7EBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6455B07CE27F2DB4F76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C468D16C903838CAB43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A534AFEE5582F53896ADBC07FB667505D41F79607B46EEC0BDF87CCE6106E1FC07E67D4AC08A07B9B0DB8A315C1FF4794DBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF12726C73063A20E195F3CC64606D51C38484321B9A8AF1E8D15E2A99E82F0BA56BD4E2D2DF3D4047588A46A5EBCE8E374A6B70838ED063DF30B6DA1AD897D1E1A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojBFnFgsoZgk6s3KG37A+fHw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7692B1FD1060CC79C202499BD13B954694CD776CA2DFBE07C79DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v1] Fix BC_UCLO insertion for returns. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! Please, consider my comments below. On 30.05.23, Sergey Bronnikov wrote: > From: Sergey Bronnikov > > Contributed by XmiliaH. > > (cherry-picked from commit 93a65d3cc263aef2d2feb3d7ff2206aca3bee17e) > > After emitting bytecode instruction BC_FNEW fixup is not required, > because FuncState will set a flag PROTO_CHILD that will trigger emitting > a pair of instructions BC_UCLO and BC_RET (see ) > and BC_RET will close all upvalues from base equal to 0. This part describes why replacing UCLO with FNEW is good enough and better than just deleting | case BC_UCLO: return; But the original problem is that some of BC_RET are not fixup-ed, due to early return, if UCLO is obtained before, those leads to VM inconsistency after return from the function. Please, mention this too. > > Sergey Bronnikov: > * added the description and the test for the problem > > Signed-off-by: Sergey Bronnikov > Co-authored-by: Sergey Kaplun > --- > Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-819-fix-missing-uclo > PR: https://github.com/tarantool/tarantool/pull/8689 > > src/lj_parse.c | 2 +- > .../lj-819-fix-missing-uclo.test.lua | 27 +++++++++++++++++++ > 2 files changed, 28 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/lj-819-fix-missing-uclo.test.lua > > diff --git a/src/lj_parse.c b/src/lj_parse.c > index af0dc53f..343fa797 100644 > --- a/src/lj_parse.c > +++ b/src/lj_parse.c > diff --git a/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua b/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua > new file mode 100644 > index 00000000..b3f1f78a > --- /dev/null > +++ b/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua > @@ -0,0 +1,27 @@ > +local tap = require('tap') > +local test = tap.test('lj-819-fix-missing-uclo') > + > +test:plan(1) > + > +local function missing_uclo() > + while true do -- luacheck: ignore > + if false then > + break Please, comment why do we need this always false branch for reproducer (the aforementioned BC_UCLO). Also, examples of bytecode listings for this function before and after the patch are desirable. > + end > + local f > + while true do > + if f then > + return f Please, comment, that exactly here we got not fixupped RET before the patch. > + end > + f = function() > + return f > + end > + end > + end > +end > + > +local f = missing_uclo() > +local res = f() > +test:ok(type(res) == 'function', 'type of returned value is correct') Minor: the comment why we don't get here a function, when upvalue isn't closed is desirable. > + > +os.exit(test:check() and 0 or 1) Also, before the patch I got the following assertion in JIT: | LUA_PATH="src/?.lua;;" src/luajit -Ohotloop=1 -e ' | | local function missing_uclo() | while true do -- luacheck: ignore | local f | if false then break end | while true do | if f then | return f | end | f = function() | return f | end | end | end | end | f = missing_uclo() | print(f()) | f = missing_uclo() | print(f()) | ' | 3.1002202036551 | luajit: /home/burii/reviews/luajit/lj-819-missing-uclo/src/lj_record.c:135: rec_check_slots: Assertion `((((((tr))>>24) & IRT_TYPE) - (TRef)(IRT_NUM) <= (TRef) | (IRT_INT-IRT_NUM)))' failed. | Aborted I don't sure that we should test this particular failure too, since the origin of the problem is the incorrect emitted bytecode. Thoughts? > -- > 2.34.1 > -- Best regards, Sergey Kaplun