From patchwork Fri Sep 27 17:51:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1168677 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-509721-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yEl5dqkN"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=golang-org.20150623.gappssmtp.com header.i=@golang-org.20150623.gappssmtp.com header.b="VzhpD84o"; 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 46fzrv0TKLz9sNf for ; Sat, 28 Sep 2019 03:52:12 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=PnmTHhJYnqNu2shpo7LICPF3lzRxS4HfEhNO0UZDv2t1h1 3FZKGf+Mmb1yi44te5HjUrU6mwUE0GZQ4/q4OAM1kkGNWANFWZM7owJh4MHagP4l kTCZGdNAzhv0Bz4BXRmUEfP8q8UI/x596MGsrAUs7d2X2B9bwWv9Dy3ufjcFo= 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=Yznf5FPYU2dc0CIqnvjGQPoyKBg=; b=yEl5dqkNUAhrOfvbqpUV TPVEyBl1Cpfr5jKL+OISPtOFsG3la3b6YRc/Y5K2prdHObPEa//ffmzY8uJ4H54O HkR1V3+m/Rm6iOZUjfFMJbMQvS33XdMAYPXOMjpvyyucO7By43Gfql+sUcFxUeZh 9fdcaowJfSfOpOO7Gtfh6qM= Received: (qmail 107223 invoked by alias); 27 Sep 2019 17:52:04 -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 106707 invoked by uid 89); 27 Sep 2019 17:52:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.7 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.1 spammy=208, 6, HX-Received:d654, HX-HELO:sk:mail-ed, H*r:sk:mail-ed X-HELO: mail-ed1-f52.google.com Received: from mail-ed1-f52.google.com (HELO mail-ed1-f52.google.com) (209.85.208.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Sep 2019 17:52:02 +0000 Received: by mail-ed1-f52.google.com with SMTP id a15so3092798edt.6 for ; Fri, 27 Sep 2019 10:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=FWFS0HbrmoGvP3sPDbx0a1J+e7agskyZbelYI8sxwu0=; b=VzhpD84oRIXE3Kza+QyUU7+iNiMY7USsWbPDeIZ4OBANM6KPhCNXjO592Ti8RujlhV FM3eRSBS7Ju8FgbLqmNoLaN379IoX65tbNSJnHqICYK/fL6XC8sWLPR2vGjDIFAsn/iT +VoI3aqFH1AMUszZlYCjW/toaB6w4xtaV0Lok5Ab5xILkk1uDJxipMq952ODDLvFIxdo RTlWF+5j22JI5k9XteBEZde+JN1YdAeX5B0CbvXdlzWjDa2zmfnwal2t44oirMucI6sj TJ6iDP6Ow78s6SlidDqi/WOH8Ew8vO8Lo8ooXIdqsU6JDVqR9+ArO1ZP68CAffCHXpQn mk3Q== MIME-Version: 1.0 From: Ian Lance Taylor Date: Fri, 27 Sep 2019 10:51:49 -0700 Message-ID: Subject: Go patch committed: Don't read a known type from import data To: gcc-patches , gofrontend-dev With the current Go export format, if we already know the type, we don't have to read and parse the definition. This patch to the Go frontend implements that. Also, we only use the finalizer in Import::finalize_methods, so make it a local variable. And to match Finalize_methods::type, only put struct types into real_for_named. 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 276187) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -27d1f3031197428b5745d09c167f982d638b8776 +9112ea664ed9ee5f108158a913812adaf03edf6e The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/import.cc =================================================================== --- gcc/go/gofrontend/import.cc (revision 275698) +++ gcc/go/gofrontend/import.cc (working copy) @@ -290,16 +290,10 @@ Import::Import(Stream* stream, Location : gogo_(NULL), stream_(stream), location_(location), package_(NULL), add_to_globals_(false), packages_(), type_data_(), type_pos_(0), type_offsets_(), builtin_types_((- SMALLEST_BUILTIN_CODE) + 1), - types_(), finalizer_(NULL), version_(EXPORT_FORMAT_UNKNOWN) + types_(), version_(EXPORT_FORMAT_UNKNOWN) { } -Import::~Import() -{ - if (this->finalizer_ != NULL) - delete this->finalizer_; -} - // Import the data in the associated stream. Package* @@ -692,16 +686,22 @@ Import::read_types() void Import::finalize_methods() { - if (this->finalizer_ == NULL) - this->finalizer_ = new Finalize_methods(gogo_); + Finalize_methods finalizer(this->gogo_); Unordered_set(Type*) real_for_named; for (size_t i = 1; i < this->types_.size(); i++) { Type* type = this->types_[i]; if (type != NULL && type->named_type() != NULL) { - this->finalizer_->type(type); - real_for_named.insert(type->named_type()->real_type()); + finalizer.type(type); + + // If the real type is a struct type, we don't want to + // finalize its methods. For a named type defined as a + // struct type, we only want to finalize the methods of the + // named type. This is like Finalize_methods::type. + Type* real_type = type->named_type()->real_type(); + if (real_type->struct_type() != NULL) + real_for_named.insert(real_type); } } for (size_t i = 1; i < this->types_.size(); i++) @@ -710,7 +710,7 @@ Import::finalize_methods() if (type != NULL && type->named_type() == NULL && real_for_named.find(type) == real_for_named.end()) - this->finalizer_->type(type); + finalizer.type(type); } } @@ -1105,12 +1105,12 @@ Import::read_named_type(int index) type = this->types_[index]; else { - type = this->read_type(); - if (no->is_type_declaration()) { // We can define the type now. + type = this->read_type(); + no = package->add_type(type_name, type, this->location_); Named_type* ntype = no->type_value(); @@ -1127,14 +1127,18 @@ Import::read_named_type(int index) } else if (no->is_type()) { - // 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 methods yet, which means - // that we can not reliably compare interface types. + // We have seen this type before. type = no->type_value(); // Don't change the visibility of the existing type. + + // For older export versions, we need to skip the type + // definition in the stream. + if (this->version_ < EXPORT_FORMAT_V3) + this->read_type(); } + else + go_unreachable(); this->types_[index] = type; Index: gcc/go/gofrontend/import.h =================================================================== --- gcc/go/gofrontend/import.h (revision 275698) +++ gcc/go/gofrontend/import.h (working copy) @@ -208,8 +208,6 @@ class Import : public Import_expression // Constructor. Import(Stream*, Location); - virtual ~Import(); - // Register the builtin types. void register_builtin_types(Gogo*); @@ -450,8 +448,6 @@ class Import : public Import_expression std::vector builtin_types_; // Mapping from exported type codes to Type structures. std::vector types_; - // Helper for finalizing methods. - Finalize_methods* finalizer_; // Version of export data we're reading. Export_data_version version_; };