From patchwork Fri Dec 11 19:15:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1415251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CdBbXoSf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ct0qJ0yncz9sVJ for ; Sat, 12 Dec 2020 06:15:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE1D6385480A; Fri, 11 Dec 2020 19:15:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id 4C3D73857037 for ; Fri, 11 Dec 2020 19:15:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4C3D73857037 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x835.google.com with SMTP id u21so7232143qtw.11 for ; Fri, 11 Dec 2020 11:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=iqwL/4jg/uyLB4L4QDFjG1G0wmkCNsGVIskHvOmxOoE=; b=CdBbXoSfZAqySiYL+tXWOwLuzNT4MRQpjOCCt6BbLb+42WZPaeu6WKjdrqV7mlhRFk lxN7JOvZu8qSdfKy8ETDNxmLq5HWI+uJffMCkX/OGLW7gm/Ka2MsigUCcNB+MnL6O6VP TfYleNuLANBWoCceN8TEnRYQYkHLJPpRwe5AIF+j559yFua2mvl1R/lldh2D1XCOcmB2 zAyPpVXWwHRRuSwlLTQ/+7biS7LK8JoFjSGC6UaUrg4tRdsRypmHwwl+IjexD+3/1LgY GOEYJnGR3frz8Wyoavkr9xnsJHdEuNCm4761s89Vqe59Uv4EHPzhHUAnv/sl5x1RqQ/6 34bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=iqwL/4jg/uyLB4L4QDFjG1G0wmkCNsGVIskHvOmxOoE=; b=ZdL284nxRhokwMnRqXgqMgFQQ0ENkZcTVB11ZW1RJVF5p/vjErLWhBmytSQKmmaaYa 4VNJEywRw4L76iWC/MMSsBrahshJ3yKn7ExhP4Lm1kmD+nP8I3aNsgVQV6Y/8Qz+TTfE Dh16/qU+DwpFktkw5SxzHFkukjwFJrhesZ4qyReLJALgtr387EWPX+eLhOXmiDCdpy1v Z+Yud/rZxAdhmJ0wKrQgggRNSzmksrACeZzTy9cD58wINQ11simjZzjVGKNWTFAPQE4d mya2z3WUPmuNgd3wUh//oByaFG2B7dIqfGEu0oD7hyPthxJDAUrtcgQEV5vcfNtsUu18 wKzQ== X-Gm-Message-State: AOAM530ex2AYGDMUR9JG1H1V+KAv8Npbqui4oxU825TFWF8bbE7cU1jC 3Z2IsQ+d1d9hg33FRAqa3aI= X-Google-Smtp-Source: ABdhPJzBTAE/QvrIwqjpVUCyb9gxfkYKmYQLYRGUd9/K0YCHXUspcrWAhze/NFKp86yysqbVm8Xgqw== X-Received: by 2002:aed:3306:: with SMTP id u6mr17488198qtd.386.1607714115526; Fri, 11 Dec 2020 11:15:15 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:399b:e797:899b:dc78? ([2620:10d:c091:480::1:d553]) by smtp.googlemail.com with ESMTPSA id m54sm8196858qtc.29.2020.12.11.11.15.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Dec 2020 11:15:13 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Final module preparations Message-ID: <116eeb0d-f828-dd07-1245-e2453ceb7bce@acm.org> Date: Fri, 11 Dec 2020 14:15:12 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This adds the final few preparations to drop modules in. I'd missed a couple of changes to core compiler -- a new pair of preprocessor options, and marking the boundary of fixed and lazy global trees. For C++, we need to add module.cc to the GTY scanner. Parsing final cleanups needs a few tweaks for modules. Lambdas used to initialize a global (for instance) get an extra scope, but we now need to point that object to the lambda too. Finally template instantiation needs to do lazy loading before looking at the available instantiations and specializations. gcc/ * gcc.c (cpp_unique_options): Add Mmodules, Mno-modules. * tree-core.h (enum tree_index): Add TI_MODULE_HWM. gcc/cp/ * config-lang.in (gtfiles): Add cp/module.cc. * decl2.c (c_parse_final_cleanups): Add module support. * lambda.c (record_lambda_scope): Call maybe_attach_decl. * module.cc (maybe_attach_decl, lazy_load_specializations): Stubs. (finish_module_procesing): Stub. * pt.c (lookup_template_class_1): Lazy load specializations. (instantiate_template_1): Likewise. pushing to trunk diff --git i/gcc/cp/config-lang.in w/gcc/cp/config-lang.in index da70b358413..4f5f8eca130 100644 --- i/gcc/cp/config-lang.in +++ w/gcc/cp/config-lang.in @@ -47,7 +47,7 @@ gtfiles="\ \$(srcdir)/cp/friend.c \ \$(srcdir)/cp/init.c \ \$(srcdir)/cp/lambda.c \$(srcdir)/cp/lex.c \$(srcdir)/cp/logic.cc \ -\$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \ +\$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \$(srcdir)/cp/module.cc \ \$(srcdir)/cp/name-lookup.c \ \$(srcdir)/cp/parser.c \$(srcdir)/cp/pt.c \ \$(srcdir)/cp/rtti.c \ diff --git i/gcc/cp/decl2.c w/gcc/cp/decl2.c index b13c9d9f73d..6d8158a66f0 100644 --- i/gcc/cp/decl2.c +++ w/gcc/cp/decl2.c @@ -4964,6 +4964,11 @@ c_parse_final_cleanups (void) instantiate_pending_templates (retries); ggc_collect (); + if (header_module_p ()) + /* A header modules initializations are handled in its + importer. */ + continue; + /* Write out virtual tables as required. Writing out the virtual table for a template class may cause the instantiation of members of that class. If we write out @@ -5162,6 +5167,8 @@ c_parse_final_cleanups (void) reconsider = true; } + finish_module_processing (parse_in); + lower_var_init (); generate_mangling_aliases (); @@ -5177,6 +5184,10 @@ c_parse_final_cleanups (void) #pragma interface, etc.) we decided not to emit the definition here. */ && !DECL_INITIAL (decl) + /* A defaulted fn in a header module can be synthesized on + demand later. (In non-header modules we should have + synthesized it above.) */ + && !(DECL_DEFAULTED_FN (decl) && header_module_p ()) /* Don't complain if the template was defined. */ && !(DECL_TEMPLATE_INSTANTIATION (decl) && DECL_INITIAL (DECL_TEMPLATE_RESULT @@ -5210,9 +5221,8 @@ c_parse_final_cleanups (void) splay_tree_foreach (priority_info_map, generate_ctor_and_dtor_functions_for_priority, /*data=*/&locus_at_end_of_parsing); - else if (c_dialect_objc () && objc_static_init_needed_p ()) - /* If this is obj-c++ and we need a static init, call - generate_ctor_or_dtor_function. */ + else if ((c_dialect_objc () && objc_static_init_needed_p ()) + || module_initializer_kind ()) generate_ctor_or_dtor_function (/*constructor_p=*/true, DEFAULT_INIT_PRIORITY, &locus_at_end_of_parsing); diff --git i/gcc/cp/lambda.c w/gcc/cp/lambda.c index 1a1647f465e..f6746d7304b 100644 --- i/gcc/cp/lambda.c +++ w/gcc/cp/lambda.c @@ -1114,6 +1114,8 @@ maybe_add_lambda_conv_op (tree type) while (src) { tree new_node = copy_node (src); + /* We set DECL_CONTEXT of NEW_NODE to the statfn below. + Notice this is creating a recursive type! */ /* Clear TREE_ADDRESSABLE on thunk arguments. */ TREE_ADDRESSABLE (new_node) = 0; @@ -1393,6 +1395,12 @@ record_lambda_scope (tree lambda) { LAMBDA_EXPR_EXTRA_SCOPE (lambda) = lambda_scope; LAMBDA_EXPR_DISCRIMINATOR (lambda) = lambda_count++; + if (lambda_scope) + { + tree closure = LAMBDA_EXPR_CLOSURE (lambda); + gcc_checking_assert (closure); + maybe_attach_decl (lambda_scope, TYPE_NAME (closure)); + } } /* This lambda is an instantiation of a lambda in a template default argument diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc index 2417d67ee41..d8012d75ca4 100644 --- i/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -154,11 +154,21 @@ set_originating_module (tree, bool) { } +void +maybe_attach_decl (tree, tree) +{ +} + void lazy_load_binding (unsigned, tree, tree, binding_slot *) { } +void +lazy_load_specializations (tree) +{ +} + void lazy_load_members (tree) { @@ -216,6 +226,11 @@ maybe_check_all_macros (cpp_reader *) { } +void +finish_module_processing (cpp_reader *) +{ +} + void fini_modules () { diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 6b8e486a642..e5f18d23ea0 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -9788,6 +9788,15 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, return error_mark_node; gen_tmpl = most_general_template (templ); + if (modules_p ()) + { + tree origin = get_originating_module_decl (gen_tmpl); + load_pending_specializations (CP_DECL_CONTEXT (origin), + DECL_NAME (origin)); + if (DECL_MODULE_PENDING_SPECIALIZATIONS_P (gen_tmpl)) + lazy_load_specializations (gen_tmpl); + } + parmlist = DECL_TEMPLATE_PARMS (gen_tmpl); parm_depth = TMPL_PARMS_DEPTH (parmlist); arg_depth = TMPL_ARGS_DEPTH (arglist); @@ -20907,6 +20916,15 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) (DECL_TI_ARGS (DECL_TEMPLATE_RESULT (tmpl)), targ_ptr)); + if (modules_p ()) + { + tree origin = get_originating_module_decl (gen_tmpl); + load_pending_specializations (CP_DECL_CONTEXT (origin), + DECL_NAME (origin)); + if (DECL_MODULE_PENDING_SPECIALIZATIONS_P (gen_tmpl)) + lazy_load_specializations (gen_tmpl); + } + /* It would be nice to avoid hashing here and then again in tsubst_decl, but it doesn't seem to be on the hot path. */ spec = retrieve_specialization (gen_tmpl, targ_ptr, 0); diff --git i/gcc/gcc.c w/gcc/gcc.c index 1d32375f648..d179de7d97f 100644 --- i/gcc/gcc.c +++ w/gcc/gcc.c @@ -1232,6 +1232,7 @@ static const char *cpp_unique_options = %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ + %{Mmodules} %{Mno-modules}\ %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ %{remap} %{%:debug-level-gt(2):-dD}\ %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ diff --git i/gcc/tree-core.h w/gcc/tree-core.h index e457b917b98..a89f063ab55 100644 --- i/gcc/tree-core.h +++ w/gcc/tree-core.h @@ -773,6 +773,10 @@ enum tree_index { TI_SAT_UDA_TYPE, TI_SAT_UTA_TYPE, + TI_MODULE_HWM, + /* Nodes below here change during compilation, and should therefore + not be in the C++ module's global tree table. */ + TI_OPTIMIZATION_DEFAULT, TI_OPTIMIZATION_CURRENT, TI_TARGET_OPTION_DEFAULT,