Commit 50ba28bb by Ian Lance Taylor

Push hash table identity check down to subtypes.

From-SVN: r167870
parent 53f672ca
...@@ -6172,7 +6172,7 @@ Bound_method_expression::do_check_types(Gogo*) ...@@ -6172,7 +6172,7 @@ Bound_method_expression::do_check_types(Gogo*)
? this->expr_type_ ? this->expr_type_
: this->expr_->type()); : this->expr_->type());
etype = etype->deref(); etype = etype->deref();
if (!Type::are_identical(rtype, etype, NULL)) if (!Type::are_identical(rtype, etype, true, NULL))
this->report_error(_("method type does not match object type")); this->report_error(_("method type does not match object type"));
} }
} }
...@@ -6849,7 +6849,7 @@ Builtin_call_expression::do_complex_constant_value(mpfr_t real, mpfr_t imag, ...@@ -6849,7 +6849,7 @@ Builtin_call_expression::do_complex_constant_value(mpfr_t real, mpfr_t imag,
bool ret = false; bool ret = false;
Type* itype; Type* itype;
if (args->back()->float_constant_value(i, &itype) if (args->back()->float_constant_value(i, &itype)
&& Type::are_identical(rtype, itype, NULL)) && Type::are_identical(rtype, itype, false, NULL))
{ {
mpfr_set(real, r, GMP_RNDN); mpfr_set(real, r, GMP_RNDN);
mpfr_set(imag, i, GMP_RNDN); mpfr_set(imag, i, GMP_RNDN);
...@@ -7228,7 +7228,7 @@ Builtin_call_expression::do_check_types(Gogo*) ...@@ -7228,7 +7228,7 @@ Builtin_call_expression::do_check_types(Gogo*)
break; break;
} }
if (!Type::are_identical(e1, e2, NULL)) if (!Type::are_identical(e1, e2, true, NULL))
this->report_error(_("element types must be the same")); this->report_error(_("element types must be the same"));
} }
break; break;
...@@ -7282,7 +7282,7 @@ Builtin_call_expression::do_check_types(Gogo*) ...@@ -7282,7 +7282,7 @@ Builtin_call_expression::do_check_types(Gogo*)
|| args->back()->type()->is_error_type()) || args->back()->type()->is_error_type())
this->set_is_error(); this->set_is_error();
else if (!Type::are_identical(args->front()->type(), else if (!Type::are_identical(args->front()->type(),
args->back()->type(), NULL)) args->back()->type(), true, NULL))
this->report_error(_("cmplx arguments must have identical types")); this->report_error(_("cmplx arguments must have identical types"));
else if (args->front()->type()->float_type() == NULL) else if (args->front()->type()->float_type() == NULL)
this->report_error(_("cmplx arguments must have " this->report_error(_("cmplx arguments must have "
...@@ -8085,7 +8085,7 @@ Call_expression::is_compatible_varargs_argument(Named_object* function, ...@@ -8085,7 +8085,7 @@ Call_expression::is_compatible_varargs_argument(Named_object* function,
Array_type* param_at = param_type->array_type(); Array_type* param_at = param_type->array_type();
if (param_at != NULL if (param_at != NULL
&& Type::are_identical(var_at->element_type(), && Type::are_identical(var_at->element_type(),
param_at->element_type(), NULL)) param_at->element_type(), true, NULL))
return true; return true;
error_at(arg->location(), "... mismatch: passing ...T as ..."); error_at(arg->location(), "... mismatch: passing ...T as ...");
*issued_error = true; *issued_error = true;
......
...@@ -503,16 +503,13 @@ class Type ...@@ -503,16 +503,13 @@ class Type
verify() verify()
{ return this->do_verify(); } { return this->do_verify(); }
// Return true if two types are identical. If this returns false, // Return true if two types are identical. If ERRORS_ARE_IDENTICAL,
// returns that an erroneous type is identical to any other type;
// this is used to avoid cascading errors. If this returns false,
// and REASON is not NULL, it may set *REASON. // and REASON is not NULL, it may set *REASON.
static bool static bool
are_identical(const Type* lhs, const Type* rhs, std::string* reason); are_identical(const Type* lhs, const Type* rhs, bool errors_are_identical,
std::string* reason);
// Return true if two types are identical when it comes to putting
// them in a hash table. This differs from are_identical only in
// how error types are handled.
static bool
are_identical_for_hash_table(const Type*, const Type*);
// Return true if two types are compatible for use in a binary // Return true if two types are compatible for use in a binary
// operation, other than a shift, comparison, or channel send. This // operation, other than a shift, comparison, or channel send. This
...@@ -1110,7 +1107,7 @@ class Type_identical ...@@ -1110,7 +1107,7 @@ class Type_identical
public: public:
bool bool
operator()(const Type* t1, const Type* t2) const operator()(const Type* t1, const Type* t2) const
{ return Type::are_identical_for_hash_table(t1, t2); } { return Type::are_identical(t1, t2, false, NULL); }
}; };
// An identifier with a type. // An identifier with a type.
...@@ -1583,7 +1580,7 @@ class Function_type : public Type ...@@ -1583,7 +1580,7 @@ class Function_type : public Type
// Whether this type is the same as T. // Whether this type is the same as T.
bool bool
is_identical(const Function_type* t, bool ignore_receiver, is_identical(const Function_type* t, bool ignore_receiver,
std::string*) const; bool errors_are_identical, std::string*) const;
// Record that this is a varargs function. // Record that this is a varargs function.
void void
...@@ -1890,7 +1887,7 @@ class Struct_type : public Type ...@@ -1890,7 +1887,7 @@ class Struct_type : public Type
// Whether this type is identical with T. // Whether this type is identical with T.
bool bool
is_identical(const Struct_type* t) const; is_identical(const Struct_type* t, bool errors_are_identical) const;
// Whether this struct type has any hidden fields. This returns // Whether this struct type has any hidden fields. This returns
// true if any fields have hidden names, or if any non-pointer // true if any fields have hidden names, or if any non-pointer
...@@ -2009,7 +2006,7 @@ class Array_type : public Type ...@@ -2009,7 +2006,7 @@ class Array_type : public Type
// Whether this type is identical with T. // Whether this type is identical with T.
bool bool
is_identical(const Array_type* t) const; is_identical(const Array_type* t, bool errors_are_identical) const;
// Whether this type has any hidden fields. // Whether this type has any hidden fields.
bool bool
...@@ -2126,7 +2123,7 @@ class Map_type : public Type ...@@ -2126,7 +2123,7 @@ class Map_type : public Type
// Whether this type is identical with T. // Whether this type is identical with T.
bool bool
is_identical(const Map_type* t) const; is_identical(const Map_type* t, bool errors_are_identical) const;
// Import a map type. // Import a map type.
static Map_type* static Map_type*
...@@ -2212,7 +2209,7 @@ class Channel_type : public Type ...@@ -2212,7 +2209,7 @@ class Channel_type : public Type
// Whether this type is identical with T. // Whether this type is identical with T.
bool bool
is_identical(const Channel_type* t) const; is_identical(const Channel_type* t, bool errors_are_identical) const;
// Import a channel type. // Import a channel type.
static Channel_type* static Channel_type*
...@@ -2315,7 +2312,7 @@ class Interface_type : public Type ...@@ -2315,7 +2312,7 @@ class Interface_type : public Type
// Whether this type is identical with T. REASON is as in // Whether this type is identical with T. REASON is as in
// implements_interface. // implements_interface.
bool bool
is_identical(const Interface_type* t) const; is_identical(const Interface_type* t, bool errors_are_identical) const;
// Whether we can assign T to this type. is_identical is known to // Whether we can assign T to this type. is_identical is known to
// be false. // be false.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment