From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8EC673858CD1 for ; Sun, 26 Nov 2023 21:30:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EC673858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EC673858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701034233; cv=none; b=ZChFbDgmS6BpJa1RALtQxpO5sTYN6weKvX1as/QeNWu/a7hfTNPt1hviQ3kveogZ1HtFBMRcsbLwUjtd6t/djI22+6W7VdTfRa4oSmQVjTa/AD8IH2jyJVJhWAILaD+nE4N47FxgSroyXJm4dK+njLzfJ0qkB2gmJZiVh23/6QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701034233; c=relaxed/simple; bh=D18tT6aS6Ktc5QJznA4qsqIyWjehTK4Y4bUOByNCibY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=WVYDHk41mZ1IOZ+uo3u6EmQ8553wAF046yC7kP9XBg/lG+/S6Uknn0anwNFy6YuEPDTvjLDHO7K8Tq9JqzcN5Umsq9Qt9yO8TW4UgDSNyYmkphivq0CEse+wQahxZoFHs0utqx3veVTY2kkiYmz/S4d78jL0+OUXe5yDUOPOK8Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701034229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O6Xbd2w5Qi89XbCG6adCEnuuSQqlwPvZGzshUwWPD2M=; b=WhhEKj0WTB3r6W0GOORB/zoA+UXWBEZCZg9B0clzKuiRrdQUtw7wpQTWc6ffECqwXhinkr FvHgZmRxfuD+6fc5KQfzOyLLiJD3t4d5sJLb6D503C5Ds0gWLUMlZhelMNO2GfNnoT43R0 rIYm9e4qfRKs0l2GtZuPNJzpLmm2BhA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-kJZY6Vf9NKiSizNgnv8lPQ-1; Sun, 26 Nov 2023 16:30:27 -0500 X-MC-Unique: kJZY6Vf9NKiSizNgnv8lPQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-67a0f1be799so32080356d6.2 for ; Sun, 26 Nov 2023 13:30:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701034227; x=1701639027; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O6Xbd2w5Qi89XbCG6adCEnuuSQqlwPvZGzshUwWPD2M=; b=PsVUf81aLiqmxn7hb7iBldifEAWq7jO69pLqPVhgna5nCGbbOYhn/CinZWDiFIZZoZ lQIszMqGbL2rWNZomEqE3WLVF+cgOaMh3aBjkGpOeZFPgjhSYuIsgC36LM6U0n2CYcs0 FLrSsA/SOG6lxca/0AQsMsQ+5WPuD1Uv/4D6Z3mofEr8ZXJzx2KzcYu+qm6zQYoK92h+ JbY1DCktxuNytLrUYSwm9P67w7jnOEYlkmUF5x0OFHZQKuRhpTReElkYbkJcoaB58Q6X XQNdYxRxRoHXbEn8q5ezYxLdQ8uPjxWGfV3z0hetV1QQrQzaVOoZOz+UJbBSdzsWjqYt drgw== X-Gm-Message-State: AOJu0YypFceQ/t2V7ZrYI4+AP5LHKJEPidCG3iB1gxHm5dXI6LFMa0he rE5cyjUI0hNoBY5+4Q5TE5xofAULGdr2CpDLJgbI5YXGGHW1IoxIrtr+DGXBUXTk4lGZkn9Ih5o 4PqtsDqO3jnbWiRNOM+IRa+slMg== X-Received: by 2002:ad4:5de8:0:b0:67a:dc0:14f7 with SMTP id jn8-20020ad45de8000000b0067a0dc014f7mr14960782qvb.50.1701034226849; Sun, 26 Nov 2023 13:30:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/GOTzzRmo/Wx9TEBgJE/+TzOS195o0SOgYX35WH6Hw/WN8wd4bPC1EdxtCDYF/QkR5WLJhQ== X-Received: by 2002:ad4:5de8:0:b0:67a:dc0:14f7 with SMTP id jn8-20020ad45de8000000b0067a0dc014f7mr14960766qvb.50.1701034226519; Sun, 26 Nov 2023 13:30:26 -0800 (PST) Received: from [192.168.1.145] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id od3-20020a0562142f0300b0067a0faae794sm3051588qvb.99.2023.11.26.13.30.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Nov 2023 13:30:25 -0800 (PST) Message-ID: Date: Sun, 26 Nov 2023 16:30:24 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/1] c++: Initial support for P0847R7 (Deducing This) [PR102609] To: waffl3x Cc: "gcc-patches@gcc.gnu.org" References: <9OlK_2c3Punfm3w-wEHqyHGyKGG8Gr_K0BUnDOuC9Aazur4mWlAM5WuL1Ea0AMLvFLl6LKFVTs813yY0zA7m0_ji_R9qhE52G7MZXrVPfZE=@protonmail.com> <7Xr5Vil7ptZzPaCtc_ZCdcTPuUVY7dheOnklF-vVDb5_jl8PivYWgTT_f3cKLvg7IMnDruCDDrICRI6WVrUT3f8ZScGKAh4ATIkYSuRqPZc=@protonmail.com> From: Jason Merrill In-Reply-To: <7Xr5Vil7ptZzPaCtc_ZCdcTPuUVY7dheOnklF-vVDb5_jl8PivYWgTT_f3cKLvg7IMnDruCDDrICRI6WVrUT3f8ZScGKAh4ATIkYSuRqPZc=@protonmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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