From patchwork Fri Feb 9 21:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 199123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1149841dyd; Fri, 9 Feb 2024 13:50:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX7FgVNmqSja4yr3G8kPKaGDXlCEBtUNN8v8mmFXt5em9HpeeJXBcwTYYvG6MwMaLxhwabOSYk+weyk0rq+2cxBdV/Liw== X-Google-Smtp-Source: AGHT+IFZJn56SBUNhECCB9XctZTbKbseZ8T+jx2NExny0hRNvICg35ljLSy8k8lvOYsK+LDHCZLQ X-Received: by 2002:a05:620a:1924:b0:785:5e5b:9bc1 with SMTP id bj36-20020a05620a192400b007855e5b9bc1mr496695qkb.74.1707515450876; Fri, 09 Feb 2024 13:50:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707515450; cv=pass; d=google.com; s=arc-20160816; b=TOrmQLLwVMKPb6DItpBDJiFCNgygXSPnQI735uAvgQThnIFtTlOw/ImeljuYIAkaRB JLL0o9wevElxv48hSC6UDoc/lI1UBMAja1WtXb+uvEbgdtk9dr/fXEuq2hcIma8cwXhl Ed+eCuL3WnBR6KUr9ugY50l74wjtq/y2eTRUClCbYzyoA0zoq4qU3ZGesyk3sG+85nnQ BjF35Wx8+mSetJ9mZlnv+EvtHQqr80kyEAMHezrvrqczHVDSFjgpCtZUDH8ZkSQL7fg6 Rim352/P676+jRqXA+Xb+WQXJfkeuAAm9a45d5ILdjXKu66G6Oh4SXHQp6YMM5c1IdEz BGQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=GaDBy9zAn5Px5jn8QSQs1hqHXBh8NDYh/Vw6vql1uqs=; fh=8np2TaZYYKUZiqPuHiLrkC9cEZik1Yuo/5aKBfMyXig=; b=uFFPCxBzbrXo5DJgEIy6zJMRBmnkbjq1sxogELc3XxXhnlMa0palh3yn7bjFGtfRGd eIjO3ew4xMMWV9TGKnK05ROnUzFi1Tf3U/FU/+r2vWa4j4H1NtWcs07VEF9gPeDkJYlG vGIM20e24jKKcW2SEmhvBsDYWuATfHCo5pzlrZj3pG2fWrP4MFo8yTPqUnaXz4myfLKw 9mUwpkWK2YsHIEMvJ6+dW/5mZZv3hJteuKE/i7XYNJkO4RPttTI684E+ZlrqKeBkXC1o 0VAPUU9Sgs2HVMIgIrEBGwCLECdzDJ93wL3zO85lWjrA2BUEgRG6PKoIihtHjcqTN2KM UzEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KFO41Q9Y; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCV/6eqKFjwUFGmn8hppiYx7HAVSDm2We3IWClxGMMppU2ow11USL1YEq+2YkPZL5C2wn23dgaB3tTogWOqKpNROO4Davw== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z9-20020a05620a100900b00785be743678si352651qkj.645.2024.02.09.13.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KFO41Q9Y; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85D5238582A4 for ; Fri, 9 Feb 2024 21:50:50 +0000 (GMT) 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 476CB3858C35 for ; Fri, 9 Feb 2024 21:50:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 476CB3858C35 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 476CB3858C35 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=1707515410; cv=none; b=nVldf6qo5CngP0DXbY8UeNL35/o59pPiBvPyJZvyydLsbHozVDzjva1uKW9QSgeHEcgvgADq2BaGsli/C3qLgKH7ySQwwjOF58sJcL8hhTbfPREbFNFD7+Ppe9S8KVK3YdPzfHDAZfDAmGolkk6NJ4nxDafYrTuMjiHnYeCgYDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707515410; c=relaxed/simple; bh=yjOA0OYc3CA/kEAsoAzRbZ08r/v0Ql4sh132fQqs2GM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QuaHQ24d9FrD+mFlbQkU/H07QwlCx2cPmOOPa8yuVKl4BAD/5gq9D6IwGOvoC8n/3iJbjAsHCMTc5dCwpLGXZb2XItRra92udNNSIhDB6H4FwVjSMtG6c2XTrn9bJUtOR9BpKEvFSgVIXSKIZcLPphv+/BfrD2DLU8nWQaHYpVQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707515408; 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; bh=GaDBy9zAn5Px5jn8QSQs1hqHXBh8NDYh/Vw6vql1uqs=; b=KFO41Q9YHdsFYHuuJMhUVcjMjdpCtlTjT8yerUZGt96zc9hPTVFsN+Zp8iKNj2VLZb7zNQ YR4vsXIW1GEbrnRE376QXFF0qwObeL+3git0lJ+rFmL5KQJEDnxJ4dyPL9Thh3SLXG/Q0W V9oTKPxTXjSWof5Gg9qlQqXS0Z8UNVk= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-_yhOuhzQOx6OHDLVmCS2aQ-1; Fri, 09 Feb 2024 16:50:08 -0500 X-MC-Unique: _yhOuhzQOx6OHDLVmCS2aQ-1 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6e124429720so1421087a34.3 for ; Fri, 09 Feb 2024 13:50:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707515406; x=1708120206; 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=GaDBy9zAn5Px5jn8QSQs1hqHXBh8NDYh/Vw6vql1uqs=; b=p6jflU3j8NzQLUIjL1LC6+hO3IjKxwxnQL1iJyObvFlx2D81gJNIrnt0Bvxjl16Cs6 /wiUKPjX1PbqIgnnQCG3ZYy0/tErUTYIQEhYr8yvCekjy9OaSPfjMEOvjzEHxAC/0Gpb FyZDvkLkWy702whfALWu67AImq5hH4nRLtNqIekZJD3Kesu9REtgmw6iCcFyMwSsLwaz omCgIEtUv2EvKPC0jj7OpuC8X2SKG2+PtBE0i4hHbBO4pQvCktsHtkI/77EtS0P2JSum A8ylxjCU8rmB9omXk9ZrHncRhapIV0VFMIiMNlT7Sp0Ky7VbIP0D91+UjObbEAI8TVT4 6BAw== X-Gm-Message-State: AOJu0YzQHYPSWCEdUpcV2zqQH6/AluV71uFFhBlXgDOKgrnodf8RWua0 0vVp16zG/wkR0m9WKfaRaLguts+hvRZIbBVs6QCYnxfDRssF1lxzjymOkrrP/dF48ZjpLy6zWgU NhTKHT1+2aWcQ1gKysqDVZjvx1fItMCswG8UfqeuAOsIR7GGWDm1C2crYtDY3hMo1MqdWQ78dda H87/jQ9xIRWVWoS3y/cQr+q+gE+mL5bfXqan5y X-Received: by 2002:a9d:3e0d:0:b0:6e2:bc4f:5858 with SMTP id a13-20020a9d3e0d000000b006e2bc4f5858mr376850otd.17.1707515406153; Fri, 09 Feb 2024 13:50:06 -0800 (PST) X-Received: by 2002:a9d:3e0d:0:b0:6e2:bc4f:5858 with SMTP id a13-20020a9d3e0d000000b006e2bc4f5858mr376830otd.17.1707515405789; Fri, 09 Feb 2024 13:50:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVTND7q+2EoDkLge1zheih1CMKyITFFeFB0xfQRQyAC+NTssnu52pTX2E6hLQU8jqc0rDh25J0E34z9ft2qpStgttDJNtByd6exfsu9dYNRf5o= Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id kr21-20020ac861d5000000b0042c594ee9c2sm930133qtb.63.2024.02.09.13.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:50:05 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka Subject: [PATCH 1/2] c++/modules: reduce lazy loading recursion Date: Fri, 9 Feb 2024 16:50:00 -0500 Message-ID: <20240209215001.1196422-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.561.g235986be82 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_H5, 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790459721056073258 X-GMAIL-MSGID: 1790459721056073258 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk -- >8 -- It turns out that with modules we can call mangle_decl recursively, which is a problem because the global mangling state isn't recursion aware. The recursion happens from write_closure_type_name, which calls lambda_function, which performs name lookup, which can trigger lazy loading, which can call maybe_clone_body for a newly loaded cdtor, which can inspect DECL_ASSEMBLER_NAME, which enters mangling. This was observed when using fmtlib as a module with trunk and it leads to a bogus "mangling conflicts with a previous mangle error" followed by an ICE from cdtor_comdat_group due to a mangling mismatch. This patch fixes this by sidestepping lazy loading when performing the op() lookup in lambda_function, so that we don't accidentally end up entering mangling recursively. This should be safe since the lazy load should still get triggered by some other name lookup. In passing it was noticed that lazy loading can get quite recursive ultimately due to the name lookups from check_local_shadow, which may perform lazy loading, which cause us to instantiate/clone things, which end up calling check_local_shadow. This patch fixes this by implementating an optimization suggested by Jason: > I think we shouldn't bother with check_local_shadow in a clone or > instantiation, only when actually parsing. This reduces the maximum depth of lazy loading recursion for a simple modular Hello World from ~115 to ~12. gcc/cp/ChangeLog: * lambda.cc (lambda_function): Call get_class_binding_direct instead of lookup_member to sidestep lazy loading. * name-lookup.cc (check_local_shadow): Punt if we're in a function context that's definitely not actual parsing. --- gcc/cp/lambda.cc | 4 +--- gcc/cp/name-lookup.cc | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 1d37e5a52b9..4b1f9391fee 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -175,9 +175,7 @@ lambda_function (tree lambda) if (CLASSTYPE_TEMPLATE_INSTANTIATION (type) && !COMPLETE_OR_OPEN_TYPE_P (type)) return NULL_TREE; - lambda = lookup_member (type, call_op_identifier, - /*protect=*/0, /*want_type=*/false, - tf_warning_or_error); + lambda = get_class_binding_direct (type, call_op_identifier); if (lambda) lambda = STRIP_TEMPLATE (get_first_fn (lambda)); return lambda; diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index e58f3b5cb4d..ca5ba87bc76 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -3275,6 +3275,23 @@ check_local_shadow (tree decl) if (TREE_CODE (decl) == PARM_DECL && !DECL_CONTEXT (decl)) return NULL_TREE; + if (DECL_FUNCTION_SCOPE_P (decl)) + { + tree ctx = DECL_CONTEXT (decl); + if (DECL_CLONED_FUNCTION_P (ctx) + || DECL_TEMPLATE_INSTANTIATED (ctx) + || (DECL_LANG_SPECIFIC (ctx) + && DECL_DEFAULTED_FN (ctx)) + || (LAMBDA_FUNCTION_P (ctx) + && LAMBDA_EXPR_REGEN_INFO (CLASSTYPE_LAMBDA_EXPR + (DECL_CONTEXT (ctx))))) + /* It suffices to check shadowing only when actually parsing. + So punt for clones, instantiations, defaulted functions and + regenerated lambdas. This optimization helps lazy loading + cascades with modules. */ + return NULL_TREE; + } + tree old = NULL_TREE; cp_binding_level *old_scope = NULL; if (cxx_binding *binding = outer_binding (DECL_NAME (decl), NULL, true))