public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: Petter Tomner <tomner@kth.se>
To: David Malcolm <dmalcolm@redhat.com>, Antoni Boucher <bouanto@zoho.com>
Cc: "jit@gcc.gnu.org" <jit@gcc.gnu.org>
Subject: SV: [PATCH] libgccjit: add some reflection functions in the jit C api
Date: Sat, 23 Oct 2021 21:20:45 +0000	[thread overview]
Message-ID: <e588b618f0b242489aba7c58fc772f27@kth.se> (raw)
In-Reply-To: <f9f942ebd1476deaf785bb5119b2d4903c583773.camel@zoho.com>

Hi! (Sorry, my mail client dropped the jit mailing-list. Resending the mail to it)

+gcc_jit_type *
+gcc_jit_type_unqualified (gcc_jit_type *type)
+{
+  RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
+
+  return (gcc_jit_type *)type->unqualified ();
+}

I think there is a problem with the current implementation of unqualified() that might be kinda surprising to
users, since it only removes one qualifier and also not "pointed to" qualifiers.

Unrelated to this patch that behavior should probably be documented, since it effects many entry-points
and makes cast to base type kinda mandatory when qualified types are mixed. Casts uses a recursive
check of types and is happy to cast any pointer to any pointer (no matter the level of pointerness) so
they work.

I guess the casts should get some shortcircuit for casts between same base types really,
to not bloat the GENERIC tree.

I made a utility function in another patch for comparing types that do full stripping (see bellow).

Maybe something like that could be usefull?

jit-recording.h:
+/* Strip all qualifiers and count pointer depth, returning true
+   if the types and pointer depth are the same, otherwise false. */
+static inline bool
+types_kinda_same (recording::type *a, recording::type *b)
+{
+  /* Handle trivial case here, to allow for inlining. */
+  return a == b || types_kinda_same_internal (a, b);
+}
jit-recording.c:
+/* Strip qualifiers and count pointer depth, returning true
+   if the types' base type and pointer depth are
+   the same, otherwise false.
+
+   Do not call this directly. Call 'types_kinda_same' */
+bool
+types_kinda_same_internal (recording::type *a, recording::type *b)
+{
+  int ptr_depth[2] = {};
+  recording::type *base_types[2];
+  recording::type *types[2] = {a, b};
+
+  /* Strip qualifiers and count pointerness */
+  for (int i = 0; i < 2; i++)
+    {
+      recording::type *t = types[i];
+      while (true)
+       {
+         if (!t)
+           return false; /* Should only happen on bad input */
+
+         recording::type *pointed_to_type = t->is_pointer();
+         if (pointed_to_type != NULL)
+           {
+             ptr_depth[i]++;
+             t = pointed_to_type;
+             continue;
+           }
+
+         /* unqualified() returns 'this' on base types */
+         recording::type *next = t->unqualified ();
+         if (next == t)
+           {
+             base_types[i] = t;
+             break;
+           }
+         t = next;
+       }
+    }
+
+  return base_types[0] == base_types[1] &&
+    (ptr_depth[0] == ptr_depth[1]);
+}


Från: Jit <jit-bounces+tomner=kth.se@gcc.gnu.org> för Antoni Boucher via Jit <jit@gcc.gnu.org>
Skickat: den 13 oktober 2021 04:09
Till: David Malcolm
Kopia: Antoni Boucher via Jit; gcc-patches@gcc.gnu.org
Ämne: Re: [PATCH] libgccjit: add some reflection functions in the jit C api
    
David: PING

