From patchwork Fri Jul 21 18:14:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 792247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458686-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cJbpEt1W"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xDf7J3MVZz9s4q for ; Sat, 22 Jul 2017 04:14:50 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=myQiUhuBQiNWD+H2k+7+f8AWOq24Qoc39NWYaCsaozFr9DSxfI duBlcgWZ22T81GnsiKA8p99cmO2up+r1TibwuOoMzY66DyyOlSFc/T7aJ1qgp7dB HVwUr6QaRz33I5y60ySS1EmXh0rRwGFS42OFPTy/dShLJQE4knx3DQbPE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=CvVk4c7N6eQ8hx0aiy37SigontM=; b=cJbpEt1WmO2y3d8uNQ9W G1bLlhdeUNYrjpBl00rWI1Zyvmp7pNMlvUYiQ/5x54fdBa1BQQx/Wp/EpGZ/4CIV CqCy8w/v87nzF+WfVYDy67ElE15kyN9QeA9Dj9tfDFDq0weFZc+Ci0rp3CnY+YB7 bhaklHwmptmxbs2/LHh60HE= Received: (qmail 965 invoked by alias); 21 Jul 2017 18:14:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 908 invoked by uid 89); 21 Jul 2017 18:14:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=in-charge, Maintain X-HELO: mail-yb0-f170.google.com Received: from mail-yb0-f170.google.com (HELO mail-yb0-f170.google.com) (209.85.213.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Jul 2017 18:14:34 +0000 Received: by mail-yb0-f170.google.com with SMTP id w187so13909292ybc.0 for ; Fri, 21 Jul 2017 11:14:34 -0700 (PDT) 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=L1Y7/k30d4BVyvz7p/nvlzeDyxx3IgHMLpCH00Hk2bE=; b=Lt+fs9nuVqfvisBaA+zlIqERU6KhzGBIcFUlHm4Co0Bvbxrz5+Or2AUSZ2JKyApqsZ UA+CMjZiR8QyCq0uBgJrBdcvggWnk6xLXt8OrNT7+eoay7Zg0ifA3EQmdOGmFSSnZC9s cuCH5LL4hFjYrzvHaKPkc0aIqDFfxIzus/Gej4MpMPu7PMDnC6BRRW5wBS65Y/OFUXSD QNmI/UDzBV2hqvQWXYEhflRl8cATN00+/08nSJ0byKwbQ16JPTlc2F4IrstL+uLUDH4z es0ovtgcirstPEd8HlRMiRL6hkZs16yHRt8BUCuiMnI/CNwL/D74yJ7M2qPZEV7WGJOd W+gA== X-Gm-Message-State: AIVw110xe35IofZOrs3zxHaxh4ZDPhrzx0cufSvolYusyHh77O8YObh/ bl/H++g3shlhpw== X-Received: by 10.37.176.76 with SMTP id e12mr6729850ybj.50.1500660872919; Fri, 21 Jul 2017 11:14:32 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:fb48]) by smtp.googlemail.com with ESMTPSA id o133sm1865488ywc.75.2017.07.21.11.14.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 11:14:32 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] no special cdtor slots Message-ID: <96ebfde1-d960-b6a8-31f1-9b184c85cd6f@acm.org> Date: Fri, 21 Jul 2017 14:14:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 ctors and dtors had special slots in the METHOD_VEC, because they used not to have proper names. Now they have unique identifiers, we can treat them just as any other function and look them up by [cd]tor_identifier. (the eventual goal is to replace separate METHOD_VEC and FIELD_VEC with a single map map, so don't worry about this making looking for cdtors slower than an array access right now) Applied to trunk. nathan 2017-07-21 Nathan Sidwell Remove special CDtor METHOD_VEC slots. * cp-tree.h (CLASSTYPE_CONSTRUCTOR_SLOT, CLASSTYPE_DESTRUCTOR_SLOT): Delete. (CLASSTYPE_CONSTRUCTORS): Use lookup_fnfields_slot_nolazy. (CLASSTYPE_DESTRUCTOR): Likewise. * class (add_method): Don't use special cdtor slots. * search.c (lookup_fnfields_idx_nolazy): Likewise. (look_for_overrides_here): Use lookup_fnfields_slot. * semantics (classtype_has_nothrow_assign_or_copy_p): Likewise. Index: class.c =================================================================== --- class.c (revision 250426) +++ class.c (working copy) @@ -1039,50 +1039,39 @@ add_method (tree type, tree method, bool we're going to end up with an assignment operator at some point as well. */ vec_alloc (method_vec, 8); - /* Create slots for constructors and destructors. */ - method_vec->quick_push (NULL_TREE); - method_vec->quick_push (NULL_TREE); CLASSTYPE_METHOD_VEC (type) = method_vec; } /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc. */ grok_special_member_properties (method); - /* Constructors and destructors go in special slots. */ - if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method)) - slot = CLASSTYPE_CONSTRUCTOR_SLOT; - else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method)) - slot = CLASSTYPE_DESTRUCTOR_SLOT; - else - { - tree m; + tree m; - insert_p = true; - /* See if we already have an entry with this name. */ - for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; - vec_safe_iterate (method_vec, slot, &m); - ++slot) + insert_p = true; + /* See if we already have an entry with this name. */ + for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; + vec_safe_iterate (method_vec, slot, &m); + ++slot) + { + m = OVL_FIRST (m); + if (template_conv_p) { - m = OVL_FIRST (m); - if (template_conv_p) - { - if (TREE_CODE (m) == TEMPLATE_DECL - && DECL_TEMPLATE_CONV_FN_P (m)) - insert_p = false; - break; - } - if (conv_p && !DECL_CONV_FN_P (m)) - break; - if (DECL_NAME (m) == DECL_NAME (method)) - { - insert_p = false; - break; - } - if (complete_p - && !DECL_CONV_FN_P (m) - && DECL_NAME (m) > DECL_NAME (method)) - break; + if (TREE_CODE (m) == TEMPLATE_DECL + && DECL_TEMPLATE_CONV_FN_P (m)) + insert_p = false; + break; + } + if (conv_p && !DECL_CONV_FN_P (m)) + break; + if (DECL_NAME (m) == DECL_NAME (method)) + { + insert_p = false; + break; } + if (complete_p + && !DECL_CONV_FN_P (m) + && DECL_NAME (m) > DECL_NAME (method)) + break; } current_fns = insert_p ? NULL_TREE : (*method_vec)[slot]; @@ -1256,7 +1245,7 @@ add_method (tree type, tree method, bool if (conv_p) TYPE_HAS_CONVERSION (type) = 1; - else if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p) + else if (!complete_p && !IDENTIFIER_CDTOR_P (DECL_NAME (method))) push_class_level_binding (DECL_NAME (method), current_fns); if (insert_p) Index: cp-tree.h =================================================================== --- cp-tree.h (revision 250426) +++ cp-tree.h (working copy) @@ -2148,29 +2148,21 @@ struct GTY(()) lang_type { and the RECORD_TYPE for the class template otherwise. */ #define CLASSTYPE_DECL_LIST(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->decl_list) -/* The slot in the CLASSTYPE_METHOD_VEC where constructors go. */ -#define CLASSTYPE_CONSTRUCTOR_SLOT 0 - -/* The slot in the CLASSTYPE_METHOD_VEC where destructors go. */ -#define CLASSTYPE_DESTRUCTOR_SLOT 1 - /* The first slot in the CLASSTYPE_METHOD_VEC where conversion operators can appear. */ -#define CLASSTYPE_FIRST_CONVERSION_SLOT 2 +#define CLASSTYPE_FIRST_CONVERSION_SLOT 0 /* A FUNCTION_DECL or OVERLOAD for the constructors for NODE. These are the constructors that take an in-charge parameter. */ #define CLASSTYPE_CONSTRUCTORS(NODE) \ - ((*CLASSTYPE_METHOD_VEC (NODE))[CLASSTYPE_CONSTRUCTOR_SLOT]) + (lookup_fnfields_slot_nolazy (NODE, ctor_identifier)) /* A FUNCTION_DECL for the destructor for NODE. This is the destructors that take an in-charge parameter. If CLASSTYPE_LAZY_DESTRUCTOR is true, then this entry will be NULL until the destructor is created with lazily_declare_fn. */ #define CLASSTYPE_DESTRUCTOR(NODE) \ - (CLASSTYPE_METHOD_VEC (NODE) \ - ? (*CLASSTYPE_METHOD_VEC (NODE))[CLASSTYPE_DESTRUCTOR_SLOT] \ - : NULL_TREE) + (lookup_fnfields_slot_nolazy (NODE, dtor_identifier)) /* A dictionary of the nested user-defined-types (class-types, or enums) found within this class. This table includes nested member class Index: search.c =================================================================== --- search.c (revision 250426) +++ search.c (working copy) @@ -1590,18 +1590,6 @@ lookup_fnfields_idx_nolazy (tree type, t if (GATHER_STATISTICS) n_calls_lookup_fnfields_1++; - /* Constructors are first... */ - if (name == ctor_identifier) - { - fn = CLASSTYPE_CONSTRUCTORS (type); - return fn ? CLASSTYPE_CONSTRUCTOR_SLOT : -1; - } - /* and destructors are second. */ - if (name == dtor_identifier) - { - fn = CLASSTYPE_DESTRUCTOR (type); - return fn ? CLASSTYPE_DESTRUCTOR_SLOT : -1; - } if (IDENTIFIER_CONV_OP_P (name)) return lookup_conversion_operator (type, TREE_TYPE (name)); @@ -2428,37 +2416,26 @@ look_for_overrides (tree type, tree fnde tree look_for_overrides_here (tree type, tree fndecl) { - int ix; - - /* If there are no methods in TYPE (meaning that only implicitly - declared methods will ever be provided for TYPE), then there are - no virtual functions. */ - if (!CLASSTYPE_METHOD_VEC (type)) - return NULL_TREE; + tree ovl = lookup_fnfields_slot (type, DECL_NAME (fndecl)); - if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl)) - ix = CLASSTYPE_DESTRUCTOR_SLOT; - else - ix = lookup_fnfields_1 (type, DECL_NAME (fndecl)); - if (ix >= 0) - for (ovl_iterator iter ((*CLASSTYPE_METHOD_VEC (type))[ix]); iter; ++iter) - { - tree fn = *iter; + for (ovl_iterator iter (ovl); iter; ++iter) + { + tree fn = *iter; - if (!DECL_VIRTUAL_P (fn)) - /* Not a virtual. */; - else if (DECL_CONTEXT (fn) != type) - /* Introduced with a using declaration. */; - else if (DECL_STATIC_FUNCTION_P (fndecl)) - { - tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn)); - tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); - if (compparms (TREE_CHAIN (btypes), dtypes)) - return fn; - } - else if (same_signature_p (fndecl, fn)) - return fn; - } + if (!DECL_VIRTUAL_P (fn)) + /* Not a virtual. */; + else if (DECL_CONTEXT (fn) != type) + /* Introduced with a using declaration. */; + else if (DECL_STATIC_FUNCTION_P (fndecl)) + { + tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn)); + tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + if (compparms (TREE_CHAIN (btypes), dtypes)) + return fn; + } + else if (same_signature_p (fndecl, fn)) + return fn; + } return NULL_TREE; } Index: semantics.c =================================================================== --- semantics.c (revision 250426) +++ semantics.c (working copy) @@ -9083,15 +9083,7 @@ classtype_has_nothrow_assign_or_copy_p ( if (assign_p) fns = lookup_fnfields_slot (type, cp_assignment_operator_id (NOP_EXPR)); else if (TYPE_HAS_COPY_CTOR (type)) - { - /* If construction of the copy constructor was postponed, create - it now. */ - if (CLASSTYPE_LAZY_COPY_CTOR (type)) - lazily_declare_fn (sfk_copy_constructor, type); - if (CLASSTYPE_LAZY_MOVE_CTOR (type)) - lazily_declare_fn (sfk_move_constructor, type); - fns = CLASSTYPE_CONSTRUCTORS (type); - } + fns = lookup_fnfields_slot (type, ctor_identifier); bool saw_copy = false; for (ovl_iterator iter (fns); iter; ++iter)