From: Jason Merrill <jason@redhat.com>
To: waffl3x <waffl3x@protonmail.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v3 1/2] c++: Initial support for P0847R7 (Deducing This) [PR102609]
Date: Thu, 2 Nov 2023 23:04:41 -0400 [thread overview]
Message-ID: <2f4020bf-3ef7-4627-9d92-c74676981f4b@redhat.com> (raw)
In-Reply-To: <zXWkSXEO_H62WXyNUeV1zNAx9wSVGQ5ooxKAfpN2InCP4X25uOC0yTZlnMqbDMoIa4lGwj0hP-KEP5UIcMs1S1zkhz_Zx4oM3oz09DY2BRg=@protonmail.com>
On 10/28/23 00:07, waffl3x wrote:
> I wanted to change DECL_NONSTATIC_MEMBER_FUNCTION_P to include explicit
> object member functions, but it had some problems when I made the
> modification. I also noticed that it's used in cp-objcp-common.cc so
> would making changes to it be a bad idea?
>
> -- cp-tree.h
> ```
> /* Nonzero for FUNCTION_DECL means that this decl is a non-static
> member function. */
> #define DECL_NONSTATIC_MEMBER_FUNCTION_P(NODE) \
> (TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE)
> ```
> I didn't want to investigate the problems as I was knee deep in
> investigating the addressof bug. So I instead modified
> DECL_FUNCTION_MEMBER_P to include explicit object member functions and
> moved on.
>
> -- cp-tree.h
> ```
> /* Nonzero for FUNCTION_DECL means that this decl is a member function
> (static or non-static). */
> #define DECL_FUNCTION_MEMBER_P(NODE) \
> (DECL_NONSTATIC_MEMBER_FUNCTION_P (NODE) || DECL_STATIC_FUNCTION_P (NODE) \
> || DECL_IS_XOBJ_MEMBER_FUNC (NODE))
> ```
> I am mostly just mentioning this here in case it becomes more relevant
> later. Looking at how much DECL_NONSTATIC_MEMBER_FUNCTION_P is used
> throughout the code I now suspect that adding explicit object member
> functions to it might cause xobj member functions to be treated as
> regular member functions when they should not be.
>
> If this change were to stick it would cause a discrepancy in the
> behavior of DECL_NONSTATIC_MEMBER_FUNCTION_P and it's name. If we were
> to do this, I think it's important we document the discrepancy and why
> it exists, and in the future, it should possibly be refactored. One
> option would be to simply rename it to DECL_IOBJ_MEMBER_FUNCTION_P.
> After all, I suspect that it's unlikely that the current macro
> (DECL_NONSTATIC_MEMBER_FUNCTION_P) is being used in places that concern
> explicit object member functions. So just adding explicit object member
> functions to it will most likely just result in headaches.
>
> It seems to me that would be the best solution, so when and if it comes
> up again, I think that route should be considered.
Agreed, it sounds good to rename the current macro and then add a new
macro that includes both implicit and explicit, assuming that's a useful
category.
> Secondly, there are some differences in the nodes describing an
> explicit object member function from those describing static member
> functions and implicit object member functions that I am not sure
> should be present.
>
> I did my best to summarize the differences, if you want the logs of
> tree_debug that I derived them from I can provide them. Most of my
> understanding of the layout of the nodes is from reading print-tree.cc
> and looking at debug_tree outputs, so it's possible I made a mistake.
>
> I am opting to use the names of members as they are output by
> debug_tree, I recognize this is not always the actual name of the
> member in the actual tree_node structures.
>
> Additionally, some of the differences listed are to be expected and are
> most likely the correct values for each node. However, I wanted to be
> exhaustive when listing them just in case I am mistaken in my opinion
> on whether the differences should or should not occur.
>
> The following declarations were used as input to the compiler.
> iobj decl:
> struct S { void f() {} };
> xobj decl:
> struct S { void f(this S&) {} };
> static decl:
> struct S { static void f(S&) {} };
>
> These differences can be observed in the return values of
> grokdeclarator for each declaration.
>
> 1. function_decl::type::tree_code
> iobj: method_type
> xobj: function_type
> stat: function_type
> 2. function_decl::type::method basetype
> iobj: <record_type 0x7ffff7194c78 S>
> xobj: NULL/no output
> stat: NULL/no output
> 3. function_decl::type::arg-types::tree_list[0]::value
> iobj: <pointer_type>
> xobj: <reference_type>
> stat: <reference_type>
> 4. function_decl::decl_6
> iobj: false/no output
> xobj: false/no output
> stat: true
> 5. function_decl::align
> iobj: 16
> xobj: 8
> stat: 8
> 6. function_decl::result::uid
> iobj: D.2513
> xobj: D.2513
> stat: D.2512
> 7. function_decl::full-name
> iobj: "void S::f()"
> xobj: "void S::f(this S&)"
>
> Differences 1, 3, and 7 seem obviously correct to me for all 3
> declarations, 6 is a little bizarre to me, but since it's just a UID
> it's merely an oddity, I doubt it is concerning.
Agreed.
> That leaves 2, 4, and 5.
>
> 2. I am pretty sure xobj functions should have the struct they are a
> part of recorded as the method basetype member. I have already checked
> that function_type and method_type are the same node type under the
> hood and it does appear to be, so it should be trivial to set it.
> However I do have to wonder why static member functions don't set it,
> it seems to be that it would be convenient to use the same field. Can
> you provide any insight into that?
method basetype is only for METHOD_TYPE; if you want the containing type
of the function, that's DECL_CONTEXT.
> 4. I have no comment here, but it does concern me since I don't
> understand it at all.
In the list near the top of cp-tree.h, DECL_LANG_FLAG_6 for a
FUNCTION_DECL is documented to be DECL_THIS_STATIC, which should only be
set on the static member.
> 5. I am pretty sure this is fine for now, but if xobj member functions
> ever were to support virtual/override capabilities, then it would be a
> problem. Is my understanding correct, or is there some other reason
> that iobj member functions have a different value here?
It is surprising that an iobj memfn would have a different DECL_ALIGN,
but it shouldn't be a problem; the vtables only rely on alignment being
at least 2.
> There are also some differences in the arg param in
> cp_build_addr_expr_1 that concerns me, but most of them are reflected
> in the differences I have already noted. I had wanted to include these
> differences as well but I have been spending too much time staring at
> it, it's no longer productive. In short, the indirect_ref node for xobj
> member functions has reference_to_this set, while iobj member functions
> do not.
That's a result of difference 3.
> The baselink binfo field has the private flag set for xobj
> member functions, iobj member functions does not.
TREE_PRIVATE on a binfo is part of BINFO_ACCESS, which isn't a fixed
value, but gets updated during member search. Perhaps the differences
in consideration of conversion to a base led to it being set or cleared
differently? I wouldn't worry too much about it unless you see
differences in access control.
> I've spent too much time on this write up, so I am calling it here, it
> wasn't all a waste of time because half of what I was doing here are
> things I was going to need to do anyway at least. I still feel like I
> spent too much time on it. Hopefully it's of some value for me/others
> later.
I hope my responses are helpful as well.
Jason
next prev parent reply other threads:[~2023-11-03 3:04 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 6:02 [PATCH " waffl3x
2023-08-31 8:33 ` Jakub Jelinek
2023-09-02 8:43 ` waffl3x
2023-09-11 13:49 ` [PATCH v2 " waffl3x
2023-09-19 20:14 ` Jason Merrill
2023-09-20 0:30 ` waffl3x
2023-09-20 21:19 ` Jason Merrill
2023-09-21 11:28 ` waffl3x
2023-09-22 11:30 ` Jason Merrill
2023-09-26 1:56 ` [PATCH v3 " waffl3x
2023-09-27 22:43 ` Hans-Peter Nilsson
2023-09-27 23:35 ` Waffl3x
2023-10-17 20:53 ` Jason Merrill
2023-10-17 21:11 ` Jason Merrill
2023-10-18 11:46 ` waffl3x
2023-10-18 14:17 ` Jason Merrill
2023-10-18 17:28 ` waffl3x
2023-10-18 17:45 ` Jakub Jelinek
2023-10-18 18:12 ` Jason Merrill
2023-10-19 21:05 ` waffl3x
2023-10-19 21:11 ` Jakub Jelinek
2023-10-19 21:31 ` waffl3x
2023-10-19 21:53 ` Jakub Jelinek
2023-10-19 22:18 ` Jason Merrill
[not found] ` <Q2xXS2RkwtzDslDUAsi4YWupkb9s3QKvecqsxLNUr=5FL-MdSmzIJcZ96S3B9Avk30GneMm8R67JsQ4D-Uj1JB6N8dhTw6LAlNsrpLKHuLP2o=3D@protonmail.com>
2023-10-19 22:51 ` waffl3x
2023-10-19 23:35 ` waffl3x
2023-10-20 2:39 ` Jason Merrill
2023-10-20 4:34 ` waffl3x
2023-10-20 16:01 ` Jason Merrill
[not found] ` <zXWkSXEO=5FH62WXyNUeV1zNAx9wSVGQ5ooxKAfpN2InCP4X25uOC0yTZlnMqbDMoIa4lGwj0hP-KEP5UIcMs1S1zkhz=5FZx4oM3oz09DY2BRg=3D@protonmail.com>
[not found] ` <9YnRZJPkB8KCk8R86UDwWBoNnmOEAir4IU4enb1qIGgVdkB6dwy76ClgAzwpPqpToQ9sLTBs50EIRwhivBJU6RAFfLt-fjJxdYTZ35YVFWA=3D@protonmail.com>
2023-10-28 4:07 ` waffl3x
2023-10-28 23:21 ` waffl3x
2023-11-01 23:15 ` waffl3x
2023-11-02 7:01 ` waffl3x
2023-11-02 7:01 ` Jakub Jelinek
2023-11-03 3:04 ` Jason Merrill [this message]
2023-11-03 4:44 ` waffl3x
2023-11-03 18:05 ` Jason Merrill
2023-11-04 6:40 ` waffl3x
2023-11-09 18:44 ` Jason Merrill
2023-11-10 4:24 ` waffl3x
2023-11-10 23:12 ` Jason Merrill
2023-11-11 10:43 ` waffl3x
2023-11-11 11:24 ` waffl3x
2023-11-14 3:48 ` Jason Merrill
2023-11-14 4:36 ` waffl3x
2023-11-18 6:43 ` waffl3x
2023-11-19 6:22 ` Jason Merrill
2023-11-19 13:39 ` waffl3x
2023-11-19 16:31 ` Jason Merrill
2023-11-19 18:36 ` waffl3x
2023-11-19 20:34 ` Jason Merrill
2023-11-19 21:44 ` waffl3x
2023-11-20 14:35 ` Jason Merrill
[not found] ` <1MdaTybBd=5Fo4uw-Gb23fYyd5GNz7qFqoSe=5Ff5h90LY=5FBdzM2ge2qPSyCuiCLYoYcZSjmVv13fw1LmjQC=5FM2L8raS1fydY5pEJ=5Fvwvv5Z-0k=3D@protonmail.com>
2023-11-21 10:02 ` waffl3x
2023-11-21 13:04 ` [PATCH v5 1/1] " waffl3x
2023-11-22 3:22 ` Jason Merrill
2023-11-22 20:46 ` waffl3x
2023-11-22 21:38 ` Jason Merrill
[not found] ` <kltTuyDDwoyOmhBWostMKm5zF3sQCGz3HjMBrBUK6LOZp1-AbGMl5ijKKMlOncwR2yiWippyp89sFPZykNF3OVyz4yknnCVwn=5FiHJPUl25k=3D@protonmail.com>
[not found] ` <dHEpSeuiljMbH0YhwLULApd3yO3LNaVkamGW2KJBYBl0EgMrtpJZ41GeTVOc77siD1kh2vkF4zwInWWGxYXfcnW4XV7sfDPX7cY028JiORE=3D@protonmail.com>
2023-11-22 21:56 ` waffl3x
2023-11-22 22:44 ` waffl3x
2023-11-24 6:49 ` waffl3x
2023-11-24 23:26 ` waffl3x
2023-11-25 1:14 ` waffl3x
2023-11-26 21:30 ` Jason Merrill
2023-11-26 23:10 ` waffl3x
2023-11-27 1:16 ` Jason Merrill
[not found] ` <BEI8PD7nktTuX7dimb22uDnR0b8Bc8ozi4xx9KbiEFj8TjgUCxMfEPpcIPL0bkdThBBab97T1uEJ9rUM3va1eiE1TyRw=5FiLrxwKgg30ZaW0=3D@protonmail.com>
2023-11-27 1:30 ` waffl3x
2023-11-27 1:44 ` waffl3x
2023-11-27 2:40 ` Jason Merrill
2023-11-27 5:35 ` [PATCH v6 " waffl3x
2023-11-28 3:31 ` waffl3x
2023-11-28 10:00 ` waffl3x
2023-11-30 5:00 ` Jason Merrill
2023-11-30 6:36 ` waffl3x
2023-11-30 14:55 ` Jason Merrill
2023-12-01 6:02 ` waffl3x
2023-12-01 16:52 ` Jason Merrill
2023-12-02 1:31 ` waffl3x
2023-12-02 15:02 ` Jason Merrill
[not found] ` <KQegse=5FguOyql4Ok1lrAgS7gasZJd1pOoPbCTdGxcHh-G4A9Tlf5zCnGJmqtshMt72edmcXdIapaZNPp4VJp5Ar9PHZbUrbwDsPjTSUrnOI=3D@protonmail.com>
[not found] ` <59LofhYhxl7MLEuElXwZcESRB6MpjdG-iq-89B63siDRo5k0j-y6z-PVa6Y3iE1xE5LkJwpwTFi82bd0RZjB1yZbSJptFdPTBWfvOGj1W78=3D@protonmail.com>
2023-12-05 4:35 ` waffl3x
2023-12-05 4:39 ` waffl3x
2023-12-05 5:54 ` waffl3x
2023-12-06 7:33 ` [PATCH v7 " waffl3x
2023-12-06 8:48 ` Jakub Jelinek
2023-12-06 9:31 ` waffl3x
2023-12-06 11:08 ` waffl3x
2023-12-08 19:25 ` Jason Merrill
2023-12-10 15:22 ` waffl3x
2023-12-10 18:59 ` Jason Merrill
2023-12-22 9:01 ` waffl3x
2023-12-22 17:26 ` Jason Merrill
2023-12-23 7:10 ` waffl3x
2023-12-26 16:37 ` Jason Merrill
2024-01-01 15:17 ` waffl3x
2024-01-01 15:34 ` waffl3x
2024-01-01 17:12 ` waffl3x
2024-01-06 12:37 ` waffl3x
2023-11-25 17:32 ` [PATCH v5 " Jason Merrill
2023-11-25 22:59 ` waffl3x
2023-09-19 20:24 ` [PATCH 1/2] " Jason Merrill
[not found] <b=5FiIXwWwO63ZE1ZSZHUIAdWyA2sqGsE3FM7eXfsInWogDyBZRsw8CwNsvFSDmEVmBtdq0pqb4zJ55HN2JCR7boDNramlEfne-R5PWdUXjbA=3D@protonmail.com>
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=2f4020bf-3ef7-4627-9d92-c74676981f4b@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=waffl3x@protonmail.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).