From: Philip Herron <herron.phi...@googlemail.com> Cloning inference variables is very expensive because it means we are indirectly creating an implicit new inference variable added to the reference chain.
gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): no need for unreachable here * typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars (UnifyRules::expect_inference_variable): likewise Signed-off-by: Philip Herron <herron.phi...@googlemail.com> --- .../errors/privacy/rust-privacy-reporter.cc | 3 ++- gcc/rust/typecheck/rust-unify.cc | 18 ++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index 3faa3b404e6..e1d4b167d3d 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -221,8 +221,9 @@ PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings, auto ref_id = ty->get_ref (); if (auto lookup_id = mappings.lookup_hir_to_node (ref_id)) return check_for_privacy_violation (*lookup_id, locus); - rust_unreachable (); } + break; + case TyTy::REF: return recursive_check ( static_cast<const TyTy::ReferenceType *> (ty)->get_base ()); diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 0ffab667433..6699f7e46b5 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -69,7 +69,6 @@ UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other, TyTy::BaseType *resolved) { TypeCheckContext &context = *TypeCheckContext::get (); - Analysis::Mappings &mappings = Analysis::Mappings::get (); TyTy::BaseType *b = base->destructure (); TyTy::BaseType *o = other->destructure (); @@ -102,13 +101,8 @@ UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other, continue; // if any of the types are inference variables lets fix them - if (ref_tyty->get_kind () == TyTy::TypeKind::INFER) - { - auto node = Analysis::NodeMapping (mappings.get_current_crate (), - UNKNOWN_NODEID, ref, - UNKNOWN_LOCAL_DEFID); - context.insert_type (node, resolved->clone ()); - } + if (ref_tyty->is<TyTy::InferType> ()) + context.insert_implicit_type (ref, resolved); } } } @@ -343,7 +337,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, || r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; if (is_valid) - return rtype->clone (); + return rtype; } break; @@ -354,7 +348,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, || r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; if (is_valid) - return rtype->clone (); + return rtype; } break; } @@ -373,7 +367,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, if (is_valid) { ltype->apply_primitive_type_hint (*rtype); - return rtype->clone (); + return rtype; } } break; @@ -387,7 +381,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, if (is_valid) { ltype->apply_primitive_type_hint (*rtype); - return rtype->clone (); + return rtype; } } break; -- 2.49.0