From patchwork Fri Feb 9 19:39:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 871556 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-472981-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="P0bi9Kxw"; 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 3zdQPM5cGzz9sDB for ; Sat, 10 Feb 2018 06:39:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=ccfafWlJ74nkoJTjMYOeWDQMzsPnI/8yQJ1nO2Vy24P6Xi 6NlTgewy8Bx4hgT/bd80AednrEY7PjcoL9em/hfdN8Oq8iuZL4tdK2NqRz8smEEf 9hnH5UzgX93s1wswlM2DKi2o07fvN174jrys1EHRDJp7Xl7yE9CKFK0hscg8I= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=AxTjIZscq/TXFV2PJlp6K+FHwKU=; b=P0bi9KxwxNbct65WK2YP /c2YhjWD0j3bH+VubWGGkVA+yAFgTYw38sXzZQDnx7AevNCSmtYDSv/BvHWpN0x1 DaTTMuuk7aSPqAd8js3I6FRQHuaAFcEck3sxNYXgeSA/JZ27SeJjw5591sScHaXJ PH0qh8t59szcGWJC+Ub0i64= Received: (qmail 115444 invoked by alias); 9 Feb 2018 19:39:28 -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 115425 invoked by uid 89); 9 Feb 2018 19:39:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Feb 2018 19:39:25 +0000 Received: by mail-wm0-f54.google.com with SMTP id i186so17289609wmi.4 for ; Fri, 09 Feb 2018 11:39:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=XX2EgeX7tnpr5kZJX6HsNVg/bGLJKjVZwnMffjzaXdk=; b=XZzTZR0FbAw340yhCblK9PlLwbQTLF3UR+B0XWuEAptCkhD3Uqe4oTFfiCTBl6E6V3 58RCYiFvLFAFsnJvx5uy5WKsB7xXHeXGYlRN/YgRXBLjAMhx3Z3S3hTC6KmIDunKmj1/ GQK7HOmmihZNC9vcAGYiOTU6vrxuvV1gs3F4HSv4+3Jggv6arZyazQLK4UrU4KHnCqYU S0M3LoA+mMlwFgNgE2h2Ey1ddTqfGSdw0DnG060AMhfiznka5wcM2gTOJNggA0Tc5au5 nl+IQxwnF/nl1qa2rndL0r2C36U4NLiAECClFyIOZshUQQEA989H+VwzDSlzEsL3E0lX KLiw== X-Gm-Message-State: APf1xPA9LVZXiuKchVMXyBQGCaw/BX3M28ZtF/vORI91yPlW56ifpOug mPQdlHixFOMp5AMyEx8gkxfLC6xuQFjAfNmo8W/W8cbu X-Google-Smtp-Source: AH8x226j+V18mFacnnu6wM2ybx3k0+NWQgyptWP6CWS0HzgIrESvLEh+Zto+kI63KPfp1pcHy93/kK7OvG83mPKTmTQ= X-Received: by 10.80.181.93 with SMTP id z29mr5044994edd.223.1518205163136; Fri, 09 Feb 2018 11:39:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.134.56 with HTTP; Fri, 9 Feb 2018 11:39:22 -0800 (PST) From: Ian Lance Taylor Date: Fri, 9 Feb 2018 11:39:22 -0800 Message-ID: Subject: Go patch committed: Track //go:nointerface in export data To: gcc-patches , gofrontend-dev@googlegroups.com In the Go frontend, the magic //go:nointerface comment, used for field tracking, was only implemented for conversions to interface types in the same package. This patch records it in the export data, so that it works as expected for types imported from a different package. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 257527) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -7e94bac5676afc8188677c98ecb263c78c1a7f8d +89105404f94005ffa8e2b08df78015dc9ac91362 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 257527) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -5189,17 +5189,24 @@ Function::defer_stack(Location location) void Function::export_func(Export* exp, const std::string& name) const { - Function::export_func_with_type(exp, name, this->type_); + Function::export_func_with_type(exp, name, this->type_, + this->is_method() && this->nointerface()); } // Export a function with a type. void Function::export_func_with_type(Export* exp, const std::string& name, - const Function_type* fntype) + const Function_type* fntype, bool nointerface) { exp->write_c_string("func "); + if (nointerface) + { + go_assert(fntype->is_method()); + exp->write_c_string("/*nointerface*/ "); + } + if (fntype->is_method()) { exp->write_c_string("("); @@ -5280,10 +5287,21 @@ Function::import_func(Import* imp, std:: Typed_identifier** preceiver, Typed_identifier_list** pparameters, Typed_identifier_list** presults, - bool* is_varargs) + bool* is_varargs, + bool* nointerface) { imp->require_c_string("func "); + *nointerface = false; + if (imp->match_c_string("/*")) + { + imp->require_c_string("/*nointerface*/ "); + *nointerface = true; + + // Only a method can be nointerface. + go_assert(imp->peek_char() == '('); + } + *preceiver = NULL; if (imp->peek_char() == '(') { @@ -6213,6 +6231,32 @@ Bindings_snapshot::check_goto_defs(Locat // Class Function_declaration. +// Whether this declares a method. + +bool +Function_declaration::is_method() const +{ + return this->fntype_->is_method(); +} + +// Whether this method should not be included in the type descriptor. + +bool +Function_declaration::nointerface() const +{ + go_assert(this->is_method()); + return (this->pragmas_ & GOPRAGMA_NOINTERFACE) != 0; +} + +// Record that this method should not be included in the type +// descriptor. + +void +Function_declaration::set_nointerface() +{ + this->pragmas_ |= GOPRAGMA_NOINTERFACE; +} + // Return the function descriptor. Expression* Index: gcc/go/gofrontend/gogo.h =================================================================== --- gcc/go/gofrontend/gogo.h (revision 257527) +++ gcc/go/gofrontend/gogo.h (working copy) @@ -1476,13 +1476,14 @@ class Function // Export a function with a type. static void export_func_with_type(Export*, const std::string& name, - const Function_type*); + const Function_type*, bool nointerface); // Import a function. static void import_func(Import*, std::string* pname, Typed_identifier** receiver, Typed_identifier_list** pparameters, - Typed_identifier_list** presults, bool* is_varargs); + Typed_identifier_list** presults, bool* is_varargs, + bool* nointerface); private: // Type for mapping from label names to Label objects. @@ -1607,6 +1608,10 @@ class Function_declaration location() const { return this->location_; } + // Return whether this function declaration is a method. + bool + is_method() const; + const std::string& asm_name() const { return this->asm_name_; } @@ -1628,6 +1633,16 @@ class Function_declaration this->pragmas_ = pragmas; } + // Whether this method should not be included in the type + // descriptor. + bool + nointerface() const; + + // Record that this method should not be included in the type + // descriptor. + void + set_nointerface(); + // Return an expression for the function descriptor, given the named // object for this function. This may only be called for functions // without a closure. This will be an immutable struct with one @@ -1652,7 +1667,10 @@ class Function_declaration // Export a function declaration. void export_func(Export* exp, const std::string& name) const - { Function::export_func_with_type(exp, name, this->fntype_); } + { + Function::export_func_with_type(exp, name, this->fntype_, + this->is_method() && this->nointerface()); + } // Check that the types used in this declaration's signature are defined. void Index: gcc/go/gofrontend/import.cc =================================================================== --- gcc/go/gofrontend/import.cc (revision 257527) +++ gcc/go/gofrontend/import.cc (working copy) @@ -607,8 +607,9 @@ Import::import_func(Package* package) Typed_identifier_list* parameters; Typed_identifier_list* results; bool is_varargs; + bool nointerface; Function::import_func(this, &name, &receiver, - ¶meters, &results, &is_varargs); + ¶meters, &results, &is_varargs, &nointerface); Function_type *fntype = Type::make_function_type(receiver, parameters, results, this->location_); if (is_varargs) @@ -648,6 +649,10 @@ Import::import_func(Package* package) if (this->add_to_globals_) this->gogo_->add_dot_import_object(no); } + + if (nointerface) + no->func_declaration_value()->set_nointerface(); + return no; } Index: gcc/go/gofrontend/types.cc =================================================================== --- gcc/go/gofrontend/types.cc (revision 257527) +++ gcc/go/gofrontend/types.cc (working copy) @@ -9742,7 +9742,12 @@ bool Named_method::do_nointerface() const { Named_object* no = this->named_object_; - return no->is_function() && no->func_value()->nointerface(); + if (no->is_function()) + return no->func_value()->nointerface(); + else if (no->is_function_declaration()) + return no->func_declaration_value()->nointerface(); + else + go_unreachable(); } // Class Interface_method.