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 26A263858CD1 for ; Thu, 23 May 2024 19:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26A263858CD1 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 26A263858CD1 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=1716494229; cv=none; b=M79JTBvWiutn0cWBnjMbOFsy0kQdSVP2LHVzMMbQVovmDttmjQZWYhxlrMImKAaRjv3KkDe7qfQFWEm7pmM78ruZYInSGnx7JpWr6DH7Q/NBcdg2I07O9Hv+yBcJp5IknKVbnOO6qfAJocVq1TP+tMKziZ0/+0a2lPjxYXZkaVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716494229; c=relaxed/simple; bh=+7vEw0tAhd/ZmHvpiA+DMhG0mfwoUkUtPsaq0yc/5Kk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=vzkq9XWcXsbxBnZbcjCeunchucJ3FN9BVOZPi0J2w4JEeRRXv2pqlwiyiVSPCkLJ5RbsHru4msgPzjZ2a6bmcWHI705sM7bfuNaAVqpbh/TUGM9JDPolHXenpYlA0nVXbm8hT49rkojWwHYMb4S8Z1J26tjrJ+OjNi7/nHxx6VQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716494225; 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=qYhmIzpVURl/MnKLsKfRpYBpZQmYnSxn7QoWjV1D3W0=; b=E3m+ddfTMrAMnfhx5cjbyp+Ie3EOXFLhnNbWK82hCWx717l2BFMHdi1CZIskEh0op8A+OS oFYqBudczxSfHdN1SHkVwMOs2xpwnBPcgrJobpVjlz+utoXnd2DuW654QB9rR8xoJggxrP h6S4qA9C4i1J7DwXmJfEWm/DF+BSsMw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-yTGVvTpuO12IHZh1Um587w-1; Thu, 23 May 2024 15:57:02 -0400 X-MC-Unique: yTGVvTpuO12IHZh1Um587w-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-794ab0f2952so12875785a.0 for ; Thu, 23 May 2024 12:57:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716494221; x=1717099021; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qYhmIzpVURl/MnKLsKfRpYBpZQmYnSxn7QoWjV1D3W0=; b=NtDghhv4DrnCLyqqd3ULIz0yaHCGI21LEtoAxPFOmpbFll2+EICwfe+ffpYAWpzbMv nx2lGnmaQ93cJruJIMnX3h2R2FuRy4Cbss5PuQHc26UpWe3VUAmqIB84XTytrwuifghR YuSbiIl1qibt//iSLNMfl/HYHS8tx57Z6LdJe7CsKrcxspouJyU0mq7uPMGAJmBpO6k3 Q2zyA/6qRsW8TsBeaEin3MPT595UT7rkCd0zROMwZEX1+sIjit0DI8sHU2FuDn9T6xNx AaCz1hAT//OnLjNrlkhQREtaaLcJq60xlt9izTD2kbZnMN6F+w1s9nkYrl2L6dG+jtwz Nkpg== X-Forwarded-Encrypted: i=1; AJvYcCUjxlkpwGnuxAhZWhq5VNPrRZBM3ZcXU10I2a+kiiw0eEc167AQdWXrHfN6sW/u5jVJuozkBp4v9rTYfnE61WKF9HYfiHXzAw== X-Gm-Message-State: AOJu0YyAAEbkrfHaiQxh67HWXnHWmDnY6TMd/uKhbjFnq8+y4YKmSQqy Ct+o16xBCZPBjDMUOE94Do9hXDY+jrieYIWcLFraVV8sP5Ah/gqFGE6MpwLKgOkZSyqKcRCsCfc DlJZECHPWGQjr5f0nPyZGUppF3y8gcDgEfEVYUwxdmzsDpf0la8lf/0I= X-Received: by 2002:a05:620a:190d:b0:792:ff9a:1834 with SMTP id af79cd13be357-794aa84d220mr98944585a.28.1716494221479; Thu, 23 May 2024 12:57:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZwf8OzgWX6pxWKNTITl5wyC3Akf5ka9w+X1aUAwBX92w5oTqkJGo6euTCbeNajT8jrm6XCQ== X-Received: by 2002:a05:620a:190d:b0:792:ff9a:1834 with SMTP id af79cd13be357-794aa84d220mr98942185a.28.1716494221053; Thu, 23 May 2024 12:57:01 -0700 (PDT) Received: from [192.168.1.130] (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 af79cd13be357-792bf3106c2sm1517325585a.106.2024.05.23.12.57.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 12:57:00 -0700 (PDT) Message-ID: <5164fd27-5a68-4b07-954c-e57e519b8ebd@redhat.com> Date: Thu, 23 May 2024 15:56:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++/modules: Ensure all partial specialisations are tracked [PR114947] To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Nathan Sidwell References: <6640c449.170a0220.9790b.fc84@mx.google.com> From: Jason Merrill In-Reply-To: <6640c449.170a0220.9790b.fc84@mx.google.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=-12.3 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 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 5/12/24 09:29, Nathaniel Shead wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? > > -- >8 -- > > Constrained partial specialisations aren't all necessarily tracked on > the instantiation table. The modules code uses a separate > 'partial_specializations' table to track them instead to ensure that > they get walked and emitted when emitting a module, but currently this > does not always happen. > > The attached testcase fails in two ways. First, because the partial > specialisation is just a declaration (and not a definition), > 'set_defining_module' never ends up getting called on it and so it never > gets added to the partial specialisation table. We fix this by ensuring > that when partial specializations are created they always get added, and > so we never miss one. To prevent adding partial specialisations multiple > times we split this out as a new function. Hmm, I wonder if it would make sense to move DECL_TEMPLATE_SPECIALIZATIONS from the template's DECL_SIZE into a hash table that the modules code could walk instead of managing its own separate table? The patch is OK. > The second way it fails is that when exporting the primary interface for > a module with partitions, we also re-walk the specializations of all > imported partitions to merge them into a single BMI. So this patch > ensures that after calling 'match_mergeable_specialization' we also > ensure that if the name came from a partition it gets added to the > specialization table so that a dependency is correctly created for it. > > PR c++/114947 > > gcc/cp/ChangeLog: > > * cp-tree.h (set_defining_module_for_partial_spec): Declare. > * module.cc (trees_in::decl_value): Track partial specs coming > from partitions. > (set_defining_module): Don't track partial specialisations here > anymore. > (set_defining_module_for_partial_spec): New function. > * pt.cc (process_partial_specialization): Call it. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/partial-4_a.C: New test. > * g++.dg/modules/partial-4_b.C: New test. > > Signed-off-by: Nathaniel Shead > --- > gcc/cp/cp-tree.h | 1 + > gcc/cp/module.cc | 22 ++++++++++++++++++---- > gcc/cp/pt.cc | 2 ++ > gcc/testsuite/g++.dg/modules/partial-4_a.C | 8 ++++++++ > gcc/testsuite/g++.dg/modules/partial-4_b.C | 5 +++++ > 5 files changed, 34 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/modules/partial-4_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/partial-4_b.C > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index db098c32f2d..2580bf05fb2 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7418,6 +7418,7 @@ extern unsigned get_importing_module (tree, bool = false) ATTRIBUTE_PURE; > /* Where current instance of the decl got declared/defined/instantiated. */ > extern void set_instantiating_module (tree); > extern void set_defining_module (tree); > +extern void set_defining_module_for_partial_spec (tree); > extern void maybe_key_decl (tree ctx, tree decl); > extern void propagate_defining_module (tree decl, tree orig); > extern void remove_defining_module (tree decl); > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 520dd710549..3ca963cb3e9 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -8416,6 +8416,11 @@ trees_in::decl_value () > add_mergeable_specialization (!is_type, &spec, decl, spec_flags); > } > > + /* When making a CMI from a partition we're going to need to walk partial > + specializations again, so make sure they're tracked. */ > + if (state->is_partition () && (spec_flags & 2)) > + set_defining_module_for_partial_spec (inner); > + > if (NAMESPACE_SCOPE_P (decl) > && (mk == MK_named || mk == MK_unique > || mk == MK_enum || mk == MK_friend_spec) > @@ -19246,13 +19251,22 @@ set_defining_module (tree decl) > vec_safe_push (class_members, decl); > } > } > - else if (DECL_IMPLICIT_TYPEDEF_P (decl) > - && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl))) > - /* This is a partial or explicit specialization. */ > - vec_safe_push (partial_specializations, decl); > } > } > > +/* Also remember DECL if it's a newly declared class template partial > + specialization, because these are not necessarily added to the > + instantiation tables. */ > + > +void > +set_defining_module_for_partial_spec (tree decl) > +{ > + if (module_p () > + && DECL_IMPLICIT_TYPEDEF_P (decl) > + && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl))) > + vec_safe_push (partial_specializations, decl); > +} > + > void > set_originating_module (tree decl, bool friend_p ATTRIBUTE_UNUSED) > { > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 1816bfd1f40..6d33bac90b0 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -5456,6 +5456,8 @@ process_partial_specialization (tree decl) > gcc_checking_assert (!TI_PARTIAL_INFO (tinfo)); > TI_PARTIAL_INFO (tinfo) = build_template_info (tmpl, NULL_TREE); > > + set_defining_module_for_partial_spec (decl); > + > for (inst = DECL_TEMPLATE_INSTANTIATIONS (maintmpl); inst; > inst = TREE_CHAIN (inst)) > { > diff --git a/gcc/testsuite/g++.dg/modules/partial-4_a.C b/gcc/testsuite/g++.dg/modules/partial-4_a.C > new file mode 100644 > index 00000000000..e74bb0ad866 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/partial-4_a.C > @@ -0,0 +1,8 @@ > +// PR c++/114947 > +// { dg-additional-options "-fmodules-ts -std=c++20" } > +// { dg-module-cmi M:part } > +module M:part; > + > +template struct R {}; > +template requires false struct R {}; > +template requires true struct R; > diff --git a/gcc/testsuite/g++.dg/modules/partial-4_b.C b/gcc/testsuite/g++.dg/modules/partial-4_b.C > new file mode 100644 > index 00000000000..1c645671a55 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/partial-4_b.C > @@ -0,0 +1,5 @@ > +// PR c++/114947 > +// { dg-additional-options "-fmodules-ts -std=c++20" } > +// { dg-module-cmi M } > +export module M; > +import :part;