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 468833858298 for ; Wed, 22 Nov 2023 21:38:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 468833858298 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 468833858298 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=1700689096; cv=none; b=dWOh1joGThjfpElp7mVNOoT9JK4toqiyJX+xbWVpQN0lIa4MSAPtG/uK/FZJFiPwRILQIA2IbHo1v1U+hzPPSXzVUS0GAHEQmoWSF0i1UovPzEHMiFTcxcGk9Ygr0Y6RUQ8iBnHCRhBzC4AWd+nTCcmSH2XjCB2FzDjsw3gt61Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700689096; c=relaxed/simple; bh=MkObgD3BmFjhJXDXU/3X8KAq0bX92TLQuhxXlbSUp64=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=cDWEiUDypwBuMWZmDjvh0LRRtA90dm5UfkQJAecC5YlhoM3J0wqVONFbzdrOh3XK6KV1EVGGhWWsk7rzuvIbPHJhICfTwulYJVFmtBdlMwWmQeLBUEj4HbKiIVKlp4zrbJatVLN1p/SQBZai05CXK1D2Rsjn3F00K14lhG3+Syc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700689085; 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=9tQ53dAYynDJ00ziFqlPQ1PNaShhCzYvkgRrA8P9TnU=; b=Xd3a6EhfhyIbaEWTgIkRYG2XGqVOAtm+JzXy+u9ryfrDT+4ar0qq58OUuMtSA0kjCs94AT IqkiZ+DKHsNxkDvh3NM1J6bwcLzb50DBABf0lDEV9uP8Hkvq6qqnmJ3ggrT9SwMlWjbIUU emW7r+Ym0X1AiirKG6EfHUrSdz5D0OE= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-VD6iwSZnN4C2N2fAWcm6yw-1; Wed, 22 Nov 2023 16:38:03 -0500 X-MC-Unique: VD6iwSZnN4C2N2fAWcm6yw-1 Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-581dcaf04e6so231196eaf.1 for ; Wed, 22 Nov 2023 13:38:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700689083; x=1701293883; 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=9tQ53dAYynDJ00ziFqlPQ1PNaShhCzYvkgRrA8P9TnU=; b=cfhpXzjf3z5HBDz+EALeS6PixmUePNVa8snebkYeVFyVs5AIDV6bbWa0KOmfJxcz7Q kGvjB1VfapaW3FmlQNldftZNDGjOSbkHf+ZLtqjJEmhUo6N0znuCqKPTBFE5dtEUv4iS 0ESzqUGLEpCP+r40V/qrgpz37DVFNoOp/kZFqqDyk6XyDbKoicQXJU2Ok7CTAQkXiTeT DDOEquztMw01q1NagjQytypYRsb3I7GMs7p7JlBjoR79Nunc9wbY8jh5h1d+ySucxGl4 r1B1CKcFTlcZ+tF1iWJ5eXh8DXXJ2pbORTJ88+feiJRABPSyAyh61zC+I7YrCFobBLnt Rcyw== X-Gm-Message-State: AOJu0Ywvf8UnqgKWrBWSnmEcVP0pAit4lH/b2zY40dzgFyZhQgW84EdI K9Lnnvqr9GqU4KVCRV4t+8jJrIxTxlnuq122y9SjqBey/xzPbzqtSwE+I5LeLBWD2d7ssXPq7+I dJewvY6mLQJkAYyc9HQ== X-Received: by 2002:a05:6870:4d16:b0:1f0:edce:184c with SMTP id pn22-20020a0568704d1600b001f0edce184cmr5052538oab.54.1700689083031; Wed, 22 Nov 2023 13:38:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqhH5WZBfQ+Qo/p5TQWBvVELo4B32mUPzUmFZSM3s4i3TPRsC4koX+lw18ZqtBL6Nx0LSaww== X-Received: by 2002:a05:6870:4d16:b0:1f0:edce:184c with SMTP id pn22-20020a0568704d1600b001f0edce184cmr5052519oab.54.1700689082687; Wed, 22 Nov 2023 13:38:02 -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 j4-20020a05620a288400b0076efaec147csm198712qkp.45.2023.11.22.13.38.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 13:38:01 -0800 (PST) Message-ID: Date: Wed, 22 Nov 2023 16:38:01 -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: <9890a007-755e-41e2-bc33-37ebf0755435@redhat.com> <1MdaTybBd_o4uw-Gb23fYyd5GNz7qFqoSe_f5h90LY_BdzM2ge2qPSyCuiCLYoYcZSjmVv13fw1LmjQC_M2L8raS1fydY5pEJ_vwvv5Z-0k=@protonmail.com> <9OlK_2c3Punfm3w-wEHqyHGyKGG8Gr_K0BUnDOuC9Aazur4mWlAM5WuL1Ea0AMLvFLl6LKFVTs813yY0zA7m0_ji_R9qhE52G7MZXrVPfZE=@protonmail.com> From: Jason Merrill In-Reply-To: <9OlK_2c3Punfm3w-wEHqyHGyKGG8Gr_K0BUnDOuC9Aazur4mWlAM5WuL1Ea0AMLvFLl6LKFVTs813yY0zA7m0_ji_R9qhE52G7MZXrVPfZE=@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/22/23 15:46, waffl3x wrote: > On Tuesday, November 21st, 2023 at 8:22 PM, Jason Merrill wrote: >> On 11/21/23 08:04, waffl3x wrote: >> >>> /* Nonzero for FUNCTION_DECL means that this decl is a non-static >>> - member function. */ >>> + member function, use DECL_IOBJ_MEMBER_FUNC_P instead. */ >>> #define DECL_NONSTATIC_MEMBER_FUNCTION_P(NODE) \ >>> (TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE) >>> >>> +/* Nonzero for FUNCTION_DECL means that this decl is an implicit object >>> + member function. */ >>> +#define DECL_IOBJ_MEMBER_FUNC_P(NODE) \ >>> + (TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE) >> >> I was thinking to rename DECL_NONSTATIC_MEMBER_FUNCTION_P rather than >> add a new, equivalent one. And then go through all the current uses of >> the old macro to decide whether they mean IOBJ or OBJECT. > > I figure it would be easier to make that transition if there's a clear > line between old versus new. To be clear, my intention is for the old > macro to be removed once all the uses of it are changed over to the new > macro. I can still remove it for the patch if you like but having both > and removing the old one later seems better to me. Hmm, I think changing all the uses is a necessary part of this change. I suppose it could happen before the main patch, if you'd prefer, but it seems more straightforward to include it. >>> + else if (declarator->declarator->kind == cdk_pointer) >>> + error_at (DECL_SOURCE_LOCATION (xobj_parm), >>> + /* "a pointer to function type cannot "? */ >>> + "a function pointer type cannot " >>> + "have an explicit object parameter"); >> >> "pointer to function type", yes. >> >>> + /* The locations being used here are probably not correct. */ >> >> Why not? > > I threw them in just so I could call inform, but it doesn't feel like > the messages should be pointing at the parameter, but rather at the > full type declaration. When I put those locations in I wasn't sure how > to get the full declaration location, and I'm still not 100% confident > in how to do it, so I just threw them in and moved on. That would be more precise, but I think it's actually preferable for the inform to have the same location as the previous error to avoid redundant quoting of the source. >> Let's clear xobj_parm after giving an error in the TYPENAME case > > I don't like the spirit of this very much, whats your reasoning for > this? We're nearly at the end of the scope where it is last used, I > think it would be more unclear if we suddenly set it to NULL_TREE near > the end. It raises the question of whether that assignment actually > does anything, or if we are just trying to indicate that it isn't being > used anymore, but I already made sure to declare it in the deepest > scope possible. That much should be sufficient for indicating it's > usage, no? Hmm, I think I poked at that and changed my mind, but forgot to delete the suggestion. Never mind. >>> if ((!methodp && !DECL_XOBJ_MEMBER_FUNC_P (decl)) >>> || DECL_STATIC_FUNCTION_P (decl)) >> >> I think this can just be if (DECL_OBJECT_MEMBER_FUNC_P (decl)). > > Alright, and going forward I'll try to make more changes that are > consistent with this one. With that said I'm not sure it can, but I'll > take a close look and if you're right I'll make that change. > >>> if (TREE_CODE (fntype) == METHOD_TYPE) >>> ctype = TYPE_METHOD_BASETYPE (fntype); >>> + else if (DECL_XOBJ_MEMBER_FUNC_P (decl1)) >>> + ctype = DECL_CONTEXT (decl1); >> >> All of this can be >> >> if (DECL_CLASS_SCOPE_P (decl1)) >> ctype = DECL_CONTEXT (decl1); >> >> I think I'm going to go ahead and clean that up now. > > Sounds good to me, a lot of this stuff needs small cleanups and I'm > just concerned about making them too much. My cleanup of the ctype logic is in now. >>> + /* Error reporting here is a little awkward, if the type of the >>> + object parameter is deduced, we should tell them the lambda >>> + is effectively already const, or to make the param const if it is >>> + not, but if it is deduced and taken by value shouldn't we say >>> + that it's taken by copy and won't mutate? >>> + Seems right to me, but it's a little strange. */ >> >> I think just omit the inform if dependent_type_p. > > Maybe I don't understand what a dependent type is as well as I thought, > but doesn't this defeat every useful case? The most common being an > xobj parameter of lambda type, which will always be deduced. Unless a > template parameter does not count as a dependent type, which is not > something I've ever thought about before. No, you're right. A template parameter is certainly dependent. I think the informs are fine as they are. > Mildly related, a lot of the stuff I hacked together with multiple > levels of accessing macros and predicates was due to not being able to > find a solution for what I needed. I think we would highly benefit from > better documentation of the accessors and predicates. I believe I've > seen some that appear to be duplicates, and some where they don't > appear to be implemented properly or match their description. If there > is such a document please direct me to it as I have spent an hour or so > each time I stumble on one of these problems. > > In the section I wrote in add_method I spent I think about 3 hours > trying to figure out what combination of predicates and accessing > macros was correct for what I was trying to do. It gets pretty > convoluted to traverse, especially when the implementations of them are > rather involved. Finding non_reference was a big help for example, and > I stumbled across it by pure luck. > > If we don't have this kind of documentation anywhere yet, I'm happy to > work on it next. I've spent a lot of time looking at it all so I feel > like I have a DECENT grasp on some of it. I think it would greatly > enhance the status quo, and might even help us figure out what needs to > be cleaned up, removed, replaced, etc. > > Side side note, if said document does exist already, I either need to > learn how to search the wiki more effectively or it needs some sort of > improvement. There isn't really such a document; the comments are the main internals documentation, such as it is. I wonder about reorganizing cp-tree.h rather than creating a separate document that is likely to go out of date more quickly? Jason