From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 1AADB3858D33 for ; Thu, 23 May 2024 13:33:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AADB3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1AADB3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716471211; cv=none; b=vo68lXJuEfP19m7atBIXYW980oJcFA5Drb8ixbWaj381iI5cUdDLWKt0oWD3lwS4iXJW3CZYKYvVYZ2t3F2n62rQ45IBFa9cC/oAi3DLSAvxq8bt1RXYF/buzi1KI8ZVMmyqMdy+q+yRxHeirqDGfFRN4Boaad2JR5rf9VpmFUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716471211; c=relaxed/simple; bh=Mf/KWV0Xz/ngTw5PxuANIDzRMdPWVwic1R3/NoQ/tdM=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=DwDORyzKX4EibtcMOMb9JpkjInmdvBKVzFYTtSQL5QiyPTvvYvL0hA7IxJqlj5lXfrE/XUpqPw4pArJb8bJYGbxmvie1L2gngBsSs5JPwaIw4mEtSMY0czgU7Qu+kWjgxA7+tsg+GwG17MAiCHuBbDkewxqo031MBFHgiIILDEE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f3406f225bso4648005ad.3 for ; Thu, 23 May 2024 06:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716471208; x=1717076008; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=AZ1AP6hH9VWvcVJ/fi3/XjKpfRNcHNKF9UdIEtXOprw=; b=drafDUQ6V9AMO/VwLt537q5uTaqjqaxBaMJuUetllmwHc0ypViXkMSYlw72d78820V niIemRo7HLOcsYOgBW6W7+Xn23xzVkHBFLI+gBZhnxBjLN0HVHbHVLgWQZ01sOSUvito ibATkXjlInHJ2kAfswV0+hufuGp8Hvxhp8BuRuXeYWd36KDORc9gqDxCTKuqVxTzzIFz SjWJ0FASbo1rc7TC1aWeOwVq9Wsa2SGS/ueIUs5PVVDVZOZiA1ROWkUVJUTjJ3Esclbh sUKr069GY+DY+1sxk11oZk21DN69i+UvGx18d382mYeIWRmBI2PyFIt1UsoQ8WLViEOH Nj1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716471208; x=1717076008; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AZ1AP6hH9VWvcVJ/fi3/XjKpfRNcHNKF9UdIEtXOprw=; b=c6gpd5QGd0hZLNGQc6Xl5bRkcUZfMeFFQZ4MJ5oQTP76y22sOXu2D+Gx/f4Qqi3w0P g2/el8prIyzZSqI6+9A05XZTdH0jpOTnURgfmiL1s9krxavmSHzhmXMHh4UqQY0JU436 XvfleuYzc4jgYlGYjfd0fvfmhuGeCvnkEN1wxAdS3pX5qSrSVyHM6tPBc30kvXgRSLXx ZURhMjztSUaTKGCEhTUl63AmEvZf3IwxE/RM+XsCkbJ7A29DWyhi0sUGRbViF9P8jiNH g69fzEe6bplMJp666bmyNrtFV32RZRA5aADDeDEplCB69/xR18MDqgGDZDuMrsYifzaZ WHTA== X-Gm-Message-State: AOJu0YxlMJ7OwueCd1V/reeiAhS3505YwRFrVuaKtKPecvPGbnMXo+t3 iv09R0kjQ+35H2WEdaJdkFtCwJKR8n+BIkogTTfr/fy2ueQj6GaGfWedGA== X-Google-Smtp-Source: AGHT+IEjYp/AQ90feiaEeFnoygqe9iClmjK30jgM8qJasKxsQCtaT3j4cH6vPRzBFspVY4sH5GFkKw== X-Received: by 2002:a17:902:e80d:b0:1e9:43c:d176 with SMTP id d9443c01a7336-1f31c95d48cmr62012385ad.12.1716471207885; Thu, 23 May 2024 06:33:27 -0700 (PDT) Received: from Thaum. (14-200-72-253.tpgi.com.au. [14.200.72.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f3246dd9fbsm30307405ad.157.2024.05.23.06.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:33:27 -0700 (PDT) Message-ID: <664f45a7.170a0220.c69fa.7df0@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 23 May 2024 23:33:23 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: Re: [PATCH] c++/modules: Ensure all partial specialisations are tracked [PR114947] References: <6640c449.170a0220.9790b.fc84@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6640c449.170a0220.9790b.fc84@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Sun, May 12, 2024 at 11:29:39PM +1000, 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. > > 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 () ...but this can be 'module_maybe_has_cmi_p' if my change to 'module_has_cmi_p' to include header units is merged first. > + && 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; > -- > 2.43.2 >