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 v5 1/1] c++: Initial support for P0847R7 (Deducing This) [PR102609]
Date: Sun, 26 Nov 2023 16:30:24 -0500 [thread overview]
Message-ID: <a87121c4-650c-4627-b37c-7071cd5908eb@redhat.com> (raw)
In-Reply-To: <7Xr5Vil7ptZzPaCtc_ZCdcTPuUVY7dheOnklF-vVDb5_jl8PivYWgTT_f3cKLvg7IMnDruCDDrICRI6WVrUT3f8ZScGKAh4ATIkYSuRqPZc=@protonmail.com>
On 11/24/23 20:14, waffl3x wrote:
> OKAY, I figured out SOMETHING, I think this should be fine. As noted in
> the comments, this might be a better way of handling the static lambda
> case too. This is still a nasty hack so it should probably be done
> differently, but I question if making a whole new fntype node in
> tsubst_lambda_expr makes sense. On the other hand, maybe there will be
> problems if a lambda is already instantiated? I'm not sure, mutating
> things this way makes me uneasy though.
A problem with changing TYPE_METHOD_BASETYPE for a FUNCTION_TYPE is that
all equivalent FUNCTION_TYPE share the same tree node (through
type_hash_canon), so you're messing with the type of unrelated functions
at the same time. I think it's better to stick with the way static
lambdas are handled.
> I don't like that pt.cc feels like it has a ton of hidden mutations,
> it's really hard to follow through it. Would you agree it's in need for
> cleanup or am I just not experienced enough in this area yet?
I'm sure there are things that could use cleaning up, but I'm not
thinking of anything specific offhand. Any particular examples?
> Regarding the error handling, I just had a thought about it, I have a
> hunch it definitely needs to go in tsubst_template_decl or
> tsubst_function_decl. There might need to be more changes to determine
> the actual type of the lambda in there, but everything else I've done
> changes the implicit object argument to be treated more like a regular
> argument, doing error handling for the object type in
> tsubst_lambda_expr would be inconsistent with that.
But the rule about unrelated type is specific to lambdas, so doing it in
tsubst_lambda_expr seems preferable to adding a lambda special case to
generic code.
> The other problem I'm having is
>
> auto f0 = [n = 5, &m](this auto const&){ n = 10; };
> This errors just fine, the lambda is unconditionally const so
> LAMBDA_EXPR_MUTABLE_P flag is set for the closure.
>
> This on the other hand does not. The constness of the captures depends
> on (I assume) LAMBDA_EXPR_MUTABLE_P so all the captures are non-const
> here.
> auto f1 = [n = 5](this auto&& self){ n = 10; };
> as_const(f1)();
That sounds correct, why would this be an error?
The constness of the captures doesn't depend on LAMBDA_EXPR_MUTABLE_P,
it depends on the type of the object parameter, which in this case is
non-const, so so are the captures.
> I was going to close out this message there but I just realized why
> exactly you think erroring in instantiate_body is too late, it's
> because at that point an error is an error, while if we error a little
> bit earlier during substitution it's not a hard error. I'm glad I
> realized this now, because I am much more confident in how to implement
> the errors for unrelated type now. I'm still a little confused on what
> the exact protocol for emitting errors at this stage is, as there
> aren't many explicit errors written in. It seems to me like the errors
> are supposed to be emitted when calling back into non-template stages
> of the compiler with substituted types. It also seems like that hasn't
> always been strictly followed, and I hate to contribute to code debt
> but I'm not sure how I would do it in this case, nor if I actually have
> a valid understanding of how this all works.
Most errors that could occur in template substitution are guarded by if
(complain & tf_error) so that they aren't emitted during deduction
substitution. It's better if those are in code that's shared with the
non-template case, but sometimes that isn't feasible.
> One side note before I close up here, I don't like when *_P macros are
> used to set flags. Is this something else we should clean up in the future?
I don't think so, a wholesale renaming would just confuse existing
developers.
> I'm beginning to
> wonder if an overhaul that gets rid of the macros from the public
> interface is a good idea. I'm reluctant to suggest that as I've really
> warmed up to the macros a lot. They are used in a consistent and easy
> to understand way which is highly unlike the bad uses of macros that
> I've seen before that really obscure what's actually going on. But they
> are still macros, so maybe moving away from them is the right call,
> especially since there has started to be a mix-up of macros and
> functions for the same purposes. I'm mildly of the opinion that only
> one style should be used (in the public interface) because mixing them
> causes confusion, it did for me anyway. Perhaps I should open a thread
> on the general mail list and see what others think, get some input
> before I decide which direction to go with it. To be clear, when I say
> getting rid of macros, I want to emphasize I mean only in the public
> interface, I don't see any value in getting rid of macros under the
> hood as the way the checking macros are implemented is already really
> good and works. It would only cause problems to try to move away from
> that. I think I'll probably start to mess around with this idea as soon
> as this patch is done.
There has been some movement from macros toward inline functions since
the switch to C++, but that also has complications with
const-correctness, declaration order, and bit-fields. It's probably
good to use inlines instead of larger macros when feasible, but the
accessors should probably stay macros.
Jason
next prev parent reply other threads:[~2023-11-26 21:30 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 6:02 [PATCH 1/2] " 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
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 [this message]
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=a87121c4-650c-4627-b37c-7071cd5908eb@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).