]> 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)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:43 +0000 (16:36 +0200)
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 3faa3b404e69ee4939b6e53ce5c65247d5795c97..e1d4b167d3d8d87ea276439ccd6b1a438158e04e 100644 (file)
@@ -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 ());
index 0ffab667433c40a27b253f372df1d4b4b7e22884..6699f7e46b564b8e9be5d69c04bea2567279c1b6 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);
        }
     }
 }
@@ -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;