From patchwork Wed May 1 10:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1930113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=b8hsn7K9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTsyd062Cz1ymc for ; Wed, 1 May 2024 20:00:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F944384AB50 for ; Wed, 1 May 2024 10:00:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id B4A85385841D for ; Wed, 1 May 2024 10:00:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4A85385841D 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 B4A85385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557632; cv=none; b=DUgyRDTMaMkYd0G0uQv9+nie/RJRJrn06buYBhp340pKQHfMrWKnXdieTGb4bCAG9dTe3jMGnaQ8kx7XWyXqin77+T/bJGUne1Jy5xr2r4w7UKqwGqrRyEsiBNDfoCUydmc9A9nKE3bBXSVXwqf7e9HwtxwKUtdPp+eoh+pMfEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714557632; c=relaxed/simple; bh=0vQqCqr/l2iT21vc4cwTmhv2H0x7YOyEhk1bZyd2hTU=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=OJ56iqjpk8cojEfx2CPLUMcp6sM4iKvhwiPjeJeVkCH0os7XDo6szi/4iFg+yN/t3izfwKEQT8HCt6ApU+vv+WCnjQR2CtxiE6OfebNtnU5HMB8NswKK7Tl/ik1KjozoqKhWWurfY9LjSXx8ncG4HaCpz6ayOzvdOz1CMBy14YQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ecff9df447so6398606b3a.1 for ; Wed, 01 May 2024 03:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557628; x=1715162428; 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=QUbUan5DwZN8wf7x1njhQaDcUbLQJviRb1oYFPeKdtM=; b=b8hsn7K9CtnEEuInSLQoI4MGUtPFNuwu6rrh3kCZwabKP2ebR07sbBJ/wV1YDB87e4 Ued43DwEIB45Lobt6cC06ouuRwCGfMGqOnipl6OhQ4sC3PelX2Dp3qbg1A6zJ706/6FZ y5LOOr9yXE3mW53/jMSHiU49Ju5aZ9wi3m/Evmw7Pk+W366Yl5+DTKuThSE4dGUoRyB1 Hak5PPNSEt/ZRg3tFBnvZMTDW8mIUiRddYK1PKVvZkRmA8Ts0qmtBD71QnAO5DsUNDHn h1hJSmmBLhIvseGVS6ey041FvusRp6ZM3QmFOPf8dOkz7NQTRUm8ymi0eRZSsuBp4fos s0KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557628; x=1715162428; 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=QUbUan5DwZN8wf7x1njhQaDcUbLQJviRb1oYFPeKdtM=; b=azjU7/oQWbT9pGebB41nwv1QWU700t0+aKr0fUDUWPQjEV/dVq5Z1QJcovaIzc7mBs EsmRM0Fqw3PkDA++ZNFsyOIn2siJS6vx/hKoRnfJPAwE10cNnZnUmBxjUnTYdQi0PxWC 2ad/DTQ/HudNRNWzFJwI99xvLeBXrNiDFPGuZcAXHMMs9filufFBmdd4fnmCRVLEsA6u cl88+0KbJo4i0c1i4rH06H9Lsjr/66wU6QtLdMrfunNXrjX4euZPBaWgDpNe1tnmRZ8c 6YKKba1k9P+RgcLMtBH0ESmvCpeoplzpoIO1pEBqZCEa6kfKF1IvBSUVXhWYqXvxzpBV j/sA== X-Gm-Message-State: AOJu0YzGr8gTSPg9iBhT51ityZLidGXlLiw3VxNvQWpufgyUspsUYKlf CgPOmxd6Zucs+gYk3ESjustc574Z4eTGFICtA9eCWTzF7Fwle/dbk4FXgg== X-Google-Smtp-Source: AGHT+IHETWWIRliYc+tBoaUD/F3TFutc23iJqbHgCli4cgM7RzGUFKOgikrh/onXYfK4KIcasMM/Ww== X-Received: by 2002:a05:6a00:3923:b0:6ed:21bc:ed8c with SMTP id fh35-20020a056a00392300b006ed21bced8cmr2140826pfb.18.1714557627566; Wed, 01 May 2024 03:00:27 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id ei9-20020a056a0080c900b006f33c0aee44sm14689312pfb.91.2024.05.01.03.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:00:27 -0700 (PDT) Message-ID: <663212bb.050a0220.9a96f.94c6@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 20:00:22 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH 2/4] c++/modules: Track module purview for deferred instantiations [PR114630] References: <66321257.170a0220.326c5.1f68@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66321257.170a0220.326c5.1f68@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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- When calling instantiate_pending_templates at end of parsing, any new functions that are instantiated from this point have their module purview set based on the current value of module_kind. This is unideal, however, as the modules code will then treat these instantiations as reachable and cause large swathes of the GMF to be emitted into the module CMI, despite no code in the actual module purview referencing it. This patch fixes this by also remembering the value of module_kind when the instantiation was deferred, and restoring it when doing this deferred instantiation. That way newly instantiated declarations appropriately get a DECL_MODULE_PURVIEW_P appropriate for where the instantiation was required, meaning that GMF entities won't be counted as reachable unless referenced by an actually reachable entity. Note that purviewness and attachment etc. is generally only determined by the base template: this is purely for determining whether a specialisation was declared in the module purview and hence whether it should be streamed out. See the comment on 'set_instantiating_module'. PR c++/114630 PR c++/114795 gcc/cp/ChangeLog: * cp-tree.h (struct tinst_level): Add field for tracking module_kind. * pt.cc (push_tinst_level_loc): Cache module_kind in new_level. (reopen_tinst_level): Restore module_kind from level. (instantiate_pending_templates): Save and restore module_kind so it isn't affected by reopen_tinst_level. gcc/testsuite/ChangeLog: * g++.dg/modules/gmf-3.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 3 +++ gcc/cp/pt.cc | 4 ++++ gcc/testsuite/g++.dg/modules/gmf-3.C | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/gmf-3.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1938ada0268..0e619120ccc 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6626,6 +6626,9 @@ struct GTY((chain_next ("%h.next"))) tinst_level { /* The location where the template is instantiated. */ location_t locus; + /* The module kind where the template is instantiated. */ + unsigned module_kind; + /* errorcount + sorrycount when we pushed this level. */ unsigned short errors; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1c3eef60c06..401aa92bc3e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11277,6 +11277,7 @@ push_tinst_level_loc (tree tldcl, tree targs, location_t loc) new_level->tldcl = tldcl; new_level->targs = targs; new_level->locus = loc; + new_level->module_kind = module_kind; new_level->errors = errorcount + sorrycount; new_level->next = NULL; new_level->refcount = 0; @@ -11345,6 +11346,7 @@ reopen_tinst_level (struct tinst_level *level) for (t = level; t; t = t->next) ++tinst_depth; + module_kind = level->module_kind; set_refcount_ptr (current_tinst_level, level); pop_tinst_level (); if (current_tinst_level) @@ -27442,6 +27444,7 @@ instantiate_pending_templates (int retries) { int reconsider; location_t saved_loc = input_location; + unsigned saved_module_kind = module_kind; /* Instantiating templates may trigger vtable generation. This in turn may require further template instantiations. We place a limit here @@ -27532,6 +27535,7 @@ instantiate_pending_templates (int retries) while (reconsider); input_location = saved_loc; + module_kind = saved_module_kind; } /* Substitute ARGVEC into T, which is a list of initializers for diff --git a/gcc/testsuite/g++.dg/modules/gmf-3.C b/gcc/testsuite/g++.dg/modules/gmf-3.C new file mode 100644 index 00000000000..e52ae904ea9 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gmf-3.C @@ -0,0 +1,13 @@ +// PR c++/114630 +// { dg-additional-options "-fmodules-ts -Wno-global-module -fdump-lang-module" } +// { dg-module-cmi M } + +module; +template struct allocator { + allocator() {} +}; +template class allocator; +export module M; + +// The whole GMF should be discarded here +// { dg-final { scan-lang-dump "Wrote 0 clusters" module } }