diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-08 13:41:30 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-07-10 21:28:51 +0100 |
commit | 99355534ef44f316ec2b72f4776e08cf01169715 (patch) | |
tree | da8af10feb16cd77c081304e574d9c85b11ee19e | |
parent | e3390f5602149c9f918efdd9fdc63448920da916 (diff) | |
download | gcc-99355534ef44f316ec2b72f4776e08cf01169715.zip gcc-99355534ef44f316ec2b72f4776e08cf01169715.tar.gz gcc-99355534ef44f316ec2b72f4776e08cf01169715.tar.bz2 |
The type system has a function can_eq this adds a with_errors flag
With the type system we can check for equality explicitly which is useful.
When it comes to TypeParameters or Placeholders can_eq allows for:
fn bla<T>() -> <T>
fn bla() -> i32
The type parameter can be subsituted which means the generic function can
equal the subsituted one if it was given the right substituion arguments.
This can emit errors such as expected [X] got [Y] or we might want to
have silent errors so we can filter impl items such as the impl item
overlapping pass
-rw-r--r-- | gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-path-probe.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-implitem.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-cmp.h | 448 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 76 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 40 |
7 files changed, 440 insertions, 132 deletions
diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h index 47894b1..cbfe1df 100644 --- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h +++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h @@ -145,7 +145,7 @@ public: if (query == candidate) continue; - if (query->can_eq (candidate)) + if (query->can_eq (candidate, false)) possible_collision (it->second, iy->second); } } diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index 0e26778..e21bfc9 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -58,7 +58,7 @@ public: bool ok = context->lookup_type (impl_ty_id, &impl_block_ty); rust_assert (ok); - if (!receiver->can_eq (impl_block_ty)) + if (!receiver->can_eq (impl_block_ty, false)) return; // lets visit the impl_item diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 327a9a0..dd10d42 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -275,7 +275,7 @@ public: // always be at the end of the list auto s = fn->get_self_type (); - rust_assert (s->can_eq (adt)); + rust_assert (s->can_eq (adt, false)); rust_assert (s->get_kind () == TyTy::TypeKind::ADT); TyTy::ADTType *self_adt = static_cast<TyTy::ADTType *> (s); diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index d161586..d617882 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -263,7 +263,7 @@ public: = trait_item_fntype->handle_substitions (implicit_self_substs); // check the types are compatible - if (!trait_item_fntype->can_eq (fntype)) + if (!trait_item_fntype->can_eq (fntype, true)) { RichLocation r (function.get_locus ()); r.add_range (trait_item_ref.get_locus ()); diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index 7595e2f..f01ef3b 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -46,61 +46,303 @@ public: return ok; } - virtual void visit (TupleType &) override { ok = false; } + virtual void visit (TupleType &type) override + { + ok = false; - virtual void visit (ADTType &) override { ok = false; } + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (InferType &) override { ok = false; } + virtual void visit (ADTType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (FnType &) override { ok = false; } + virtual void visit (InferType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (FnPtr &) override { ok = false; } + virtual void visit (FnType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (ArrayType &) override { ok = false; } + virtual void visit (FnPtr &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (BoolType &) override { ok = false; } + virtual void visit (ArrayType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (IntType &) override { ok = false; } + virtual void visit (BoolType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (UintType &) override { ok = false; } + virtual void visit (IntType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (USizeType &) override { ok = false; } + virtual void visit (UintType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (ISizeType &) override { ok = false; } + virtual void visit (USizeType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (FloatType &) override { ok = false; } + virtual void visit (ISizeType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (ErrorType &) override { ok = false; } + virtual void visit (FloatType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (CharType &) override { ok = false; } + virtual void visit (ErrorType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (ReferenceType &) override { ok = false; } + virtual void visit (CharType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (ParamType &) override + virtual void visit (ReferenceType &type) override { - // it is ok for types to can eq to a ParamType - ok = true; + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } } - virtual void visit (StrType &) override { ok = false; } + virtual void visit (StrType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } + + virtual void visit (NeverType &type) override + { + ok = false; + if (emit_error_flag) + { + Location ref_locus = mappings->lookup_location (type.get_ref ()); + Location base_locus + = mappings->lookup_location (get_base ()->get_ref ()); + RichLocation r (ref_locus); + r.add_range (base_locus); + rust_error_at (r, "expected [%s] got [%s]", + get_base ()->as_string ().c_str (), + type.as_string ().c_str ()); + } + } - virtual void visit (NeverType &) override { ok = false; } + virtual void visit (PlaceholderType &type) override + { + // it is ok for types to can eq to a placeholder + ok = true; + } - virtual void visit (PlaceholderType &) override - { // it is ok for types to can eq to a placeholder + virtual void visit (ParamType &type) override + { + // it is ok for types to can eq to a ParamType ok = true; } protected: - BaseCmp (BaseType *base) + BaseCmp (BaseType *base, bool emit_errors) : mappings (Analysis::Mappings::get ()), - context (Resolver::TypeCheckContext::get ()), ok (false) + context (Resolver::TypeCheckContext::get ()), ok (false), + emit_error_flag (emit_errors) {} Analysis::Mappings *mappings; Resolver::TypeCheckContext *context; bool ok; + bool emit_error_flag; private: /* Returns a pointer to the ty that created this rule. */ @@ -112,7 +354,9 @@ class InferCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - InferCmp (InferType *base) : BaseCmp (base), base (base) {} + InferCmp (InferType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (BoolType &type) override { @@ -333,7 +577,9 @@ class FnCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - FnCmp (FnType *base) : BaseCmp (base), base (base) {} + FnCmp (FnType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -353,18 +599,18 @@ public: auto a = base->param_at (i).second; auto b = type.param_at (i).second; - auto unified_param = a->unify (b); - if (unified_param->get_kind () == TypeKind::ERROR) + if (!a->can_eq (b, emit_error_flag)) { + emit_error_flag = false; BaseCmp::visit (type); return; } } - auto unified_return - = base->get_return_type ()->unify (type.get_return_type ()); - if (unified_return->get_kind () == TypeKind::ERROR) + if (!base->get_return_type ()->can_eq (type.get_return_type (), + emit_error_flag)) { + emit_error_flag = false; BaseCmp::visit (type); return; } @@ -383,7 +629,9 @@ class FnptrCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - FnptrCmp (FnPtr *base) : BaseCmp (base), base (base) {} + FnptrCmp (FnPtr *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -398,17 +646,15 @@ public: void visit (FnPtr &type) override { - auto this_ret_type = base->get_return_type (); - auto other_ret_type = type.get_return_type (); - auto unified_result = this_ret_type->unify (other_ret_type); - if (unified_result == nullptr - || unified_result->get_kind () == TypeKind::ERROR) + if (base->num_params () != type.num_params ()) { BaseCmp::visit (type); return; } - if (base->num_params () != type.num_params ()) + auto this_ret_type = base->get_return_type (); + auto other_ret_type = type.get_return_type (); + if (!this_ret_type->can_eq (other_ret_type, emit_error_flag)) { BaseCmp::visit (type); return; @@ -418,9 +664,7 @@ public: { auto this_param = base->param_at (i); auto other_param = type.param_at (i); - auto unified_param = this_param->unify (other_param); - if (unified_param == nullptr - || unified_param->get_kind () == TypeKind::ERROR) + if (!this_param->can_eq (other_param, emit_error_flag)) { BaseCmp::visit (type); return; @@ -432,17 +676,15 @@ public: void visit (FnType &type) override { - auto this_ret_type = base->get_return_type (); - auto other_ret_type = type.get_return_type (); - auto unified_result = this_ret_type->unify (other_ret_type); - if (unified_result == nullptr - || unified_result->get_kind () == TypeKind::ERROR) + if (base->num_params () != type.num_params ()) { BaseCmp::visit (type); return; } - if (base->num_params () != type.num_params ()) + auto this_ret_type = base->get_return_type (); + auto other_ret_type = type.get_return_type (); + if (!this_ret_type->can_eq (other_ret_type, emit_error_flag)) { BaseCmp::visit (type); return; @@ -452,9 +694,7 @@ public: { auto this_param = base->param_at (i); auto other_param = type.param_at (i).second; - auto unified_param = this_param->unify (other_param); - if (unified_param == nullptr - || unified_param->get_kind () == TypeKind::ERROR) + if (!this_param->can_eq (other_param, emit_error_flag)) { BaseCmp::visit (type); return; @@ -475,7 +715,9 @@ class ArrayCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - ArrayCmp (ArrayType *base) : BaseCmp (base), base (base) {} + ArrayCmp (ArrayType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (ArrayType &type) override { @@ -511,7 +753,9 @@ class BoolCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - BoolCmp (BoolType *base) : BaseCmp (base), base (base) {} + BoolCmp (BoolType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (BoolType &type) override { ok = true; } @@ -531,7 +775,9 @@ class IntCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - IntCmp (IntType *base) : BaseCmp (base), base (base) {} + IntCmp (IntType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -554,7 +800,9 @@ class UintCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - UintCmp (UintType *base) : BaseCmp (base), base (base) {} + UintCmp (UintType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -577,7 +825,9 @@ class FloatCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - FloatCmp (FloatType *base) : BaseCmp (base), base (base) {} + FloatCmp (FloatType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -600,7 +850,9 @@ class ADTCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - ADTCmp (ADTType *base) : BaseCmp (base), base (base) {} + ADTCmp (ADTType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (ADTType &type) override { @@ -624,7 +876,7 @@ public: TyTy::BaseType *this_field_ty = base_field->get_field_type (); TyTy::BaseType *other_field_ty = other_field->get_field_type (); - if (!this_field_ty->can_eq (other_field_ty)) + if (!this_field_ty->can_eq (other_field_ty, emit_error_flag)) { BaseCmp::visit (type); return; @@ -645,7 +897,9 @@ class TupleCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - TupleCmp (TupleType *base) : BaseCmp (base), base (base) {} + TupleCmp (TupleType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (TupleType &type) override { @@ -660,7 +914,7 @@ public: BaseType *bo = base->get_field (i); BaseType *fo = type.get_field (i); - if (!bo->can_eq (fo)) + if (!bo->can_eq (fo, emit_error_flag)) { BaseCmp::visit (type); return; @@ -681,7 +935,9 @@ class USizeCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - USizeCmp (USizeType *base) : BaseCmp (base), base (base) {} + USizeCmp (USizeType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -701,7 +957,9 @@ class ISizeCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - ISizeCmp (ISizeType *base) : BaseCmp (base), base (base) {} + ISizeCmp (ISizeType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -721,7 +979,9 @@ class CharCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - CharCmp (CharType *base) : BaseCmp (base), base (base) {} + CharCmp (CharType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (InferType &type) override { @@ -741,14 +1001,16 @@ class ReferenceCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - ReferenceCmp (ReferenceType *base) : BaseCmp (base), base (base) {} + ReferenceCmp (ReferenceType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (ReferenceType &type) override { auto base_type = base->get_base (); auto other_base_type = type.get_base (); - ok = base_type->can_eq (other_base_type); + ok = base_type->can_eq (other_base_type, emit_error_flag); } private: @@ -762,7 +1024,9 @@ class ParamCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - ParamCmp (ParamType *base) : BaseCmp (base), base (base) {} + ParamCmp (ParamType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} // param types are a placeholder we shouldn't have cases where we unify // against it. eg: struct foo<T> { a: T }; When we invoke it we can do either: @@ -786,10 +1050,10 @@ public: if (lookup->get_kind () == TypeKind::PARAM) { InferType infer (UNKNOWN_HIRID, InferType::InferTypeKind::GENERAL); - return infer.can_eq (other); + return infer.can_eq (other, emit_error_flag); } - return lookup->can_eq (other); + return lookup->can_eq (other, emit_error_flag); } // imagine the case where we have: @@ -812,7 +1076,9 @@ class StrCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - StrCmp (StrType *base) : BaseCmp (base), base (base) {} + StrCmp (StrType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (StrType &type) override { ok = true; } @@ -827,7 +1093,9 @@ class NeverCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - NeverCmp (NeverType *base) : BaseCmp (base), base (base) {} + NeverCmp (NeverType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} void visit (NeverType &type) override { ok = true; } @@ -842,7 +1110,47 @@ class PlaceholderCmp : public BaseCmp using Rust::TyTy::BaseCmp::visit; public: - PlaceholderCmp (PlaceholderType *base) : BaseCmp (base), base (base) {} + PlaceholderCmp (PlaceholderType *base, bool emit_errors) + : BaseCmp (base, emit_errors), base (base) + {} + + virtual void visit (TupleType &) override { ok = true; } + + virtual void visit (ADTType &) override { ok = true; } + + virtual void visit (InferType &) override { ok = true; } + + virtual void visit (FnType &) override { ok = true; } + + virtual void visit (FnPtr &) override { ok = true; } + + virtual void visit (ArrayType &) override { ok = true; } + + virtual void visit (BoolType &) override { ok = true; } + + virtual void visit (IntType &) override { ok = true; } + + virtual void visit (UintType &) override { ok = true; } + + virtual void visit (USizeType &) override { ok = true; } + + virtual void visit (ISizeType &) override { ok = true; } + + virtual void visit (FloatType &) override { ok = true; } + + virtual void visit (ErrorType &) override { ok = true; } + + virtual void visit (CharType &) override { ok = true; } + + virtual void visit (ReferenceType &) override { ok = true; } + + virtual void visit (ParamType &) override { ok = true; } + + virtual void visit (StrType &) override { ok = true; } + + virtual void visit (NeverType &) override { ok = true; } + + virtual void visit (PlaceholderType &) override { ok = true; } private: BaseType *get_base () override { return base; } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 503d380..ba98212 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -98,9 +98,9 @@ InferType::unify (BaseType *other) } bool -InferType::can_eq (BaseType *other) +InferType::can_eq (BaseType *other, bool emit_errors) { - InferCmp r (this); + InferCmp r (this, emit_errors); return r.can_eq (other); } @@ -155,7 +155,7 @@ ErrorType::unify (BaseType *other) } bool -ErrorType::can_eq (BaseType *other) +ErrorType::can_eq (BaseType *other, bool emit_errors) { return get_kind () == other->get_kind (); } @@ -421,9 +421,9 @@ ADTType::unify (BaseType *other) } bool -ADTType::can_eq (BaseType *other) +ADTType::can_eq (BaseType *other, bool emit_errors) { - ADTCmp r (this); + ADTCmp r (this, emit_errors); return r.can_eq (other); } @@ -582,9 +582,9 @@ TupleType::unify (BaseType *other) } bool -TupleType::can_eq (BaseType *other) +TupleType::can_eq (BaseType *other, bool emit_errors) { - TupleCmp r (this); + TupleCmp r (this, emit_errors); return r.can_eq (other); } @@ -666,9 +666,9 @@ FnType::unify (BaseType *other) } bool -FnType::can_eq (BaseType *other) +FnType::can_eq (BaseType *other, bool emit_errors) { - FnCmp r (this); + FnCmp r (this, emit_errors); return r.can_eq (other); } @@ -861,9 +861,9 @@ FnPtr::unify (BaseType *other) } bool -FnPtr::can_eq (BaseType *other) +FnPtr::can_eq (BaseType *other, bool emit_errors) { - FnptrCmp r (this); + FnptrCmp r (this, emit_errors); return r.can_eq (other); } @@ -928,9 +928,9 @@ ArrayType::unify (BaseType *other) } bool -ArrayType::can_eq (BaseType *other) +ArrayType::can_eq (BaseType *other, bool emit_errors) { - ArrayCmp r (this); + ArrayCmp r (this, emit_errors); return r.can_eq (other); } @@ -983,9 +983,9 @@ BoolType::unify (BaseType *other) } bool -BoolType::can_eq (BaseType *other) +BoolType::can_eq (BaseType *other, bool emit_errors) { - BoolCmp r (this); + BoolCmp r (this, emit_errors); return r.can_eq (other); } @@ -1029,9 +1029,9 @@ IntType::unify (BaseType *other) } bool -IntType::can_eq (BaseType *other) +IntType::can_eq (BaseType *other, bool emit_errors) { - IntCmp r (this); + IntCmp r (this, emit_errors); return r.can_eq (other); } @@ -1086,9 +1086,9 @@ UintType::unify (BaseType *other) } bool -UintType::can_eq (BaseType *other) +UintType::can_eq (BaseType *other, bool emit_errors) { - UintCmp r (this); + UintCmp r (this, emit_errors); return r.can_eq (other); } @@ -1137,9 +1137,9 @@ FloatType::unify (BaseType *other) } bool -FloatType::can_eq (BaseType *other) +FloatType::can_eq (BaseType *other, bool emit_errors) { - FloatCmp r (this); + FloatCmp r (this, emit_errors); return r.can_eq (other); } @@ -1180,9 +1180,9 @@ USizeType::unify (BaseType *other) } bool -USizeType::can_eq (BaseType *other) +USizeType::can_eq (BaseType *other, bool emit_errors) { - USizeCmp r (this); + USizeCmp r (this, emit_errors); return r.can_eq (other); } @@ -1212,9 +1212,9 @@ ISizeType::unify (BaseType *other) } bool -ISizeType::can_eq (BaseType *other) +ISizeType::can_eq (BaseType *other, bool emit_errors) { - ISizeCmp r (this); + ISizeCmp r (this, emit_errors); return r.can_eq (other); } @@ -1244,9 +1244,9 @@ CharType::unify (BaseType *other) } bool -CharType::can_eq (BaseType *other) +CharType::can_eq (BaseType *other, bool emit_errors) { - CharCmp r (this); + CharCmp r (this, emit_errors); return r.can_eq (other); } @@ -1276,9 +1276,9 @@ ReferenceType::unify (BaseType *other) } bool -ReferenceType::can_eq (BaseType *other) +ReferenceType::can_eq (BaseType *other, bool emit_errors) { - ReferenceCmp r (this); + ReferenceCmp r (this, emit_errors); return r.can_eq (other); } @@ -1351,9 +1351,9 @@ ParamType::unify (BaseType *other) } bool -ParamType::can_eq (BaseType *other) +ParamType::can_eq (BaseType *other, bool emit_errors) { - ParamCmp r (this); + ParamCmp r (this, emit_errors); return r.can_eq (other); } @@ -1407,7 +1407,7 @@ ParamType::is_equal (const BaseType &other) const return false; if (can_resolve ()) - return resolve ()->can_eq (other2.resolve ()); + return resolve ()->can_eq (other2.resolve (), false); return get_symbol ().compare (other2.get_symbol ()) == 0; } @@ -1451,9 +1451,9 @@ StrType::unify (BaseType *other) } bool -StrType::can_eq (BaseType *other) +StrType::can_eq (BaseType *other, bool emit_errors) { - StrCmp r (this); + StrCmp r (this, emit_errors); return r.can_eq (other); } @@ -1483,9 +1483,9 @@ NeverType::unify (BaseType *other) } bool -NeverType::can_eq (BaseType *other) +NeverType::can_eq (BaseType *other, bool emit_errors) { - NeverCmp r (this); + NeverCmp r (this, emit_errors); return r.can_eq (other); } @@ -1515,9 +1515,9 @@ PlaceholderType::unify (BaseType *other) } bool -PlaceholderType::can_eq (BaseType *other) +PlaceholderType::can_eq (BaseType *other, bool emit_errors) { - PlaceholderCmp r (this); + PlaceholderCmp r (this, emit_errors); return r.can_eq (other); } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index c04c249..d85b8a8 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -155,7 +155,7 @@ public: // similar to unify but does not actually perform type unification but // determines whether they are compatible - virtual bool can_eq (BaseType *other) = 0; + virtual bool can_eq (BaseType *other, bool emit_errors) = 0; // Check value equality between two ty. Type inference rules are ignored. Two // ty are considered equal if they're of the same kind, and @@ -274,7 +274,7 @@ public: BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; @@ -308,7 +308,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; @@ -336,7 +336,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; @@ -421,7 +421,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -853,7 +853,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -960,7 +960,7 @@ public: std::string get_identifier () const { return identifier; } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -1056,7 +1056,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -1098,7 +1098,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -1137,7 +1137,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; }; @@ -1170,7 +1170,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; IntKind get_int_kind () const { return int_kind; } @@ -1210,7 +1210,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; UintKind get_uint_kind () const { return uint_kind; } @@ -1248,7 +1248,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; FloatKind get_float_kind () const { return float_kind; } @@ -1288,7 +1288,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; }; @@ -1321,7 +1321,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; }; @@ -1354,7 +1354,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; }; @@ -1391,7 +1391,7 @@ public: std::string get_name () const override final { return as_string (); } BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -1436,7 +1436,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; bool is_equal (const BaseType &other) const override; @@ -1469,7 +1469,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; @@ -1497,7 +1497,7 @@ public: std::string as_string () const override; BaseType *unify (BaseType *other) override; - bool can_eq (BaseType *other) override; + bool can_eq (BaseType *other, bool emit_errors) override; BaseType *clone () final override; |