From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: How to add pseudo vector types Date: Fri, 30 Jul 2021 10:17:22 -0400 Message-ID: <4F02FE4E-0B48-4A94-B1D4-8C4878F51493@gmail.com> References: <83h7gw6pyj.fsf@gnu.org> <46BBFF88-76C3-4818-8805-5437409BEA93@gmail.com> <83wnpq46uk.fsf@gnu.org> <533BD53B-4E85-4E9E-B46A-346A5BBAD0F5@gmail.com> <258CB68D-1CC1-42C8-BDCD-2A8A8099B783@gmail.com> <1a776770-50b7-93cd-6591-c9a5b3a56eb8@gmail.com> <8335s64v10.fsf@gnu.org> <5380C92B-6C15-4490-A1E0-1C3132DBB16A@gmail.com> <83k0li2shw.fsf@gnu.org> <86wnpg82v3.fsf@stephe-leake.org> <83lf5wyn0z.fsf@gnu.org> <86pmv66yqg.fsf@stephe-leake.org> <83a6maw705.fsf@gnu.org> <83r1fluikh.fsf@gnu.org> <88007ACB-31E5-440F-876D-9F43C8EE02CC@gmail.com> <86fsw05lom.fsf@stephe-leake.org> <8A3823DD-5D5A-4A33-8EF9-93F05497CE4C@gmail.com> <864kcf5cmv.fsf_-_@stephe-leake.org> <18D745F5-DBB1-46CC-91D3-4ADAA9D37AB9@gmail.com> <834kcetmly.fsf@gnu.org> <831r7itjc8.fsf@gnu.org> <24808548-23F4-4068-877E-37C7190A02B0@gmail.com> <83wnpas1q7.fsf@gnu.org> <83k0l9rvf5.fsf@gnu.org> <83fsvxrszr.fsf@gnu.org> <83czr1rpei.fsf@gnu.org> <83a6m5rmp4.fsf@gnu.org> <574573B6-8844-45CC-9ACB-D5F75AE465E5@gmail.com> <83sfzwqowk.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11885"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= , Stephen Leake , Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jul 30 16:18:20 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m9TLA-0002rc-OF for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Jul 2021 16:18:20 +0200 Original-Received: from localhost ([::1]:47804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9TL9-0006b3-G0 for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Jul 2021 10:18:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9TKJ-0005uI-K3 for emacs-devel@gnu.org; Fri, 30 Jul 2021 10:17:27 -0400 Original-Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:38593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m9TKH-0002SR-Va; Fri, 30 Jul 2021 10:17:27 -0400 Original-Received: by mail-qv1-xf30.google.com with SMTP id cg4so198986qvb.5; Fri, 30 Jul 2021 07:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mMBEiuRdWf4udh8PhhaiSpIc5Z6s61KLrdY8Cy7QoZk=; b=E3gMqVNxrJLAyaR+9Z/2OjxhRLawwYW7qtDA9y6EmpjORZvkkrnjjhuOvKQy41/jpo gVF4/PQx+xHTz3Mt9VOVPHXa5V8PBTugY0P+d0p1n74g72bOzNIuv9lGyh1ktmeB4MWm 6owSO4xF2ZtfgPPb0FTZCnA4KvE3Wm2hDa1z+R84xpqqL6M4Zmnjs8Rb1wPYSXHGQmB+ JaAxEWIhssLARbHsjLzBTIso3H7WXSE9566sgyyL+1IbgJqgp4WGXVD7JRk9d8vsmzoZ FVo8sbgbA7Y4zY8pNj5UdDEe1A4H7JcSiowi1dCMlHHd+1TBo/ILPW//tR8esfyTn7Ej z7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mMBEiuRdWf4udh8PhhaiSpIc5Z6s61KLrdY8Cy7QoZk=; b=O+A1z+SJZcMvnC4UukJlUx8WOFZOvuouedBtJhgaZHhcUjr2/MvGvax2J031aqd2gJ naC9r5p2sIzCsBwiukoyCIYiViLee1dVqOB/8OboKCrnJZq3LAWF9pl77k0ZyK3ueRei ti4lXl7PWPoytdMZ7RD+4nPDOTjXPRXrrjn6TGxrKVODxWbB+W6r8hlVPV6rJVAWuSC4 a2AOEFI5KLpYl9UykgYTRKH33zZ0yT6B5bqvF+L4117yMydk4LN3LfQBEMedYi2o4Utl HBRoNdA4ps7bVB5aHGk4EHRos6Ojp9snibJ2ZifJ03w1pXyMOaOzXt24trmLYOTkRt4o 6dzA== X-Gm-Message-State: AOAM532d7cphYaKeg/tAjtMJC+H6UysCg5eiVWx3mr4p1iFZ7FYi/mU/ PzldCrWXj83PtXSZfNbD2lOnJoRi9sr9XVl+ X-Google-Smtp-Source: ABdhPJzMs7FOSP4WhpMTGHTDSrQGnqSSPGC0/M9pVHTd3rdDY+FEDmvWMiSQ2ROwBYjxLZPy8RhwRA== X-Received: by 2002:a0c:ac43:: with SMTP id m3mr2725548qvb.5.1627654644347; Fri, 30 Jul 2021 07:17:24 -0700 (PDT) Original-Received: from 2603-7080-0302-635e-c100-4f67-0a08-f5fb.res6.spectrum.com (2603-7080-0302-635e-c100-4f67-0a08-f5fb.res6.spectrum.com. [2603:7080:302:635e:c100:4f67:a08:f5fb]) by smtp.gmail.com with ESMTPSA id z21sm643007qti.73.2021.07.30.07.17.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jul 2021 07:17:23 -0700 (PDT) In-Reply-To: <83sfzwqowk.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=casouri@gmail.com; helo=mail-qv1-xf30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271850 Archived-At: >=20 > That's not the whole code, that's a patch against some previous > version of the code. So I cannot answer your questions with 100% > certainty, until I see the entire code of the TS support. For > example, I'm not sure I have a clear idea when are the two functions > ts_ensure_parsed and ts_record_change called. Oops, I thought you have all prior patches. You can clone the =E2=80=9Cts=E2= =80=9D branch from=20 https://github.com/casouri/emacs.git If this is ok, I=E2=80=99ll push to this branch instead of sending = patches from now on. >=20 > That said, it looks like the code is correct: you should record the > changes in the entire buffer, but only pass to TS the changes inside > the restriction BEGV..ZV that is in effect at the time of the re-parse > call. Btw, I don't see the code that filters changes reported to TS > by their positions against the restriction; did I miss something? Yes, I do clip the change to the visible portion: ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, ptrdiff_t new_end_byte) { eassert(start_byte <=3D old_end_byte); eassert(start_byte <=3D new_end_byte); Lisp_Object parser_list =3D Fsymbol_value (Qtree_sitter_parser_list); while (!NILP (parser_list)) { Lisp_Object lisp_parser =3D Fcar (parser_list); TSTree *tree =3D XTS_PARSER (lisp_parser)->tree; if (tree !=3D NULL) { /* We "clip" the change to between visible_beg and visible_end. It is okay if visible_end ends up larger than BUF_Z, tree-sitter only access buffer text during re-parse, and we will adjust visible_beg/end before re-parse. */ ptrdiff_t visible_beg =3D XTS_PARSER = (lisp_parser)->visible_beg; ptrdiff_t visible_end =3D XTS_PARSER = (lisp_parser)->visible_end; ptrdiff_t visible_start =3D max (visible_beg, start_byte) - visible_beg; ptrdiff_t visible_old_end =3D min (visible_end, old_end_byte) - visible_beg; ptrdiff_t visible_new_end =3D min (visible_end, new_end_byte) - visible_beg; ts_tree_edit_1 (tree, visible_start, visible_old_end, visible_new_end); XTS_PARSER (lisp_parser)->need_reparse =3D true; parser_list =3D Fcdr (parser_list); } } } > And one more question: I understand that ts_read_buffer doesn't check > against BUF_BEGV_BYTE because TS never reads before the "visible beg" > position, is that right? =20 Yes, we always update visible_beg and visible_end to match BUF_BEGV_BYTE = and BUF_ZV_BYTE before we instruct tree-sitter to re-parse. So when = tree-sitter reads at byte position 0, it translates to buffer byte = position 0 + visible_beg =3D BUF_BEGV_BYTE.=20 > But if so, why do we need the similar test > for BUF_ZV_BYTE? could TS attempt to read beyond the "visible end=E2=80=9D= ? Tree-sitter doesn=E2=80=99t know the size of the buffer, it just keeps = reading until the read function sets bytes_read to 0, signaling that it = has reached the end.=20 Yuan