From 894e6951cfdd4868a396bde68ac01f0ad28326f0 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 19 May 2025 17:42:17 +0100 Subject: [PATCH] gccrs: Remove unneeded clones untill we have an arena allocator for these tmps 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 --- .../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 c78a2f5dcc6..4a5a6aa7cf1 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -219,8 +219,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 (ty)->get_base ()); diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 45c4cbaa7df..4cfc197c430 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 ()) + context.insert_implicit_type (ref, resolved); } } } @@ -341,7 +335,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; @@ -351,7 +345,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; } @@ -369,7 +363,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, if (is_valid) { ltype->apply_primitive_type_hint (*rtype); - return rtype->clone (); + return rtype; } } break; @@ -382,7 +376,7 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype, if (is_valid) { ltype->apply_primitive_type_hint (*rtype); - return rtype->clone (); + return rtype; } } break; -- 2.47.3