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 8B6AF3858D20 for ; Thu, 7 Sep 2023 18:36:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B6AF3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694111804; 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=CLKdwWSuB8znrtYon0Ys+qfjOaZF/KpbOeL9hhOFGgo=; b=Ls8kzQ7Aguo14wJZAsA6Ji3KE9Rrap13K4mMB6N1GdBWOkuqmkkG5zg7KcIi3GHh2+Xr6E l7R1Z9lmhE6rCZR5CEWCAk9EhoF8xfkh6mmqqkrFcgKZ0UgmxcKk4hFJkyowFvkZ84WF05 KETqBSbVYJ43ydWOQ2lVwE3YjrWHP5Q= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-380-eaGFt7EMPAWnBRKGT8963w-1; Thu, 07 Sep 2023 14:36:41 -0400 X-MC-Unique: eaGFt7EMPAWnBRKGT8963w-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-76f2bd12e39so127925785a.2 for ; Thu, 07 Sep 2023 11:36:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694111801; x=1694716601; 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=CLKdwWSuB8znrtYon0Ys+qfjOaZF/KpbOeL9hhOFGgo=; b=uvg2PfsiC/wU5JquEZVYkFjDCHubyjYRqNbMi+BQmykKQECrOux5diNBf4coDBDgrb IHC3b3VYh9ZYAvW6hFjjwWL+chS6yjeHqgwVV1RFn3mHQmiDbIj8Ky+4dukz5rJgjxev SbvNqpNNArlWTeWYB+/3Rfx/wa2jUcmZ5KhNSu1jszV+pP/miyuOqKO5WK71wW0IXeaA QjI2gn4dHku4L1/CToFwDl4MzpMOtsefmuwXPDOIKoWiQHpleP+pPSTKKdYgbcBO7EhA xChXUVCpuQFC0bU2Sri3nKImEkv3xmmhXfM+yAuvQOkvawaHLdOI1svg3MGQpUsyFoa6 Qeqg== X-Gm-Message-State: AOJu0YxuDwy8+OyRimJsNDSjFMhLXZAXkEMTQFbhvlpi9g8dvf/hlx1Q dtKPRb3YdHkH1q4zx33ixc8eTsIYKDuwUZwKRB0lNGjeiEpAB02DXQlxCg7lcaS9bfYue9YBc5v g2wFweZ3KMIu8DaI9GtMj/XrhPQ== X-Received: by 2002:a05:620a:992:b0:76e:f1c0:7fe3 with SMTP id x18-20020a05620a099200b0076ef1c07fe3mr296992qkx.78.1694111800981; Thu, 07 Sep 2023 11:36:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0y9OhaeU8EL3DbCJ065tQBaFJ5EwX1VRNd7QCFRguNsWOpFyBHWjbq3qPF2H23h/4k57r2Q== X-Received: by 2002:a05:620a:992:b0:76e:f1c0:7fe3 with SMTP id x18-20020a05620a099200b0076ef1c07fe3mr296977qkx.78.1694111800599; Thu, 07 Sep 2023 11:36:40 -0700 (PDT) Received: from [192.168.1.108] (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 pj23-20020a05620a1d9700b0076ce061f44dsm5979210qkn.25.2023.09.07.11.36.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Sep 2023 11:36:39 -0700 (PDT) Message-ID: <8417a150-3d0c-8a7d-e01b-8e6f4bad1b05@redhat.com> Date: Thu, 7 Sep 2023 14:36:39 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH] c++: refine CWG 2369 satisfaction vs non-dep convs [PR99599] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230822015139.1920183-1-ppalka@redhat.com> <04bfb515-906c-21d3-311f-0a1c022e3b22@redhat.com> From: Jason Merrill In-Reply-To: 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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP 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 9/6/23 18:09, Patrick Palka wrote: > On Mon, 28 Aug 2023, Jason Merrill wrote: > >> On 8/24/23 09:31, Patrick Palka wrote: >>> On Wed, 23 Aug 2023, Jason Merrill wrote: >>> >>>> On 8/21/23 21:51, Patrick Palka wrote: >>>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look like >>>>> a reasonable approach? I didn't observe any compile time/memory impact >>>>> of this change. >>>>> >>>>> -- >8 -- >>>>> >>>>> As described in detail in the PR, CWG 2369 has the surprising >>>>> consequence of introducing constraint recursion in seemingly valid and >>>>> innocent code. >>>>> >>>>> This patch attempts to fix this surpising behavior for the majority >>>>> of problematic use cases. Rather than checking satisfaction before >>>>> _all_ non-dependent conversions, as specified by the CWG issue, >>>>> this patch makes us first check "safe" non-dependent conversions, >>>>> then satisfaction, then followed by "unsafe" non-dependent conversions. >>>>> In this case, a conversion is "safe" if computing it is guaranteed >>>>> to not induce template instantiation. This patch heuristically >>>>> determines "safety" by checking for a constructor template or conversion >>>>> function template in the (class) parm or arg types respectively. >>>>> If neither type has such a member, then computing the conversion >>>>> should not induce instantiation (modulo satisfaction checking of >>>>> non-template constructor and conversion functions I suppose). >>>>> >>>>> + /* We're checking only non-instantiating conversions. >>>>> + A conversion may instantiate only if it's to/from a >>>>> + class type that has a constructor template/conversion >>>>> + function template. */ >>>>> + tree parm_nonref = non_reference (parm); >>>>> + tree type_nonref = non_reference (type); >>>>> + >>>>> + if (CLASS_TYPE_P (parm_nonref)) >>>>> + { >>>>> + if (!COMPLETE_TYPE_P (parm_nonref) >>>>> + && CLASSTYPE_TEMPLATE_INSTANTIATION (parm_nonref)) >>>>> + return unify_success (explain_p); >>>>> + >>>>> + tree ctors = get_class_binding (parm_nonref, >>>>> + complete_ctor_identifier); >>>>> + for (tree ctor : lkp_range (ctors)) >>>>> + if (TREE_CODE (ctor) == TEMPLATE_DECL) >>>>> + return unify_success (explain_p); >>>> >>>> Today we discussed maybe checking CLASSTYPE_NON_AGGREGATE? >>> >>> Done; all dups of this PR seem to use tag types that are aggregates, so this >>> seems like a good simplification. I also made us punt if the arg type has a >>> constrained non-template conversion function. >>> >>>> >>>> Also, instantiation can also happen when checking for conversion to a >>>> pointer >>>> or reference to base class. >>> >>> Oops, I suppose we just need to strip pointer types upfront as well. The >>> !COMPLETE_TYPE_P && CLASSTYPE_TEMPLATE_INSTANTIATION tests will then make >>> sure we deem a potential derived-to-base conversion unsafe if appropriate >>> IIUC. >>> >>> How does the following look? >>> >>> -- >8 -- >>> >>> Subject: [PATCH] c++: refine CWG 2369 satisfaction vs non-dep convs >>> [PR99599] >>> >>> PR c++/99599 >>> >>> gcc/cp/ChangeLog: >>> >>> * config-lang.in (gtfiles): Add search.cc. >>> * pt.cc (check_non_deducible_conversions): Add bool parameter >>> passed down to check_non_deducible_conversion. >>> (fn_type_unification): Call check_non_deducible_conversions >>> an extra time before satisfaction with noninst_only_p=true. >>> (check_non_deducible_conversion): Add bool parameter controlling >>> whether to compute only conversions that are guaranteed to >>> not induce template instantiation. >>> * search.cc (conversions_cache): Define. >>> (lookup_conversions): Use it to cache the lookup. Improve cache >>> rate by considering TYPE_MAIN_VARIANT of the type. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/cpp2a/concepts-nondep4.C: New test. >>> --- >>> gcc/cp/config-lang.in | 1 + >>> gcc/cp/pt.cc | 81 +++++++++++++++++-- >>> gcc/cp/search.cc | 14 +++- >>> gcc/testsuite/g++.dg/cpp2a/concepts-nondep4.C | 21 +++++ >>> 4 files changed, 110 insertions(+), 7 deletions(-) >>> create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-nondep4.C >>> >>> @@ -22921,6 +22933,65 @@ check_non_deducible_conversion (tree parm, tree >>> arg, unification_kind_t strict, >>> { >>> bool ok = false; >>> tree conv_arg = TYPE_P (arg) ? NULL_TREE : arg; >>> + if (conv_p && *conv_p) >>> + { >>> + /* This conversion was already computed earlier (when >>> + computing only non-instantiating conversions). */ >>> + gcc_checking_assert (!noninst_only_p); >>> + return unify_success (explain_p); >>> + } >>> + if (noninst_only_p) >>> + { >>> + /* We're checking only non-instantiating conversions. >>> + Computing a conversion may induce template instantiation >>> + only if ... */ >> >> Let's factor this whole block out into another function. > > Sounds good. > >> >> Incidentally, CWG1092 is a related problem with defaulted functions, which I >> dealt with in a stricter way: when LOOKUP_DEFAULTED we ignore a conversion >> from the parameter being copied to a non-reference-related type. As a >> follow-on, it might make sense to use this test there as well? > > Interesting, I can look into that. > >> >>> + tree parm_inner = non_reference (parm); >>> + tree type_inner = non_reference (type); >>> + bool ptr_conv_p = false; >>> + if (TYPE_PTR_P (parm_inner) >>> + && TYPE_PTR_P (type_inner)) >>> + { >>> + parm_inner = TREE_TYPE (parm_inner); >>> + type_inner = TREE_TYPE (type_inner); >>> + ptr_conv_p = true; >>> + } >> >> I think we also want to set ptr_conv_p if the types are reference_related_p? > > Ah, because in that case we know the selected conversion will always be > a derived-to-base conversion? That sounds like a nice refinement. > >> >>> + /* ... conversion functions are considered and the arg's class >>> + type has one that is a template or is constrained. */ >> >> Maybe just check TYPE_HAS_CONVERSION without digging into the actual >> conversions, like with CLASSTYPE_NON_AGGREGATE? >> > > Sounds good, I split out the conversion function caching into a separate > patch. > > Like so? OK. > -- >8 -- > > Subject: [PATCH] c++: refine CWG 2369 satisfaction vs non-dep convs [PR99599] > > PR c++/99599 > > gcc/cp/ChangeLog: > > * pt.cc (check_non_deducible_conversions): Add bool parameter > passed down to check_non_deducible_conversion. > (fn_type_unification): Call check_non_deducible_conversions > an extra time before satisfaction with noninst_only_p=true. > (conversion_may_instantiate_p): Define. > (check_non_deducible_conversion): Add bool parameter controlling > whether to compute only conversions that are guaranteed to > not induce template instantiation.