public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Enforce the is_concrete inferface to start cleaning up the needs_substitution helpers
@ 2022-06-08 11:48 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:92a24fc3aecc11fc80387479829ea97293c44076

commit 92a24fc3aecc11fc80387479829ea97293c44076
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri Nov 5 11:04:28 2021 +0000

    Enforce the is_concrete inferface to start cleaning up the needs_substitution helpers

Diff:
---
 gcc/rust/typecheck/rust-tyty.cc |  10 ++++
 gcc/rust/typecheck/rust-tyty.h  | 116 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 112 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 16cabc8bb1b..184922857aa 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -333,6 +333,16 @@ StructFieldType::clone () const
 			      get_field_type ()->clone ());
 }
 
+bool
+SubstitutionParamMapping::need_substitution () const
+{
+  if (!param->can_resolve ())
+    return true;
+
+  auto resolved = param->resolve ();
+  return !resolved->is_concrete ();
+}
+
 bool
 SubstitutionParamMapping::fill_param_ty (BaseType &type, Location locus)
 {
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 5ffd95c29da..5e26b3af549 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -340,7 +340,7 @@ public:
 
   virtual bool is_unit () const { return false; }
 
-  virtual bool is_concrete () const { return true; }
+  virtual bool is_concrete () const = 0;
 
   TypeKind get_kind () const { return kind; }
 
@@ -470,7 +470,7 @@ public:
 
   bool default_type (BaseType **type) const;
 
-  bool is_concrete () const final override { return false; }
+  bool is_concrete () const final override { return true; }
 
 private:
   InferTypeKind infer_kind;
@@ -503,6 +503,8 @@ public:
   BaseType *clone () const final override;
 
   std::string get_name () const override final { return as_string (); }
+
+  bool is_concrete () const final override { return false; }
 };
 
 class SubstitutionArgumentMappings;
@@ -559,6 +561,11 @@ public:
     return true;
   }
 
+  bool is_concrete () const override final
+  {
+    return !contains_type_parameters ();
+  }
+
   ParamType *handle_substitions (SubstitutionArgumentMappings mappings);
 
 private:
@@ -587,6 +594,8 @@ public:
 
   StructFieldType *clone () const;
 
+  bool is_concrete () const { return ty->is_concrete (); }
+
   void debug () const { rust_debug ("%s", as_string ().c_str ()); }
 
 private:
@@ -717,6 +726,8 @@ public:
     return var.get_tyty ();
   }
 
+  bool need_substitution () const;
+
 private:
   const HIR::TypeParam &generic;
   ParamType *param;
@@ -750,8 +761,13 @@ public:
 
   bool is_conrete () const
   {
-    return argument != nullptr && argument->get_kind () != TyTy::TypeKind::ERROR
-	   && argument->get_kind () != TyTy::TypeKind::PARAM;
+    if (argument != nullptr)
+      return true;
+
+    if (argument->get_kind () == TyTy::TypeKind::PARAM)
+      return false;
+
+    return argument->is_concrete ();
   }
 
   std::string as_string () const
@@ -905,16 +921,12 @@ public:
 
   bool needs_substitution () const
   {
-    if (!has_substitutions ())
-      return false;
-
-    if (used_arguments.is_error ())
-      return true;
-
-    if (used_arguments.size () != get_num_substitutions ())
-      return true;
-
-    return !used_arguments.is_concrete ();
+    for (auto &sub : substitutions)
+      {
+	if (sub.need_substitution ())
+	  return true;
+      }
+    return false;
   }
 
   bool was_substituted () const { return !needs_substitution (); }
@@ -1224,6 +1236,19 @@ public:
     return identifier + subst_as_string ();
   }
 
+  bool is_concrete () const override final
+  {
+    for (auto &variant : variants)
+      {
+	for (auto &field : variant->get_fields ())
+	  {
+	    if (!field->is_concrete ())
+	      return false;
+	  }
+      }
+    return true;
+  }
+
   BaseType *clone () const final override;
 
   bool needs_generic_substitutions () const override final
@@ -1356,6 +1381,17 @@ public:
     return param_at (0).second;
   }
 
+  bool is_concrete () const override final
+  {
+    for (const auto &param : params)
+      {
+	const BaseType *p = param.second;
+	if (!p->is_concrete ())
+	  return false;
+      }
+    return get_return_type ()->is_concrete ();
+  }
+
   std::vector<std::pair<HIR::Pattern *, BaseType *>> &get_params ()
   {
     return params;
@@ -1453,6 +1489,16 @@ public:
       }
   }
 