Le lundi 27 septembre 2021 à 20:53 -0400, Antoni Boucher a écrit :
> I fixed an issue (it would show an error message when
> gcc_jit_type_dyncast_function_ptr_type was called on a type different
> than a function pointer type).
> 
> Here's the updated patch.
> 
> Le vendredi 18 juin 2021 à 16:37 -0400, David Malcolm a écrit :
> > On Fri, 2021-06-18 at 15:41 -0400, Antoni Boucher wrote:
> > > I have write access now.
> > 
> > Great.
> > 
> > > I'm not sure how I'm supposed to send my patches:
> > > should I put it in personal branches and you'll merge them?
> > 
> > Please send them to this mailing list for review; once they're
> > approved
> > you can merge them.
> > 
> > > 
> > > And for the MAINTAINERS file, should I just push to master right
> > > away,
> > > after sending it to the mailing list?
> > 
> > I think people just push the MAINTAINERS change and then let the
> > list
> > know, since it makes a good test that write access is working
> > correctly.
> > 
> > Dave
> > 
> > > 
> > > Thanks for your help!
> > > 
> > > Le vendredi 18 juin 2021 à 12:09 -0400, David Malcolm a écrit :
> > > > On Fri, 2021-06-18 at 11:55 -0400, Antoni Boucher wrote:
> > > > > Le vendredi 11 juin 2021 à 14:00 -0400, David Malcolm a
> > > > > écrit :
> > > > > > On Fri, 2021-06-11 at 08:15 -0400, Antoni Boucher wrote:
> > > > > > > Thank you for your answer.
> > > > > > > I attached the updated patch.
> > > > > > 
> > > > > > BTW you (or possibly me) dropped the mailing lists; was
> > > > > > that
> > > > > > deliberate?
> > > > > 
> > > > > Oh, my bad.
> > > > > 
> > > > 
> > > > [...]
> > > > 
> > > > 
> > > > > > 
> > > > > > 
> > > > > > > I have signed the FSF copyright attribution.
> > > > > > 
> > > > > > I can push changes on your behalf, but I'd prefer it if you
> > > > > > did
> > > > > > it,
> > > > > > especially given that you have various other patches you
> > > > > > want
> > > > > > to
> > > > > > get
> > > > > > in.
> > > > > > 
> > > > > > Instructions on how to get push rights to the git repo are
> > > > > > here:
> > > > > >   https://gcc.gnu.org/gitwrite.html
> > > > > > 
> > > > > > I can sponsor you.
> > > > > 
> > > > > Thanks.
> > > > > I did sign up to get push rights.
> > > > > Have you accepted my request to get those?
> > > > 
> > > > I did, but I didn't see any kind of notification.  Did you get
> > > > an
> > > > email
> > > > about it?
> > > > 
> > > > 
> > > > Dave
> > > > 
> > > 
> > > 
> > 
> > 
> 


    

  reply	other threads:[~2021-10-23 21:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02  1:01 Antoni Boucher
2020-10-02 20:17 ` David Malcolm
2020-10-02 20:24   ` David Malcolm
2020-10-02 22:39     ` [PATCH] libgccjit: add some reflection functions in the jit C api [PR96889] Antoni Boucher
2020-10-03 18:14     ` [PATCH] libgccjit: add some reflection functions in the jit C api [WIP] Antoni Boucher
2020-10-15 16:02     ` [PATCH] libgccjit: add some reflection functions in the jit C api Antoni Boucher
2020-10-15 16:23       ` Andrea Corallo
2020-10-15 17:39         ` Antoni Boucher
2020-10-15 18:04           ` Andrea Corallo
2020-10-15 21:52           ` David Malcolm
2020-10-17  0:41             ` Antoni Boucher
2020-11-03 22:13             ` Antoni Boucher
2021-05-13  8:33               ` Martin Liška
2021-05-13 21:30               ` David Malcolm
2021-05-14  2:11                 ` Antoni Boucher
2021-05-26  0:19                 ` Antoni Boucher
2021-05-27 22:19                   ` David Malcolm
2021-05-28  1:51                     ` Antoni Boucher
2021-06-10 22:41                       ` David Malcolm
     [not found]                         ` <bc9e81dc3f0a68d6389c9765b5901a5dbd1dcd71.camel@zoho.com>
     [not found]                           ` <e962387aff72bce1ea29b0fc2cb04b84c26f9855.camel@redhat.com>
2021-06-18 15:55                             ` Antoni Boucher
2021-06-18 16:09                               ` David Malcolm
2021-06-18 19:41                                 ` Antoni Boucher
2021-06-18 20:37                                   ` David Malcolm
2021-07-19 16:10                                     ` Antoni Boucher
2021-07-29 12:59                                       ` Antoni Boucher
2021-08-31 12:34                                         ` Antoni Boucher
2021-09-28  0:53                                     ` Antoni Boucher
2021-10-13  2:09                                       ` Antoni Boucher
2021-10-23 21:20                                         ` Petter Tomner [this message]
2021-11-14 21:30                                         ` Antoni Boucher
2021-11-20  0:53                                       ` David Malcolm
2021-11-26 18:03                                         ` Gerald Pfeifer
2021-11-26 19:51                                           ` Gerald Pfeifer
2021-11-27 16:09                                           ` SV: " Petter Tomner
2021-12-02 18:04                                             ` Gerald Pfeifer

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=e588b618f0b242489aba7c58fc772f27@kth.se \
    --to=tomner@kth.se \
    --cc=bouanto@zoho.com \
    --cc=dmalcolm@redhat.com \
    --cc=jit@gcc.gnu.org \
    /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).