From patchwork Thu Dec 1 20:57:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 61331 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51B53385840C for ; Thu, 1 Dec 2022 20:57:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51B53385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669928256; bh=QwQaBAnkZO8mz0FlMuT43TbVlOgf4pUVBS1CQF6hzQM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ENaddJ8KmumrR0RYVSAfzFNmX99l4zsXB7DWRXFj/Vaj38E6D6VZIEB2MXko7Yko0 IyRV9SXE3zIR7paGc1mtMfcRGLimEKKVY6T1YC+aTiS+ETFVSNe049KgF3kfrKofhY 1SXNMXGPOw2fK/BV4Qi0O8rzJKu4vFIbnKSwuErA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 EED0E3858D32 for ; Thu, 1 Dec 2022 20:57:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EED0E3858D32 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-596-1jtY9YRrOd6n4FfxMfdMjw-1; Thu, 01 Dec 2022 15:57:06 -0500 X-MC-Unique: 1jtY9YRrOd6n4FfxMfdMjw-1 Received: by mail-qv1-f72.google.com with SMTP id q17-20020a056214019100b004b1d3c9f3acso8432704qvr.0 for ; Thu, 01 Dec 2022 12:57:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QwQaBAnkZO8mz0FlMuT43TbVlOgf4pUVBS1CQF6hzQM=; b=mRouFVmzaTlEBPS7oEg9lQ36QXCTZXDFDsThJ5UBQDGFgpMWd7J4JYHsVZsZbn6YjW nNtuSaiQnDEw/GZjibf9RhGoScJdGHsM1OzHdBLoVKesYQ0Jog602QpZUTk/id8kDa/z KfcJwyhAtzBCz3jaG6P0MdISnlccq+P8j2uljZB7uIoL9B579F1qgG0KzsfWRNOZxZ1s yeCeSNagrTUZWxX7TAEwihlgoSN2E9qklHNbwl50guSFhv6cjlTKYO9fPzrvi1f8Ybjh exO8z+8FlhqcRmyLysrZEzE7wwZH4rZDvKPr73BM5OJQ4eUghdFtBR6wmbKiSNP1gKAM 6nzQ== X-Gm-Message-State: ANoB5plUY70Q9eHrXrDOriTPqKh3kAwe8K8g5pURxydxC6Wk3ujnDdua ZEpUJuj4Asmw/JC+0/LhTffQTpH23kafUthHfRPFbeT6OF6fk47Ls7VuFkPXNJrQtkFr3UwxFKC nc05YJhACS+XaMdlKBSaIAZy0E7s/SReCQuFIHr46vcJRZOKWuksoLKPA/0ucT1JkdJ0= X-Received: by 2002:ac8:1117:0:b0:3a5:fa9c:69c7 with SMTP id c23-20020ac81117000000b003a5fa9c69c7mr63415905qtj.13.1669928225343; Thu, 01 Dec 2022 12:57:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7FcQaEFLtBnTuJmQ8haJbaG5Yl/VUuog17QuN86Rsdrx2smecb6eYxG50Hfx5QkPkNYSy8TA== X-Received: by 2002:ac8:1117:0:b0:3a5:fa9c:69c7 with SMTP id c23-20020ac81117000000b003a5fa9c69c7mr63415885qtj.13.1669928224969; Thu, 01 Dec 2022 12:57:04 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id bl12-20020a05620a1a8c00b006fbb4b98a25sm4085201qkb.109.2022.12.01.12.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 12:57:04 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: comptypes ICE with BOUND_TEMPLATE_TEMPLATE_PARMs [PR107539] Date: Thu, 1 Dec 2022 15:57:02 -0500 Message-Id: <20221201205702.2822213-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc0.49.g083e01275b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here the two BOUND_TEMPLATE_TEMPLATE_PARMs written as C end up having the same TYPE_CANONICAL since the ctp_table (which interns the canonical form of a template type parameter) doesn't set the comparing_specializations flag which controls how PARM_DECLs from different DECL_CONTEXTs compare equal. Later (from spec_hasher::equal for the two specializations of i) we end up calling comptypes on these two types with comparing_specializations set, which notices their TYPE_CANONICAL is the same despite them no longer structurally comparing equal (thanks to the flag) and so we ICE: internal compiler error: same canonical type node for different types 'C' and 'C' This suggests that we should be setting comparing_specializations from ctp_hasher::equal as well. But doing so introduces an ICE in cpp2a/concepts-placeholder3.C: internal compiler error: canonical types differ for identical types 'auto [requires ::same_as<, decltype(f::x)>]' and 'auto [requires ::same_as<, decltype(g::x)>]' since norm_hasher::equal doesn't set comparing_specializations. I'm not sure when excatly we need to set comparing_specializations given that it controls three things (TYPENAME_TYPE equality/hashing and PARM_DECL equality) but it seems to be the conservative choice to set the flag whenever we have a global hash table that relies on structural equality of trees. To that end this patch sets comparing_specializations in ctp_hasher and the normalization/satisfaction hashers. This turns out to be a performance win of about 2% in some concepts tests, probably because improved TYPENAME_TYPE hashing enabled by the flag. Bootstrapped and regtested on x86_64-pc-linux-gnu, deos this look OK for trunk? PR c++/107539 gcc/cp/ChangeLog: * constraint.cc (norm_hasher::hash, norm_hasher::equal): Set comparing_specializations. (sat_hasher::hash, sat_hasher::equal): Likewise. * cp-tree.h (atom_hasher::hash, atom_hasher::equal): Likewise. * pt.cc (ctp_hasher::hash, ctp_hasher::equal): Likewise. gcc/testsuite/ChangeLog: * g++.dg/template/canon-type-19.C: New test. --- gcc/cp/constraint.cc | 18 +++++++++++++++--- gcc/cp/cp-tree.h | 10 ++++++++-- gcc/cp/pt.cc | 7 ++++++- gcc/testsuite/g++.dg/template/canon-type-19.C | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/canon-type-19.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index ab0f66b3d7e..37eae03afdb 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -715,14 +715,20 @@ struct norm_hasher : ggc_ptr_hash { static hashval_t hash (norm_entry *e) { - hashval_t hash = iterative_hash_template_arg (e->tmpl, 0); - return iterative_hash_template_arg (e->args, hash); + ++comparing_specializations; + hashval_t val = iterative_hash_template_arg (e->tmpl, 0); + val = iterative_hash_template_arg (e->args, val); + --comparing_specializations; + return val; } static bool equal (norm_entry *e1, norm_entry *e2) { - return e1->tmpl == e2->tmpl + ++comparing_specializations; + bool eq = e1->tmpl == e2->tmpl && template_args_equal (e1->args, e2->args); + --comparing_specializations; + return eq; } }; @@ -2530,6 +2536,9 @@ struct sat_hasher : ggc_ptr_hash { static hashval_t hash (sat_entry *e) { + auto cso = make_temp_override (comparing_specializations); + ++comparing_specializations; + if (ATOMIC_CONSTR_MAP_INSTANTIATED_P (e->atom)) { /* Atoms with instantiated mappings are built during satisfaction. @@ -2564,6 +2573,9 @@ struct sat_hasher : ggc_ptr_hash static bool equal (sat_entry *e1, sat_entry *e2) { + auto cso = make_temp_override (comparing_specializations); + ++comparing_specializations; + if (ATOMIC_CONSTR_MAP_INSTANTIATED_P (e1->atom) != ATOMIC_CONSTR_MAP_INSTANTIATED_P (e2->atom)) return false; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 548b533266a..addd26ea077 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8418,12 +8418,18 @@ struct atom_hasher : default_hash_traits { static hashval_t hash (tree t) { - return hash_atomic_constraint (t); + ++comparing_specializations; + hashval_t val = hash_atomic_constraint (t); + --comparing_specializations; + return val; } static bool equal (tree t1, tree t2) { - return atomic_constraints_identical_p (t1, t2); + ++comparing_specializations; + bool eq = atomic_constraints_identical_p (t1, t2); + --comparing_specializations; + return eq; } }; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 08de273a900..31691618d1b 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -4492,18 +4492,23 @@ struct ctp_hasher : ggc_ptr_hash { static hashval_t hash (tree t) { + ++comparing_specializations; tree_code code = TREE_CODE (t); hashval_t val = iterative_hash_object (code, 0); val = iterative_hash_object (TEMPLATE_TYPE_LEVEL (t), val); val = iterative_hash_object (TEMPLATE_TYPE_IDX (t), val); if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) val = iterative_hash_template_arg (TYPE_TI_ARGS (t), val); + --comparing_specializations; return val; } static bool equal (tree t, tree u) { - return comptypes (t, u, COMPARE_STRUCTURAL); + ++comparing_specializations; + bool eq = comptypes (t, u, COMPARE_STRUCTURAL); + --comparing_specializations; + return eq; } }; diff --git a/gcc/testsuite/g++.dg/template/canon-type-19.C b/gcc/testsuite/g++.dg/template/canon-type-19.C new file mode 100644 index 00000000000..06b0f08931d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/canon-type-19.C @@ -0,0 +1,18 @@ +// PR c++/107539 +// { dg-do compile { target c++11 } } + +template +struct i { }; + +template class C> +struct a { + template + void f(T t) { + i> i1; + } + + template + void g(T t) { + i> i2; + } +};