+  bool is_concrete () const override final
+  {
+    for (auto &p : params)
+      {
+	if (!p.get_tyty ()->is_concrete ())
+	  return false;
+      }
+    return result_type.get_tyty ()->is_concrete ();
+  }
+
 private:
   std::vector<TyVar> params;
   TyVar result_type;
@@ -1505,6 +1551,17 @@ public:
 
   BaseType *clone () const final override;
 
+  bool is_concrete () const override final
+  {
+    for (auto &param : parameter_types)
+      {
+	auto p = param.get_tyty ();
+	if (!p->is_concrete ())
+	  return false;
+      }
+    return result_type.get_tyty ()->is_concrete ();
+  }
+
   bool needs_generic_substitutions () const override final
   {
     return needs_substitution ();
@@ -1598,6 +1655,7 @@ public:
   BaseType *cast (BaseType *other) override;
 
   BaseType *clone () const final override;
+  bool is_concrete () const override final { return true; }
 };
 
 class IntType : public BaseType
@@ -1639,6 +1697,7 @@ public:
   BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
+  bool is_concrete () const override final { return true; }
 
 private:
   IntKind int_kind;
@@ -1683,6 +1742,7 @@ public:
   BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
+  bool is_concrete () const override final { return true; }
 
 private:
   UintKind uint_kind;
@@ -1725,6 +1785,7 @@ public:
   BaseType *clone () const final override;
 
   bool is_equal (const BaseType &other) const override;
+  bool is_concrete () const override final { return true; }
 
 private:
   FloatKind float_kind;
@@ -1755,6 +1816,7 @@ public:
   BaseType *cast (BaseType *other) override;
 
   BaseType *clone () const final override;
+  bool is_concrete () const override final { return true; }
 };
 
 class ISizeType : public BaseType
@@ -1782,6 +1844,7 @@ public:
   BaseType *cast (BaseType *other) override;
 
   BaseType *clone () const final override;
+  bool is_concrete () const override final { return true; }
 };
 
 class CharType : public BaseType
@@ -1809,6 +1872,7 @@ public:
   BaseType *cast (BaseType *other) override;
 
   BaseType *clone () const final override;
+  bool is_concrete () const override final { return true; }
 };
 
 class ReferenceType : public BaseType
@@ -1848,6 +1912,11 @@ public:
     return get_base ()->contains_type_parameters ();
   }
 
+  bool is_concrete () const override final
+  {
+    return !contains_type_parameters ();
+  }
+
   ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings);
 
   Mutability mutability () const { return mut; }
@@ -1896,6 +1965,11 @@ public:
     return get_base ()->contains_type_parameters ();
   }
 
+  bool is_concrete () const override final
+  {
+    return !contains_type_parameters ();
+  }
+
   PointerType *handle_substitions (SubstitutionArgumentMappings mappings);
 
   Mutability mutability () const { return mut; }
@@ -1936,6 +2010,7 @@ public:
   bool is_equal (const BaseType &other) const override;
 
   BaseType *clone () const final override;
+  bool is_concrete () const override final { return true; }
 };
 
 // https://doc.rust-lang.org/std/primitive.never.html
@@ -1975,6 +2050,7 @@ public:
   std::string get_name () const override final { return as_string (); }
 
   bool is_unit () const override { return true; }
+  bool is_concrete () const override final { return true; }
 };
 
 // used at the type in associated types in traits
@@ -2034,6 +2110,11 @@ public:
     return resolve ()->contains_type_parameters ();
   }
 
+  bool is_concrete () const override final
+  {
+    return !contains_type_parameters ();
+  }
+
 private:
   std::string symbol;
 };
@@ -2099,6 +2180,11 @@ public:
     return base->contains_type_parameters ();
   }
 
+  bool is_concrete () const override final
+  {
+    return !contains_type_parameters ();
+  }
+
   ProjectionType *
   handle_substitions (SubstitutionArgumentMappings mappings) override final;
 
@@ -2139,6 +2225,8 @@ public:
 
   std::string get_name () const override final;
 
+  bool is_concrete () const override final { return true; }
+
   // this returns a flat list of items including super trait bounds
   const std::vector<const Resolver::TraitItemReference *>
   get_object_items () const;


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

only message in thread, other threads:[~2022-06-08 11:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:48 [gcc/devel/rust/master] Enforce the is_concrete inferface to start cleaning up the needs_substitution helpers 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).