diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-05-19 17:42:17 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-05-26 18:09:21 +0000 |
commit | 894e6951cfdd4868a396bde68ac01f0ad28326f0 (patch) | |
tree | 62a020f5a50c421b44fe51574cf9b33daa84f4aa | |
parent | 457b3d1e29ce72bda6ac74a7c761decd657aab12 (diff) | |
download | gcc-894e6951cfdd4868a396bde68ac01f0ad28326f0.zip gcc-894e6951cfdd4868a396bde68ac01f0ad28326f0.tar.gz gcc-894e6951cfdd4868a396bde68ac01f0ad28326f0.tar.bz2 |
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 <herron.philip@googlemail.com>
-rw-r--r-- | gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc | 3 | ||||
-rw-r--r-- | 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 c78a2f5..4a5a6aa 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<const TyTy::ReferenceType *> (ty)->get_base ()); diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 45c4cba..4cfc197 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); } } } @@ -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; |