From patchwork Wed Sep 13 12:49:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 813422 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-462029-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="KCwZ0/Zv"; 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 3xshLt37rtz9s5L for ; Wed, 13 Sep 2017 22:49:26 +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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=kGEqcM+BqJ9CTyuSvOoi+Q9M8SRUghwQ00C74iNb+CjPdPRPNu keDBlyBfK9bUwA7+UQmKd//Nrt79pJbxPTp470NCeHUaE/BOwwfpAz++B5p5O+T0 RngCia/sgCMm0ak9mei16aHG/8lVB7dC8BvnTQ7oW5C+HdsTIkKhOLJro= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=nh2SctBXP3QW2xG6liJsVlHgMWU=; b=KCwZ0/Zv9en/soeNZXod q5eTpMCjmFdZzD2o35JD50uthR43J9hHM5SaqSHMNdx93fRcWhxVFqTwN/1BrUIU y84QAmXD5km0xIhAfysHE66jB6XuQL+SjE9LrQ+NffvnH/9CcJAQVOW5jVeELRMb 2Cl3JuNw4kRz0dTmm1XpDvw= Received: (qmail 80284 invoked by alias); 13 Sep 2017 12:49:17 -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 80262 invoked by uid 89); 13 Sep 2017 12:49:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Directly, Hang, H*MI:1574, H*M:1574 X-HELO: mail-yw0-f180.google.com Received: from mail-yw0-f180.google.com (HELO mail-yw0-f180.google.com) (209.85.161.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Sep 2017 12:49:15 +0000 Received: by mail-yw0-f180.google.com with SMTP id s62so296644ywg.0 for ; Wed, 13 Sep 2017 05:49:15 -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:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=MXdOg6Di4d3yzj9hilT3LmqG84x3WoEPQwnAqckUofU=; b=oxV+qTsNv5XBg6zwcSXRD84XjmD0pHx/17GvBdB4F0ptQWd6gp5PPrUrfFI9VCwYHB YxSdA77xLIKNzI9mwXvh6QSty7bk9l2gEHVJchMLahkdT9XWS39csfLI/fMqU4yAaHPb 2HmrPorVLOXagopXmX5O3UaBrSeBCuLPogTTU+K67kxOD4J0zDXJZZl7VN2KbASE4C3e h3OJ8e30nXq5U07fyVGbupxQ/BgOaKYgQZ2ebbNWhQPuT8NoYNcohcN6egxhgr3RIu2g mFCJwL/7Ci/Pwu+uhoLwhU210Uul247SyMgiF4ioAR3nLMxUV6+km79JXHxBFOJdiYN3 iwQA== X-Gm-Message-State: AHPjjUhsUwQ48BXZr5SSIfQwk1tSDQ+WHGYg07i9EwexyAuWKSYSp676 v6CaFATX5nheqw== X-Google-Smtp-Source: ADKCNb7tE9W9iDe2ngJvO09w8HqMGEZI6T0VGDMNtUf78ezfY2ypO8JaRUznuosOMyR2bGj5VPLtHw== X-Received: by 10.37.217.194 with SMTP id q185mr13839888ybg.21.1505306953562; Wed, 13 Sep 2017 05:49:13 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::a68b]) by smtp.googlemail.com with ESMTPSA id h7sm4589081ywf.92.2017.09.13.05.49.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Sep 2017 05:49:12 -0700 (PDT) To: GCC Patches Cc: Jason Merrill From: Nathan Sidwell Subject: [C++ PATCH] don't put conv-op names in identifier hash Message-ID: <5221953b-ac3e-1574-a25d-10a5da3cb5e1@acm.org> Date: Wed, 13 Sep 2017 08:49:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 This patch changes the conv-op identifier node creation. Conv-ops are never looked up by name, and there's no need for them to be in the identifier table. Which also means there's no need for them to have distinct names. This patch implements that. conv-op names are directly cloned from the regular 'conv_op_identifier'. They are only findable via make_conv_op_name. Jason, you asked about whether we could dispense with stashing conv-op target types in the identifier_node. That looked more complicated, we'd need to (at least) address 1) pretty printing. That passes DECL_NAME, expecting to print 'operator TYPE' from it. 2) parsing. That passes the identifier as part of declarator_name into grokdeclarator and friends. 3) class-scope name lookup. That expects an identifier and from that find the right conversion function I'm sure all that can be fixed with additional args or whatever, but I'm not going there now. nathan 2017-09-13 Nathan Sidwell Conv-op identifers not in identifier hash table * lex.c (conv_type_hasher): Make member fns inline. (make_conv_op_name): Directly clone conv_op_identifier. Index: lex.c =================================================================== --- lex.c (revision 252076) +++ lex.c (working copy) @@ -531,10 +531,24 @@ unqualified_fn_lookup_error (cp_expr nam return unqualified_name_lookup_error (name, loc); } + +/* Hasher for the conversion operator name hash table. */ struct conv_type_hasher : ggc_ptr_hash { - static hashval_t hash (tree); - static bool equal (tree, tree); + /* Hash NODE, an identifier node in the table. TYPE_UID is + suitable, as we're not concerned about matching canonicalness + here. */ + static hashval_t hash (tree node) + { + return (hashval_t) TYPE_UID (TREE_TYPE (node)); + } + + /* Compare NODE, an identifier node in the table, against TYPE, an + incoming TYPE being looked up. */ + static bool equal (tree node, tree type) + { + return TREE_TYPE (node) == type; + } }; /* This hash table maps TYPEs to the IDENTIFIER for a conversion @@ -543,57 +557,41 @@ struct conv_type_hasher : ggc_ptr_hash *conv_type_names; -/* Hash a node (VAL1) in the table. */ - -hashval_t -conv_type_hasher::hash (tree val) -{ - return (hashval_t) TYPE_UID (TREE_TYPE (val)); -} - -/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */ - -bool -conv_type_hasher::equal (tree val1, tree val2) -{ - return TREE_TYPE (val1) == val2; -} - -/* Return an identifier for a conversion operator to TYPE. We can - get from the returned identifier to the type. */ +/* Return an identifier for a conversion operator to TYPE. We can get + from the returned identifier to the type. We store TYPE, which is + not necessarily the canonical type, which allows us to report the + form the user used in error messages. All these identifiers are + not in the identifier hash table, and have the same string name. + These IDENTIFIERS are not in the identifier hash table, and all + have the same IDENTIFIER_STRING. */ tree make_conv_op_name (tree type) { - tree *slot; - tree identifier; - if (type == error_mark_node) return error_mark_node; if (conv_type_names == NULL) conv_type_names = hash_table::create_ggc (31); - slot = conv_type_names->find_slot_with_hash (type, - (hashval_t) TYPE_UID (type), - INSERT); - identifier = *slot; + tree *slot = conv_type_names->find_slot_with_hash + (type, (hashval_t) TYPE_UID (type), INSERT); + tree identifier = *slot; if (!identifier) { - char buffer[64]; - - /* Create a unique name corresponding to TYPE. */ - sprintf (buffer, "operator %lu", - (unsigned long) conv_type_names->elements ()); - identifier = get_identifier (buffer); - *slot = identifier; + /* Create a raw IDENTIFIER outside of the identifier hash + table. */ + identifier = copy_node (conv_op_identifier); + + /* Just in case something managed to bind. */ + IDENTIFIER_BINDING (identifier) = NULL; + IDENTIFIER_LABEL_VALUE (identifier) = NULL_TREE; /* Hang TYPE off the identifier so it can be found easily later when performing conversions. */ TREE_TYPE (identifier) = type; - /* Set the identifier kind so we know later it's a conversion. */ - set_identifier_kind (identifier, cik_conv_op); + *slot = identifier; } return identifier;