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.129.124]) by sourceware.org (Postfix) with ESMTPS id 8076F3857C6B for ; Mon, 18 Dec 2023 21:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8076F3857C6B 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 8076F3857C6B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702936669; cv=none; b=dr69TY8ZP+sQ+CJ0ly9dtr1c4sfO//yyWkDONphveN55CyhYTa5a7d/1by7FqKABhJJoQzBWek2kt2DlpXeH8q8JxMg4QawiAhL4Kqx4ychpaRvez+oWPM1GTIjdjeBRtHmoN1QI3ZBhnaHBPL+pvAbocWXuzuehJWXZWMJhvcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702936669; c=relaxed/simple; bh=cBarficZpjDRl9ANAtGSN02wlQLyIhwTsxt1ZRdwHkE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Rx20DVoJWgC4ynS6WITerT9DGe9J7zgSRtaelgJJ1n0sCqRuG09jK+zY99VQIl/Hb5nFdykUqiucAPbFjSQYfKs1yk32IU7lJjSOBIuwMkh8yx2mts+l7tZd1G3hqaa2iotOqebGWro50M6lqHWZ+AamZjeIivk/j/i1hX6M+I0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702936667; 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=LgzUdYKhg41RPgJbt1DMH3L9Nu5dGd/eG0cl9hhAcnM=; b=VZssPmvTmYzMOHl5mVPjE+W2Xoq4VhBlhNsZbZ+kQbWFaHSwJv8udLff6c8LEOgsfxsDME ZsWONEv6dMQMunKneZbxh83LJqLEH6SuolX50dIJ04RmEEXCK3x7u8WjHx0/u9Di17x7wt lamveGQzHomST1ipm0c0/ZhYkyRrWBY= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-XRzyXggIMrKiczRtV94mdQ-1; Mon, 18 Dec 2023 16:57:45 -0500 X-MC-Unique: XRzyXggIMrKiczRtV94mdQ-1 Received: by mail-vk1-f198.google.com with SMTP id 71dfb90a1353d-4b6d1aba011so394364e0c.2 for ; Mon, 18 Dec 2023 13:57:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702936665; x=1703541465; 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=LgzUdYKhg41RPgJbt1DMH3L9Nu5dGd/eG0cl9hhAcnM=; b=PEzb9czKYcgpuPu9hRJPn6z9pciOu+IYwxBgw8dkKIUyD5lxdnKaP4AVGZQb8jMVzJ pt+U/BCFFZCTAtO4AErFA1z4qLd9UlaAp387GPnMiw5uLmxrJrjK0mZCfrAHZwK2D0M4 hS6GpDK6YMlUb/cJ2ta3LoLEJRIP3gv6dngShW4LIa1lEID8myqiYPVNrXjbrUfotWLl SoRe6Y/WAPCCmlrb8cD+r02GUChublj2EqDQjuYPtcnVjvNyNI+GVC6ZqovdhoUg1Ffn +m+b4RSDHP8MSxEVYQcl2MSb07R3/zGK3WORFAySvXUfWKqV+sCAz4xqfGU8AgMERIoV f4ww== X-Gm-Message-State: AOJu0Yx5mKHpiwYfEKw+h38TTzAPy1G3vInsU393X0btq2zt0sNDL0lk ndlIkrfw8EMSkJbmdskYCqLXKXxWvUfeAM6hhpVyy0fIxSrzObtVC6k4zoxW4Q0U+YIkp8jmhfs IfjTV1AE/Gbe765sHQg== X-Received: by 2002:a05:6122:2802:b0:4b6:c882:65e7 with SMTP id en2-20020a056122280200b004b6c88265e7mr1313576vkb.16.1702936664724; Mon, 18 Dec 2023 13:57:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqgMHZx4TEe0mKjEROeZ0V5O9lofUIXske2oWeRSy0JFMBt89dndJ62duvgdboj+38ux0ZSw== X-Received: by 2002:a05:6122:2802:b0:4b6:c882:65e7 with SMTP id en2-20020a056122280200b004b6c88265e7mr1313573vkb.16.1702936664386; Mon, 18 Dec 2023 13:57:44 -0800 (PST) Received: from [192.168.1.146] (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 ty5-20020a05620a3f4500b0077d9aa74e40sm8636452qkn.68.2023.12.18.13.57.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 13:57:43 -0800 (PST) Message-ID: <8c4c786e-8233-42ea-bd89-3db4418e269f@redhat.com> Date: Mon, 18 Dec 2023 16:57:43 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] c++: partial ordering and dep alias tmpl specs [PR90679] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230601144938.765175-1-ppalka@redhat.com> <20230601144938.765175-2-ppalka@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=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,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 12/15/23 14:07, Patrick Palka wrote: > On Thu, 1 Jun 2023, Patrick Palka wrote: > >> During partial ordering, we want to look through dependent alias >> template specializations within template arguments and otherwise >> treat them as opaque in other contexts (see e.g. r7-7116-g0c942f3edab108 >> and r11-7011-g6e0a231a4aa240). To that end template_args_equal was >> given a partial_order flag that controls this behavior. This flag >> does the right thing when a dependent alias template specialization >> appears as template argument of the partial specialization, e.g. in >> >> template using first_t = T; >> template struct traits; >> template struct traits> { }; // #1 >> template struct traits> { }; // #2 >> >> we correctly consider #2 to be more specialized than #1. But if >> the alias specialization appears as a template argument of another >> class template specialization, e.g. in >> >> template struct traits>> { }; // #1 >> template struct traits>> { }; // #2 >> >> then we incorrectly consider #1 and #2 to be unordered. This is because >> >> 1. we don't propagate the flag to recursive template_args_equal calls >> 2. we don't use structural equality for class template specializations >> written in terms of dependent alias template specializations >> >> This patch fixes the first issue by turning the partial_order flag into >> a global. This patch fixes the second issue by making us propagate >> structural equality appropriately when building a class template >> specialization. In passing this patch also improves hashing of >> specializations that use structural equality. >> >> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for >> trunk? >> >> PR c++/90679 >> >> gcc/cp/ChangeLog: >> >> * cp-tree.h (comp_template_args): Remove partial_order >> parameter. >> (template_args_equal): Likewise. >> * pt.cc (iterative_hash_template_arg) : Hash >> the template and arguments for specializations that use >> structural equality. >> (comparing_for_partial_ordering): New flag. >> (template_args_equal): Remove partial order parameter and >> use comparing_for_partial_ordering instead. >> (comp_template_args): Likewise. >> (comp_template_args_porder): Set comparing_for_partial_ordering >> instead. Make static. >> (any_template_arguments_need_structural_equality_p): Return true >> for an argument that's a dependent alias template specialization >> or a class template specialization that itself needs structural >> equality. >> * tree.cc (cp_tree_equal) : Adjust call to >> comp_template_args. >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/cpp0x/alias-decl-75a.C: New test. >> * g++.dg/cpp0x/alias-decl-75b.C: New test. > > Ping. Here's the rebased patch: > > -- >8 -- > > Subject: [PATCH 2/2] c++: partial ordering and dep alias tmpl specs [PR90679] > > During partial ordering, we want to look through dependent alias > template specializations within template arguments and otherwise > treat them as opaque in other contexts (see e.g. r7-7116-g0c942f3edab108 > and r11-7011-g6e0a231a4aa240). To that end template_args_equal was > given a partial_order flag that controls this behavior. This flag > does the right thing when a dependent alias template specialization > appears as template argument of the partial specialization, e.g. in > > template using first_t = T; > template struct traits; > template struct traits> { }; // #1 > template struct traits> { }; // #2 > > we correctly consider #2 to be more specialized than #1. But if > the alias specialization appears as a template argument of another > class template specialization, e.g. in > > template struct traits>> { }; // #1 > template struct traits>> { }; // #2 > > then we incorrectly consider #1 and #2 to be unordered. This is because > > 1. we don't propagate the flag to recursive template_args_equal calls > 2. we don't use structural equality for class template specializations > written in terms of dependent alias template specializations > > This patch fixes the first issue by turning the partial_order flag into > a global. This patch fixes the second issue by making us propagate > structural equality appropriately when building a class template > specialization. In passing this patch also improves hashing of > specializations that use structural equality. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? > > PR c++/90679 > > gcc/cp/ChangeLog: > > * cp-tree.h (comp_template_args): Remove partial_order > parameter. > (template_args_equal): Likewise. > * pt.cc (iterative_hash_template_arg) : Hash > the template and arguments for specializations that use > structural equality. > (comparing_for_partial_ordering): New flag. > (template_args_equal): Remove partial order parameter and > use comparing_for_partial_ordering instead. > (comp_template_args): Likewise. > (comp_template_args_porder): Set comparing_for_partial_ordering > instead. Make static. > (any_template_arguments_need_structural_equality_p): Return true > for an argument that's a dependent alias template specialization > or a class template specialization that itself needs structural > equality. > * tree.cc (cp_tree_equal) : Adjust call to > comp_template_args. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/alias-decl-75a.C: New test. > * g++.dg/cpp0x/alias-decl-75b.C: New test. > --- > gcc/cp/cp-tree.h | 4 +-- > gcc/cp/pt.cc | 40 +++++++++++++++++---- > gcc/cp/tree.cc | 2 +- > gcc/testsuite/g++.dg/cpp0x/alias-decl-75a.C | 26 ++++++++++++++ > gcc/testsuite/g++.dg/cpp0x/alias-decl-75b.C | 26 ++++++++++++++ > 5 files changed, 88 insertions(+), 10 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-75a.C > create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-75b.C > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index 85980c9ad9b..1979572c365 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7507,8 +7507,8 @@ extern int template_class_depth (tree); > extern int is_specialization_of (tree, tree); > extern bool is_specialization_of_friend (tree, tree); > extern bool comp_template_args (tree, tree, tree * = NULL, > - tree * = NULL, bool = false); > -extern int template_args_equal (tree, tree, bool = false); > + tree * = NULL); > +extern int template_args_equal (tree, tree); > extern tree maybe_process_partial_specialization (tree); > extern tree most_specialized_instantiation (tree); > extern tree most_specialized_partial_spec (tree, tsubst_flags_t, bool = false); > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index a3a79713236..6b0ef496dc5 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -1894,6 +1894,11 @@ iterative_hash_template_arg (tree arg, hashval_t val) > default: > if (tree canonical = TYPE_CANONICAL (arg)) > val = iterative_hash_object (TYPE_HASH (canonical), val); > + else if (tree ti = TYPE_TEMPLATE_INFO (arg)) > + { > + val = iterative_hash_template_arg (TI_TEMPLATE (ti), val); > + val = iterative_hash_template_arg (TI_ARGS (ti), val); > + } > break; > } > > @@ -9306,6 +9311,12 @@ coerce_template_parms (tree parms, > return return_full_args ? new_args : new_inner_args; > } > > +/* Whether we are comparing template arguments during partial ordering > + (and therefore want the comparison to look through dependent alias > + template specializations). */ > + > +static int comparing_for_partial_ordering; How about putting this next to comparing_dependent_aliases? OK with that change. Jason