From a1c148518de1cb8f60f779dc206f663e8593191a Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 12 May 2021 17:50:57 +0100 Subject: Add the identifier to part of fntype signitures Tracking the identifier helps ensure fntypes are distinct and do not overlap. --- gcc/rust/typecheck/rust-hir-type-check-implitem.h | 10 ++++++---- gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 3 ++- gcc/rust/typecheck/rust-tyty.cc | 10 +++++++--- gcc/rust/typecheck/rust-tyty.h | 13 +++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index f961bba..2f54d0c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -112,7 +112,8 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), - false, std::move (params), ret_type, + function.get_function_name (), false, + std::move (params), ret_type, std::move (substitutions)); context->insert_type (function.get_mappings (), fnType); } @@ -189,9 +190,10 @@ public: context->insert_type (param.get_mappings (), param_tyty); } - auto fnType = new TyTy::FnType (method.get_mappings ().get_hirid (), true, - std::move (params), ret_type, - std::move (substitutions)); + auto fnType + = new TyTy::FnType (method.get_mappings ().get_hirid (), + method.get_method_name (), true, std::move (params), + ret_type, std::move (substitutions)); context->insert_type (method.get_mappings (), fnType); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h index ef940c1..e01b46f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h +++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h @@ -229,7 +229,8 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), - false, std::move (params), ret_type, + function.get_function_name (), false, + std::move (params), ret_type, std::move (substitutions)); context->insert_type (function.get_mappings (), fnType); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 551042a..0859570 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -679,6 +679,9 @@ FnType::is_equal (const BaseType &other) const return false; auto other2 = static_cast (other); + if (get_identifier ().compare (other2.get_identifier ()) != 0) + return false; + if (!get_return_type ()->is_equal (*other2.get_return_type ())) return false; @@ -712,9 +715,10 @@ FnType::clone () cloned_params.push_back ( std::pair (p.first, p.second->clone ())); - return new FnType (get_ref (), get_ty_ref (), is_method_flag, - std::move (cloned_params), get_return_type ()->clone (), - clone_substs (), get_combined_refs ()); + return new FnType (get_ref (), get_ty_ref (), get_identifier (), + is_method_flag, std::move (cloned_params), + get_return_type ()->clone (), clone_substs (), + get_combined_refs ()); } FnType * diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index aa709ec..5acc9e7 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -855,24 +855,26 @@ private: class FnType : public BaseType, public SubstitutionRef { public: - FnType (HirId ref, bool is_method, + FnType (HirId ref, std::string identifier, bool is_method, std::vector > params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) : BaseType (ref, ref, TypeKind::FNDEF, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - params (std::move (params)), type (type), is_method_flag (is_method) + params (std::move (params)), type (type), is_method_flag (is_method), + identifier (identifier) {} - FnType (HirId ref, HirId ty_ref, bool is_method, + FnType (HirId ref, HirId ty_ref, std::string identifier, bool is_method, std::vector > params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) : BaseType (ref, ty_ref, TypeKind::FNDEF, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - params (params), type (type), is_method_flag (is_method) + params (params), type (type), is_method_flag (is_method), + identifier (identifier) {} void accept_vis (TyVisitor &vis) override; @@ -881,6 +883,8 @@ public: std::string get_name () const override final { return as_string (); } + std::string get_identifier () const { return identifier; } + BaseType *unify (BaseType *other) override; bool can_eq (BaseType *other) override; @@ -947,6 +951,7 @@ private: std::vector > params; BaseType *type; bool is_method_flag; + std::string identifier; }; class FnPtr : public BaseType -- cgit v1.1