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 0CA4550ED88; Thu, 6 Jul 2023 12:40:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0CA4550ED88 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1688636417; bh=xJ29BfI5OyMGozDhqdW05lL0t3MurbqxSkMnj9Z2Zk4=; 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=bkcnJY1JhoA+wocCQGiPwELw7btRovk7dyBWlCfRxZZ4XWs3SLfHuC834GFItimIK KSTAMPBBH5tv1q99hdCUfZaIYNryfmUqXd4Csh5wB69njk0dmif3qKC7FaiRkKi/Zf 1Ef4PmvbmJ1qckxqXZW5tOs5uESBYI7WkGYWjje0= Received: from smtp38.i.mail.ru (smtp38.i.mail.ru [95.163.41.79]) (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 6B30646B100 for ; Thu, 6 Jul 2023 12:40:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6B30646B100 Received: by smtp38.i.mail.ru with esmtpa (envelope-from ) id 1qHLTC-00EooA-Iq; Thu, 06 Jul 2023 12:40:15 +0300 Message-ID: <895991f2-93ca-0901-031b-2b39e0612a39@tarantool.org> Date: Thu, 6 Jul 2023 12:40:13 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: Sergey Kaplun , Sergey Bronnikov References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD91BCCBDE3AB822A0A9C6E440A91431E173DD5753A4B11DACF182A05F538085040C901589D2A0D068BE5AF037CC2D4696E6E597BF3BF2C11937EAB7F8A7AF694B6 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9FBA884A7C9B8BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376AEB812070489DF38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89A59FF7ABB024B34CA0AE64CB1E1A578117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B990B2EB4F061288CA471835C12D1D977C4224003CC836476EB9C41850244470149FD398EE364050F9647ADFADE5905B1CEDA8D6C8C3B0531B3661434B16C20ACC84D3B47A649675FE827F84554CEF5019E625A9149C048EE26055571C92BF10FD1B931868CE1C5783A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4931B544F03EFBC4D5728A6D463EDFD0DBBC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A508B7D5800C408C24C89AF740467735B8299BD9BCF414A6F8F87CCE6106E1FC07E67D4AC08A07B9B0A6C7FFFE744CA7FBCB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1123510822D642066CEF1C57B57E05BFA61B91B16216FD9BCE389483A294E8984C7498080C0F87FC101EEC565983E64326051FE8790EEC43AC6D30510D05272AA74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtT0gG7HlXRIR+yS1DqwUGA== X-Mailru-Sender: 0A26D9779F8DDEAB68A88147A9E30CE8163C62C2E1C52F5534603FF2E175684B7F8BE30599730E96645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for review! See my answers below. Updated version force-pushed to the branch. S. On 6/6/23 15:51, Sergey Kaplun wrote: > 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. Added a small explanation as well. More detailed explanation added to the file with test. >> 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. Added a comment at the beginning of the test. > >> + end >> + local f >> + while true do >> + if f then >> + return f > Please, comment, that exactly here we got not fixupped RET before the > patch. Added. > >> + 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? Added a second testcase and description for it. > >> -- >> 2.34.1 >>