public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] typecheck: Refactor unify_site
@ 2023-02-23 16:35 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-23 16:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1145917c6b82ed475b84ae0dd6de241bd018721d

commit 1145917c6b82ed475b84ae0dd6de241bd018721d
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Tue Feb 21 17:29:53 2023 +0100

    typecheck: Refactor unify_site
    
    Refactor unify_site to be a simple function in rust-type-util.h.
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-autoderef.cc: Remove TypeCheckBase qualifier.
            * typecheck/rust-hir-trait-resolve.cc: Remove TypeCheckBase
            qualifier.
            * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site):
            Remove unify_site.
            * typecheck/rust-hir-type-check-base.h: Remove unify_site
            header.
            * typecheck/rust-hir-type-check.cc (TypeResolution::Resolve):
            Remove TypeCheckBase qualifier.
            * typecheck/rust-type-util.cc (unify_site): Add unify_site
            function.
            * typecheck/rust-type-util.h (unify_site): Add unify_site
            prototype.
            * typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::check):
            Remove TypeCheckBase qualifier.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/typecheck/rust-autoderef.cc           |  6 +++---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   | 13 ++++++-------
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 25 +++++--------------------
 gcc/rust/typecheck/rust-hir-type-check-base.h  | 10 +++-------
 gcc/rust/typecheck/rust-hir-type-check.cc      | 16 +++++++---------
 gcc/rust/typecheck/rust-type-util.cc           | 23 +++++++++++++++++++----
 gcc/rust/typecheck/rust-type-util.h            |  5 +++++
 gcc/rust/typecheck/rust-tyty-call.cc           |  7 ++++---
 8 files changed, 52 insertions(+), 53 deletions(-)

diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc
index fe05aeec388..658ddd7c2e9 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -265,9 +265,9 @@ resolve_operator_overload_fn (
 	  fn = static_cast<TyTy::FnType *> (lookup);
 
 	  Location unify_locus = mappings->lookup_location (ty->get_ref ());
-	  TypeCheckBase::unify_site (
-	    ty->get_ref (), TyTy::TyWithLocation (fn->get_self_type ()),
-	    TyTy::TyWithLocation (adjusted_self), unify_locus);
+	  unify_site (ty->get_ref (),
+		      TyTy::TyWithLocation (fn->get_self_type ()),
+		      TyTy::TyWithLocation (adjusted_self), unify_locus);
 
 	  lookup = fn;
 	}
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 2d7985703cf..cb8d4d62fce 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -499,10 +499,10 @@ AssociatedImplTrait::setup_associated_types (
   // the type correctly as our receiver may be generic and we are inferring its
   // generic arguments and this Self might be the concrete version or vice
   // versa.
-  auto result = TypeCheckBase::unify_site (
-    get_impl_block ()->get_mappings ().get_hirid (),
-    TyTy::TyWithLocation (receiver), TyTy::TyWithLocation (impl_self_infer),
-    impl_predicate.get_locus ());
+  auto result = unify_site (get_impl_block ()->get_mappings ().get_hirid (),
+			    TyTy::TyWithLocation (receiver),
+			    TyTy::TyWithLocation (impl_self_infer),
+			    impl_predicate.get_locus ());
   rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
   TyTy::BaseType *self_result = result;
 
@@ -527,9 +527,8 @@ AssociatedImplTrait::setup_associated_types (
       TyTy::BaseType *b = hrtb_bound_arguments.at (i);
 
       result
-	= TypeCheckBase::unify_site (a->get_ref (), TyTy::TyWithLocation (a),
-				     TyTy::TyWithLocation (b),
-				     impl_predicate.get_locus ());
+	= unify_site (a->get_ref (), TyTy::TyWithLocation (a),
+		      TyTy::TyWithLocation (b), impl_predicate.get_locus ());
       rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
     }
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index e302e27f4ab..e401e831441 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -17,13 +17,12 @@
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-hir-type-check-base.h"
-#include "rust-hir-type-check-item.h"
-#include "rust-hir-type-check-type.h"
+#include "rust-casts.h"
+#include "rust-coercion.h"
 #include "rust-hir-type-check-expr.h"
 #include "rust-hir-type-check-implitem.h"
-#include "rust-coercion.h"
-#include "rust-unify.h"
-#include "rust-casts.h"
+#include "rust-hir-type-check-item.h"
+#include "rust-hir-type-check-type.h"
 
 namespace Rust {
 namespace Resolver {
@@ -350,20 +349,6 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, Location locus)
   return repr;
 }
 
-TyTy::BaseType *
-TypeCheckBase::unify_site (HirId id, TyTy::TyWithLocation lhs,
-			   TyTy::TyWithLocation rhs, Location unify_locus)
-{
-  TyTy::BaseType *expected = lhs.get_ty ();
-  TyTy::BaseType *expr = rhs.get_ty ();
-
-  rust_debug ("unify_site id={%u} expected={%s} expr={%s}", id,
-	      expected->debug_str ().c_str (), expr->debug_str ().c_str ());
-
-  return UnifyRules::Resolve (lhs, rhs, unify_locus, true /*commit*/,
-			      true /*emit_error*/);
-}
-
 TyTy::BaseType *
 TypeCheckBase::coercion_site (HirId id, TyTy::TyWithLocation lhs,
 			      TyTy::TyWithLocation rhs, Location locus)
@@ -434,7 +419,7 @@ TypeCheckBase::cast_site (HirId id, TyTy::TyWithLocation from,
 
 void
 TypeCheckBase::resolve_generic_params (
-  const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params,
+  const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
   std::vector<TyTy::SubstitutionParamMapping> &substitutions)
 {
   for (auto &generic_param : generic_params)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h
index b8ff2cf6dc9..133c91eca0f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -20,10 +20,10 @@
 #define RUST_HIR_TYPE_CHECK_BASE
 
 #include "rust-diagnostics.h"
+#include "rust-hir-map.h"
 #include "rust-hir-type-check.h"
-#include "rust-name-resolver.h"
 #include "rust-hir-visitor.h"
-#include "rust-hir-map.h"
+#include "rust-name-resolver.h"
 
 namespace Rust {
 namespace Resolver {
@@ -34,10 +34,6 @@ class TypeCheckBase
 public:
   virtual ~TypeCheckBase () {}
 
-  static TyTy::BaseType *unify_site (HirId id, TyTy::TyWithLocation lhs,
-				     TyTy::TyWithLocation rhs,
-				     Location unify_locus);
-
   static TyTy::BaseType *coercion_site (HirId id, TyTy::TyWithLocation lhs,
 					TyTy::TyWithLocation rhs,
 					Location coercion_locus);
@@ -66,7 +62,7 @@ protected:
 						 Location locus);
 
   void resolve_generic_params (
-    const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params,
+    const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
     std::vector<TyTy::SubstitutionParamMapping> &substitutions);
 
   Analysis::Mappings *mappings;
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index d73e31efab8..f5b481b3dd4 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -18,11 +18,11 @@
 
 #include "rust-hir-type-check.h"
 #include "rust-hir-full.h"
-#include "rust-hir-type-check-item.h"
+#include "rust-hir-inherent-impl-overlap.h"
 #include "rust-hir-type-check-expr.h"
+#include "rust-hir-type-check-item.h"
 #include "rust-hir-type-check-pattern.h"
 #include "rust-hir-type-check-struct-field.h"
-#include "rust-hir-inherent-impl-overlap.h"
 
 extern bool
 saw_errors (void);
@@ -64,9 +64,8 @@ TypeResolution::Resolve (HIR::Crate &crate)
     else
       {
 	auto result
-	  = TypeCheckBase::unify_site (id, TyTy::TyWithLocation (ty),
-				       TyTy::TyWithLocation (default_type),
-				       Location ());
+	  = unify_site (id, TyTy::TyWithLocation (ty),
+			TyTy::TyWithLocation (default_type), Location ());
 	rust_assert (result);
 	rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
 	result->set_ref (id);
@@ -142,10 +141,9 @@ TraitItemReference::get_type_from_constant (
       TyTy::BaseType *expr
 	= TypeCheckExpr::Resolve (constant.get_expr ().get ());
 
-      return TypeCheckBase::unify_site (constant.get_mappings ().get_hirid (),
-					TyTy::TyWithLocation (type),
-					TyTy::TyWithLocation (expr),
-					constant.get_locus ());
+      return unify_site (constant.get_mappings ().get_hirid (),
+			 TyTy::TyWithLocation (type),
+			 TyTy::TyWithLocation (expr), constant.get_locus ());
     }
   return type;
 }
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index 4e38826686b..19935ebd922 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -18,12 +18,13 @@
 
 #include "rust-type-util.h"
 #include "rust-diagnostics.h"
-#include "rust-hir-type-check.h"
-#include "rust-name-resolver.h"
-#include "rust-hir-visitor.h"
 #include "rust-hir-map.h"
-#include "rust-hir-type-check-item.h"
 #include "rust-hir-type-check-implitem.h"
+#include "rust-hir-type-check-item.h"
+#include "rust-hir-type-check.h"
+#include "rust-hir-visitor.h"
+#include "rust-name-resolver.h"
+#include "rust-unify.h"
 
 namespace Rust {
 namespace Resolver {
@@ -104,5 +105,19 @@ query_type (HirId reference, TyTy::BaseType **result)
   return false;
 }
 
+TyTy::BaseType *
+unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
+	    Location unify_locus)
+{
+  TyTy::BaseType *expected = lhs.get_ty ();
+  TyTy::BaseType *expr = rhs.get_ty ();
+
+  rust_debug ("unify_site id={%u} expected={%s} expr={%s}", id,
+	      expected->debug_str ().c_str (), expr->debug_str ().c_str ());
+
+  return UnifyRules::Resolve (lhs, rhs, unify_locus, true /*commit*/,
+			      true /*emit_error*/);
+}
+
 } // namespace Resolver
 } // namespace Rust
diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h
index a3f9efc003b..e504082cec3 100644
--- a/gcc/rust/typecheck/rust-type-util.h
+++ b/gcc/rust/typecheck/rust-type-util.h
@@ -20,6 +20,7 @@
 #define RUST_TYPE_UTIL
 
 #include "rust-mapping-common.h"
+#include "rust-tyty.h"
 
 namespace Rust {
 
@@ -32,6 +33,10 @@ namespace Resolver {
 extern bool
 query_type (HirId reference, TyTy::BaseType **result);
 
+TyTy::BaseType *
+unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
+	    Location unify_locus);
+
 } // namespace Resolver
 } // namespace Rust
 
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc
index f0846ae25ec..3d5fc6593da 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -316,9 +316,10 @@ TypeCheckMethodCallExpr::go (FnType *ref, Analysis::NodeMapping call_mappings,
 BaseType *
 TypeCheckMethodCallExpr::check (FnType &type)
 {
-  Resolver::TypeCheckBase::unify_site (
-    call_mappings.get_hirid (), TyWithLocation (type.get_self_type ()),
-    TyWithLocation (adjusted_self, receiver_locus), call_locus);
+  Resolver::unify_site (call_mappings.get_hirid (),
+			TyWithLocation (type.get_self_type ()),
+			TyWithLocation (adjusted_self, receiver_locus),
+			call_locus);
 
   // +1 for the receiver self
   size_t num_args_to_call = arguments.size () + 1;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-23 16:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 16:35 [gcc/devel/rust/master] typecheck: Refactor unify_site Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).