From patchwork Thu Feb 2 18:32:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 139190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 8F174104792 for ; Fri, 3 Feb 2012 05:32:37 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1328812358; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=PD1ISk6WkLAzZDDl0s7kT9SHTuw=; b=fKBBj+6QSapKY+o Bvye8fpJd7TsnNuPuJ5EXMICEkh6nfIZ2corPi8D5QtRRm9soBi8W0Hwd1C86WMr YwZe3GSGhP9Y9xiC4rfAaPq3y+c6WI31IXVkYqm9gEHodOBvoniq2YZjfThsk/CX WTfkZF/g5HTR7vo/kqL45i2XoonU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=BtGjsWTA75Z+Lw0hl+Gc3lKAzKuMe+4LS4tEGFj7qn/veq6jfxfOrHIogQ9cS3 O5pXvqVXJeL6An9UKaWn6PEoKELW++XHSqEr3Jv9ou02Wm4nfMz8UiQHZ8gfDSN9 5309Yyhgy1SggHKwgi18cs8F+gaJWu2OeEpqOrh9prWCc=; Received: (qmail 1175 invoked by alias); 2 Feb 2012 18:32:34 -0000 Received: (qmail 1161 invoked by uid 22791); 2 Feb 2012 18:32:32 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pw0-f47.google.com (HELO mail-pw0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Feb 2012 18:32:18 +0000 Received: by pbbb4 with SMTP id b4so2210679pbb.20 for ; Thu, 02 Feb 2012 10:32:18 -0800 (PST) Received: by 10.68.219.232 with SMTP id pr8mr9902788pbc.12.1328207538023; Thu, 02 Feb 2012 10:32:18 -0800 (PST) Received: by 10.68.219.232 with SMTP id pr8mr9902771pbc.12.1328207537895; Thu, 02 Feb 2012 10:32:17 -0800 (PST) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net. [71.133.8.30]) by mx.google.com with ESMTPS id p9sm7292913pbb.9.2012.02.02.10.32.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Feb 2012 10:32:17 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Permit importing a method to a type being defined Date: Thu, 02 Feb 2012 10:32:14 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes 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 In a slightly complex case (I am adding a test case to the master Go testsuite) it is possible for the importer to see a method for a type which is in the process of being imported and is therefore not fully defined. This was causing the compiler to complain about an undefined type during the import. This patch fixes the problem. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 59d85958d284 go/gogo.cc --- a/go/gogo.cc Wed Feb 01 22:38:55 2012 -0800 +++ b/go/gogo.cc Thu Feb 02 10:25:58 2012 -0800 @@ -880,7 +880,7 @@ else if (rtype->forward_declaration_type() != NULL) { Forward_declaration_type* ftype = rtype->forward_declaration_type(); - return ftype->add_method_declaration(name, type, location); + return ftype->add_method_declaration(name, NULL, type, location); } else go_unreachable(); @@ -4325,11 +4325,12 @@ Named_object* Type_declaration::add_method_declaration(const std::string& name, + Package* package, Function_type* type, Location location) { - Named_object* ret = Named_object::make_function_declaration(name, NULL, type, - location); + Named_object* ret = Named_object::make_function_declaration(name, package, + type, location); this->methods_.push_back(ret); return ret; } diff -r 59d85958d284 go/gogo.h --- a/go/gogo.h Wed Feb 01 22:38:55 2012 -0800 +++ b/go/gogo.h Thu Feb 02 10:25:58 2012 -0800 @@ -1621,8 +1621,8 @@ // Add a method declaration to this type. Named_object* - add_method_declaration(const std::string& name, Function_type* type, - Location location); + add_method_declaration(const std::string& name, Package*, + Function_type* type, Location location); // Return whether any methods were defined. bool diff -r 59d85958d284 go/import.cc --- a/go/import.cc Wed Feb 01 22:38:55 2012 -0800 +++ b/go/import.cc Thu Feb 02 10:25:58 2012 -0800 @@ -441,12 +441,29 @@ Named_object* no; if (fntype->is_method()) { - Type* rtype = receiver->type()->deref(); + Type* rtype = receiver->type(); + + // We may still be reading the definition of RTYPE, so we have + // to be careful to avoid calling base or convert. If RTYPE is + // a named type or a forward declaration, then we know that it + // is not a pointer, because we are reading a method on RTYPE + // and named pointers can't have methods. + + if (rtype->classification() == Type::TYPE_POINTER) + rtype = rtype->points_to(); + if (rtype->is_error_type()) return NULL; - Named_type* named_rtype = rtype->named_type(); - go_assert(named_rtype != NULL); - no = named_rtype->add_method_declaration(name, package, fntype, loc); + else if (rtype->named_type() != NULL) + no = rtype->named_type()->add_method_declaration(name, package, fntype, + loc); + else if (rtype->forward_declaration_type() != NULL) + no = rtype->forward_declaration_type()->add_method_declaration(name, + package, + fntype, + loc); + else + go_unreachable(); } else { @@ -647,8 +664,8 @@ { // We have seen this type before. FIXME: it would be a good // idea to check that the two imported types are identical, - // but we have not finalized the methds yet, which means - // that we can nt reliably compare interface types. + // but we have not finalized the methods yet, which means + // that we can not reliably compare interface types. type = no->type_value(); // Don't change the visibility of the existing type. diff -r 59d85958d284 go/types.cc --- a/go/types.cc Wed Feb 01 22:38:55 2012 -0800 +++ b/go/types.cc Thu Feb 02 10:25:58 2012 -0800 @@ -9115,6 +9115,7 @@ Named_object* Forward_declaration_type::add_method_declaration(const std::string& name, + Package* package, Function_type* type, Location location) { @@ -9122,7 +9123,7 @@ if (no->is_unknown()) no->declare_as_type(); Type_declaration* td = no->type_declaration_value(); - return td->add_method_declaration(name, type, location); + return td->add_method_declaration(name, package, type, location); } // Traversal. diff -r 59d85958d284 go/types.h --- a/go/types.h Wed Feb 01 22:38:55 2012 -0800 +++ b/go/types.h Thu Feb 02 10:25:58 2012 -0800 @@ -2937,7 +2937,7 @@ // Add a method declaration to this type. Named_object* - add_method_declaration(const std::string& name, Function_type*, + add_method_declaration(const std::string& name, Package*, Function_type*, Location); protected: