Subject: bug#40052: CC Mode 5.34 (C++//l); cc-mode hangs fontifying src/hotspot/share/runtime/globals.hpp in OpenJDK

From: Alan Mackenzie <[email-masked]>
Date: Sat, 16 May 2020 09:07:53 +0000

Hello, Stefan.

On Fri, May 15, 2020 at 17:07:28 -0400, Stefan Monnier wrote:
> [ Just a side, question, really.  ]

> Hi Alan,

> > This hits a bug in Emacs where it allows the backward search operation
> > for a comment start, when point is at the beginning of the line
> > following an escaped newline.  Such a position can never be an end of a
> > comment in C++.

> This problems seems to apply to `c-mode` as much as to `c++-mode`, so
> I took a quick look to see if it also affects `sm-c-mode` (tested with
> Emacs-26) and it seems not to be the case.

> (At least, scrolling and editing this file in `sm-c-mode` is not
> unusably slow (tho it is a bit sluggish, especially editing, which is
> slowed down by `sm-c-mode`s feature that re-aligns the trailing
> backslashes after each edit)).

> > The fix to Emacs won't actually be getting released until Emacs 28, so
> > in the meantime, please try the following patch.  The files to patch are

> This makes it sound like it's related to a bug in the C code.
> Is it something you already fixed?  Is it the new
> `comment-end-can-be-escaped` thingy?

comment-end-can-be-escaped was actually introduced in Emacs 25, so I
think it counts as "fairly new" rather than "new".  ;-)

It was a bug in syntax.c in the use of comment-end-can-be-escaped, and
got fixed by commit 22ba04742072098be60ec223ed2e97fa9a09b045, Date:
Thu Apr 16 17:01:14 2020 +0000, "(forward-comment -n): escaped newline
is sometimes NOT end of comment".  The code now tests that flag in the
backward direction as well as the forward direction.

> I understand that it could speed things up here, but at the same time
> "LFs which don't end a comment" are the rule rather than the exception,
> so if it's a performance problem for those backslash-escaped LFs, why
> doesn't it also affect all the other LFs?

What was happening was backward_comment was searching back over the
entire long macro for the beginning of a comment, and was doing so
repeatedly.  It might be interesting to try sm-c-mode on Nick Gasson's
file without the above patch to syntax.c.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).