public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Eduard-Mihai Burtescu" <eddyb@lyken.rs>
To: "Ian Lance Taylor" <iant@google.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, "Ian Lance Taylor" <ian@airs.com>
Subject: Re: [PATCH] Refactor rust-demangle to be independent of C++ demangling.
Date: Wed, 23 Oct 2019 14:29:00 -0000	[thread overview]
Message-ID: <d544cbbb-20ad-4326-9396-f852da936c06@www.fastmail.com> (raw)
In-Reply-To: <CAKOQZ8xOU_jOt3heOgA7q-AGFmgZCtKv6b76H89Tjd5qbX1VmQ@mail.gmail.com>

On Tue, Oct 22, 2019, at 9:39 PM, Ian Lance Taylor wrote:
> I have to assume that C++ demangling is still quite a bit more common
> than Rust demangling, so it's troubling that it looks like we're going
> to do extra work for each symbol that starts with _ZN, which is not a
> particularly uncommon prefix for a C++ mangled name.  Is there some
> way we can quickly separate out Rust symbols?  Or should we try C++
> demangling first?
> 
> Ian
>

I definitely agree, I don't want to make demangling plain C++ symbols
significantly slower. The old code was also doing extra work, at least
in the AUTO_DEMANGLING mode, but less than the parse_ident
loop in this patch.

I've come up with an extra quick check that regular C++ symbols
won't pass most of the time and placed it before the parse_ident
loop, that should make it comparable with the old implementation,
and tests pass just fine with the extra check.

The diff is below, but if you want me to send a combined patch,
or anything else for that matter, please let me know.

diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
index da707dbab9b..4cb189c4019 100644
--- a/libiberty/rust-demangle.c
+++ b/libiberty/rust-demangle.c
@@ -384,6 +384,14 @@ rust_demangle_callback (const char *mangled, int options,
         return 0;
       rdm.sym_len--;
 
+      /* Legacy Rust symbols also always end with a path segment
+         that encodes a 16 hex digit hash, i.e. '17h[a-f0-9]{16}'.
+         This early check, before any parse_ident calls, should
+         quickly filter out most C++ symbols unrelated to Rust. */
+      if (!(rdm.sym_len > 19
+            && !strncmp (&rdm.sym[rdm.sym_len - 19], "17h", 3)))
+        return 0;
+
       do
         {
           ident = parse_ident (&rdm);

  reply	other threads:[~2019-10-23 13:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 18:24 Eduard-Mihai Burtescu
2019-10-22 18:48 ` Ian Lance Taylor via gcc-patches
2019-10-23 14:29   ` Eduard-Mihai Burtescu [this message]
2019-10-23 16:37     ` Alexander Monakov
2019-10-23 16:41       ` Segher Boessenkool
2019-10-23 17:19         ` Jakub Jelinek
2019-10-23 17:29           ` Segher Boessenkool
2019-10-23 17:37             ` Jakub Jelinek
2019-10-23 17:43               ` Segher Boessenkool
2019-10-25 12:46       ` Eduard-Mihai Burtescu
2019-10-30 16:56         ` Eduard-Mihai Burtescu
2019-11-08 17:02           ` Eduard-Mihai Burtescu
2019-11-08 17:44             ` Ian Lance Taylor via gcc-patches
2019-11-08 19:17               ` Eduard-Mihai Burtescu
2019-11-08 19:23                 ` Ian Lance Taylor via gcc-patches
2019-11-15 21:00                   ` Eduard-Mihai Burtescu
2019-11-16 15:39                 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d544cbbb-20ad-4326-9396-f852da936c06@www.fastmail.com \
    --to=eddyb@lyken.rs \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ian@airs.com \
    --cc=iant@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).