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 6AFC66F3FE; Tue, 31 Aug 2021 14:39:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6AFC66F3FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630409981; bh=AzLul3cAPTzq7q0gK0itGQ5omOc4fV1r3E1qwasP4Vw=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oVNDfziGL5Sawyh5k2wrgwTGyDhER3UsJmKIQ8zaSKuXbm36DKuj70fQsBicrdDzb FSxP+c5l4xRn2P8EoaEdKWN165irg9Quk1zfpLE+XOTcsgc2QPubEqf715ST7BXuoY 4ztiLXidflM0zs4ncCqMGwI/RbYd6qeyCaS+fAz4= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (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 1284D6F3FD for ; Tue, 31 Aug 2021 14:39:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1284D6F3FD Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1mL278-0003Ga-Pa; Tue, 31 Aug 2021 14:39:39 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) In-Reply-To: <20210820154846.5515-1-skaplun@tarantool.org> Date: Tue, 31 Aug 2021 14:39:37 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20210820154846.5515-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3654.100.0.2.22) X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F53808504010576A1BB1BAD4273A4A3A9587AB7D7C4417E17DEDCCD1FA618BBF2D8F6E4B56 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75644E22E05AA81AEB287FD4696A6DC2FA8DF7F3B2552694A4E2F5AFA99E116B42401471946AA11AF0E30A4C9C8E338DAD73594321916E0988F08D7030A58E5AD1A62830130A00468AEEEE3FBA3A834EE7353EFBB55337566416511BB2D3FAED2F541A9F4C379E6227F890D8DBA8DC118A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7328B01A8D746D8839FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C317B107DEF921CE79117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F790063749630363B3EBCB7CEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A59968568BD8E38ED72192CACF77B6DE7158D9131F9745240ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752546FE575EB473F1410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3494FB0335DF05DC3A03BEF1EACAA69957665D62237DF6C0DE8C70F1228116905FEB808B12375FE7181D7E09C32AA3244C812E5111A0CDECDFF5A5B63F7CFD6FEBE3D93501275E802FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKvNUqyKacB2c6m9w6n+0rA== X-Mailru-Sender: 3B9A0136629DC912F4AABCEFC589C81EA60C208D7CF263ACB72BF89C1BA348295820E56495D10B2EAD07DD1419AC565FA614486B47F28B67C5E079CCF3B0523AED31B7EB2E253A9E112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix string.char() recording with no arguments. 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 Ostanevich via Tarantool-patches Reply-To: Sergey Ostanevich Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! Some readability comments below. regards, Sergos > On 20 Aug 2021, at 18:48, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > (cherry picked from commit dfa692b746c9de067857d5fc992a41730be3d99a) >=20 > `string.char()` call without arguments yields an empty string. When = JIT > machinery records the aforementioned call it doesn't handle this case. JIT recording machinery doesn=E2=80=99t handle this case. > Each recording fast function expects 1 result by default. Hence, when ^ of a=20 > return from this call is recorded the framelink slot is used as a > result. It is loaded into the corresponding slot as an IR with = `IRT_NUM` I have a question here: is this number denotes the number of results? Then, perhaps reword the previous sentence that this very number is=20 considered as result. > type. It leads to assertion failure in `rec_check_slots()`, when a = next > bytecode is recorded, because type of TValue on the stack (`LJ_STR`) > isn't the same as IR (and TRef) type. >=20 > This patch handles the case without arguments by the loading of IR = with > empty string reference into the corresponding slot. >=20 I would add that code reuses assumption of one result by default, hence no case for =E2=80=98i =3D=3D 1=E2=80=99 in the code. > Sergey Kaplun: > * added the description and the test for the problem >=20 > Resolves tarantool/tarantool#6371 > --- >=20 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-6371-string-char-no-ar= g > Issue: https://github.com/tarantool/tarantool/issues/6371 > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/gh-6371-string-char-no= -arg > Side note: CI is totally red, but AFAICS it's unrelated with my patch. > Side note: See also Changelog at the Tarantool branch. >=20 > src/lj_ffrecord.c | 2 ++ > .../gh-6371-string-char-no-arg.test.lua | 28 +++++++++++++++++++ > 2 files changed, 30 insertions(+) > create mode 100644 = test/tarantool-tests/gh-6371-string-char-no-arg.test.lua >=20 > diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c > index 8dfa80ed..be890a93 100644 > --- a/src/lj_ffrecord.c > +++ b/src/lj_ffrecord.c > @@ -866,6 +866,8 @@ static void LJ_FASTCALL = recff_string_char(jit_State *J, RecordFFData *rd) > for (i =3D 0; J->base[i] !=3D 0; i++) > tr =3D emitir(IRT(IR_BUFPUT, IRT_PGC), tr, J->base[i]); > J->base[0] =3D emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); > + } else if (i =3D=3D 0) { > + J->base[0] =3D lj_ir_kstr(J, &J2G(J)->strempty); > } > UNUSED(rd); > } > diff --git a/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua = b/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua > new file mode 100644 > index 00000000..6df93f07 > --- /dev/null > +++ b/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua > @@ -0,0 +1,28 @@ > +local tap =3D require('tap') > + > +-- Test file to demonstrate assertion after `string.char()` > +-- recording. > +-- See also, https://github.com/tarantool/tarantool/issues/6371. > + > +local test =3D tap.test('gh-6371-string-char-no-arg') > +-- XXX: Number of loop iterations. > +-- 1, 2 -- instruction becomes hot > +-- 3 -- trace is recorded (considering loop recording specifics), > +-- but bytecodes are still executed via VM > +-- 4 -- trace is executed, need to check that emitted mcode is > +-- correct > +local NTEST =3D 4 > +test:plan(NTEST) > + > +-- Storage for the results to avoid trace aborting by `test:ok()`. > +local results =3D {} > +jit.opt.start('hotloop=3D1') > +for _ =3D 1, NTEST do > + table.insert(results, string.char()) > +end > + > +for i =3D 1, NTEST do > + test:ok(results[i] =3D=3D '', 'correct recording of string.char() = without args') > +end > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.31.0 >=20