compiler: don't read known type, simplify Import::finalize_methods

With the current export format, if we already know the type, we don't
    have to read and parse the definition.
    
    We only use the finalizer in Import::finalize_methods, so make it a
    local variable.  To match Finalize_methods::type, only put struct
    types into real_for_named.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/197700

From-SVN: r276188
This commit is contained in:
Ian Lance Taylor 2019-09-27 17:51:43 +00:00
parent 51c3b7c6ec
commit 37ed4c3269
3 changed files with 23 additions and 23 deletions

View File

@ -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.

View File

@ -290,16 +290,10 @@ Import::Import(Stream* stream, Location 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;

View File

@ -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<Named_type*> builtin_types_;
// Mapping from exported type codes to Type structures.
std::vector<Type*> types_;
// Helper for finalizing methods.
Finalize_methods* finalizer_;
// Version of export data we're reading.
Export_data_version version_;
};