]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Remove unneeded clones untill we have an arena allocator for these tmps
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 19 May 2025 16:42:17 +0000 (17:42 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Mon, 26 May 2025 18:09:21 +0000 (18:09 +0000)
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>
gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
gcc/rust/typecheck/rust-unify.cc

index c78a2f5dcc6d9be6be1b5e174fbd3ca3bb2eab56..4a5a6aa7cf1907eac0bdbe38187bfd1646f5adae 100644 (file)
@@ -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 ());
index 45c4cbaa7df8baac5ca1279ebef14698b30613de..4cfc197c430ad69d91c72ce53a06b90f4029134c 100644 (file)
@@ -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;