From patchwork Tue Nov 3 21:16:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1393429 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=peqaF+jI; 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 4CQjJH05C2z9sfG for ; Wed, 4 Nov 2020 08:16:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1947539874DB; Tue, 3 Nov 2020 21:16:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id A207D3987481 for ; Tue, 3 Nov 2020 21:16:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A207D3987481 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-qk1-x72a.google.com with SMTP id o205so9841387qke.10 for ; Tue, 03 Nov 2020 13:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:subject:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=MzX2lX96N7e5DU4c8crm+p5iorn5wuzdnR+bXxmNofE=; b=peqaF+jIFt1FZCiXHWiZjuRCIaR0RJd5QjyiI4MojgVNVC66GY8GnKjY+NdseWM7YY mqbisBhuGWqMLU/3flavtWKwdECmbW+gA/zKWk20/baE55aRyh4xa617ujFdfCH6Alan 4MFmEDJdhFhlc4B+AcQwkERtuFHzLnv2Foa4IYfQyeun1E+ZGODFJsB+D9vYhFavN53T oFhox/19bPcIseSczgfQ7nbmKiYWRuJMrpiYZH576+qSktBygJfg4DBPs1PVaDs1Ix2R qEkXBd4+5E2ULBrVWJOF46lriK1PSw1qrvnDRVKUoeIarqIM+EI1Rwsb2i+TI/H2LxBZ yWsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:subject:to:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=MzX2lX96N7e5DU4c8crm+p5iorn5wuzdnR+bXxmNofE=; b=mUF/iIfo1IflONIgm6o9hCV1aRFCO90aWOUnZjCdOUhw6jEZD/p99/5PsNnPDpRrCc K/ZBaZLFhe/6Hsv2JnpifCwKaiQlS0XkTFkON7W9rXV3iq0N/ttYp/IO0VTYeN/PpUar zG+Z/VKokrIOMXsyZInvKa+983h8KFBDFHjo4+w/d3B58I4NYDanAt+cxGbcrf3PiR4a MDcm5XdQUGoLhr/SMhvDLxPXhUa0MdfrXSPe2s2683DrluCwyL9tSCYKA+b7APGdxmtr 8lJHy30PKBQBqOHs73IvCwakZcU2i0uIGo62fMNBG+INvnCAX9Sh0tV+ZxSPAdTq9j0J Uv6Q== X-Gm-Message-State: AOAM5331OOxvxu9tq/MeRSfdVWe8zj9pcgkS2H/CijR2Iq/1zX9kQzg8 nXp3VmlALzoQmZUEq3nFnIE= X-Google-Smtp-Source: ABdhPJzqPsFK4d6himigg0k1CikXzgZDE8uBWI3aM5KvUWso5iABxnEYm1QtTrYa7tFwk7MvWP9FYQ== X-Received: by 2002:a05:620a:1375:: with SMTP id d21mr16333966qkl.309.1604438169976; Tue, 03 Nov 2020 13:16:09 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:e5ef:7eb4:1609:98bb? ([2620:10d:c091:480::1:bc2d]) by smtp.googlemail.com with ESMTPSA id c27sm71500qkk.57.2020.11.03.13.16.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2020 13:16:09 -0800 (PST) From: Nathan Sidwell Subject: [18/32] new C++ template bits To: GCC Patches , Jason Merrill , Richard Biener References: <7fc9e868-3db9-4972-ed67-6ff249f549c3@acm.org> <0bdf00a8-d8ad-9e97-134d-6668c0e8c86b@acm.org> <85996243-86cf-88b4-5b3b-451eaf3a0df6@acm.org> <4d14b230-3263-9a13-3159-c4853f282761@acm.org> <688bd28f-5998-0def-8c40-03b817832d63@acm.org> <89819c10-e86d-9b01-5673-5223a525a135@acm.org> <35879e15-d74a-c664-4d44-15f4b3783d77@acm.org> <9ae23c4c-67a5-a267-c939-5a96e9488612@acm.org> <6666545b-0583-4812-4745-d51994465818@acm.org> <1ab99df5-3997-0895-c979-f8529f476df7@acm.org> Message-ID: <28707e9f-3d66-9b8b-9341-6110243f3392@acm.org> Date: Tue, 3 Nov 2020 16:16:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <1ab99df5-3997-0895-c979-f8529f476df7@acm.org> Content-Language: en-US X-Spam-Status: No, score=-11.3 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" We also need to manipulate the instantiation tables. This exposes that bit of the template machinery. (other patches address instantiations themselves) diff --git c/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index fdb8ee57f0b..e8e4d0af2d8 100644 --- c/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -5386,6 +5563,14 @@ public: hash_map *saved; }; +/* Entry in the specialization hash table. */ +struct GTY((for_user)) spec_entry +{ + tree tmpl; /* The general template this is a specialization of. */ + tree args; /* The args for this (maybe-partial) specialization. */ + tree spec; /* The specialization itself. */ +}; + /* in class.c */ extern int current_class_depth; @@ -6976,6 +7273,16 @@ extern bool copy_guide_p (const_tree); extern bool template_guide_p (const_tree); extern bool builtin_guide_p (const_tree); extern void store_explicit_specifier (tree, tree); +extern void walk_specializations (bool, + void (*)(bool, spec_entry *, + void *), + void *); +extern tree check_mergeable_specialization (bool, spec_entry *); +extern tree match_mergeable_specialization (bool is_decl, tree tmpl, + tree args, tree spec); +extern unsigned get_mergeable_specialization_flags (tree tmpl, tree spec); +extern void add_mergeable_specialization (tree tmpl, tree args, + tree spec, unsigned); extern tree add_outermost_template_args (tree, tree); extern tree add_extra_args (tree, tree); extern tree build_extra_args (tree, tree, tsubst_flags_t); diff --git c/gcc/cp/pt.c w/gcc/cp/pt.c index aa162d2a4f9..497ac5aafec 100644 --- c/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -103,13 +106,6 @@ local_specialization_stack::~local_specialization_stack () /* True if we've recursed into fn_type_unification too many times. */ static bool excessive_deduction_depth; -struct GTY((for_user)) spec_entry -{ - tree tmpl; - tree args; - tree spec; -}; - struct spec_hasher : ggc_ptr_hash { static hashval_t hash (spec_entry *); @@ -29613,6 +29695,104 @@ declare_integer_pack (void) CP_BUILT_IN_INTEGER_PACK); } +/* Collect the specializations and explicit instantitions generated + in this module */ + +void +walk_specializations (bool decls_p, + void (*fn) (bool decls_p, spec_entry *entry, void *data), + void *data) +{ + spec_hash_table *table = decls_p ? decl_specializations + : type_specializations; + spec_hash_table::iterator end (table->end ()); + for (spec_hash_table::iterator iter (table->begin ()); iter != end; ++iter) + fn (decls_p, *iter, data); +} + +tree +check_mergeable_specialization (bool decl_p, spec_entry *elt) +{ + hash_table *specializations + = decl_p ? decl_specializations : type_specializations; + hashval_t hash = spec_hasher::hash (elt); + spec_entry **slot = specializations->find_slot_with_hash (elt, + hash, NO_INSERT); + return slot ? (*slot)->spec : NULL_TREE; +} + +/* Lookup the specialization of TMPL,ARGS in the decl or type + specialization table. Return what's there, or add SPEC and return + NULL. */ + +tree +match_mergeable_specialization (bool decl_p, tree tmpl, tree args, tree spec) +{ + gcc_checking_assert (spec); + spec_entry elt = {tmpl, args, spec}; + hash_table *specializations + = decl_p ? decl_specializations : type_specializations; + hashval_t hash = spec_hasher::hash (&elt); + spec_entry **slot = specializations->find_slot_with_hash (&elt, hash, INSERT); + spec_entry *entry = slot ? *slot: NULL; + + if (entry) + return entry->spec; + + entry = ggc_alloc (); + *entry = elt; + *slot = entry; + + return NULL_TREE; +} + +/* Return flags encoding whether SPEC is on the instantiation and/or + specialization lists of TMPL. */ + +unsigned +get_mergeable_specialization_flags (tree tmpl, tree decl) +{ + unsigned flags = 0; + + for (tree inst = DECL_TEMPLATE_INSTANTIATIONS (tmpl); + inst; inst = TREE_CHAIN (inst)) + if (TREE_VALUE (inst) == decl) + { + flags |= 1; + break; + } + + if (CLASS_TYPE_P (TREE_TYPE (decl)) + && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (decl)) + && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)) == 2) + /* Only need to search if DECL is a partial specialization. */ + for (tree part = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); + part; part = TREE_CHAIN (part)) + if (TREE_VALUE (part) == decl) + { + flags |= 2; + break; + } + + return flags; +} + +void +add_mergeable_specialization (tree tmpl, tree args, tree decl, unsigned flags) +{ + if (flags & 1) + DECL_TEMPLATE_INSTANTIATIONS (tmpl) + = tree_cons (args, decl, DECL_TEMPLATE_INSTANTIATIONS (tmpl)); + + if (flags & 2) + { + DECL_TEMPLATE_SPECIALIZATIONS (tmpl) + = tree_cons (args, decl, DECL_TEMPLATE_SPECIALIZATIONS (tmpl)); + TREE_TYPE (DECL_TEMPLATE_SPECIALIZATIONS (tmpl)) + = TREE_TYPE (DECL_TEMPLATE_RESULT (decl)); + } +} + /* Set up the hash tables for template instantiations. */ void