]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: get rid of virtual dispatch for substitution proxys
authorPhilip Herron <herron.philip@googlemail.com>
Sat, 11 Mar 2023 12:55:30 +0000 (12:55 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:21:11 +0000 (18:21 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::has_subsititions_defined): new implementation
(BaseType::needs_generic_substitutions): likewise
(ProjectionType::needs_generic_substitutions): remove
(ProjectionType::has_subsititions_defined): remove
* typecheck/rust-tyty.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h

index 651becb8457c2638809c0f4fd5db260d82db8d75..508940e5480c3771fd7a6d5ba6cad8b0c16e13bd 100644 (file)
@@ -257,18 +257,6 @@ BaseType::append_reference (HirId id)
   combined.insert (id);
 }
 
-bool
-BaseType::has_subsititions_defined () const
-{
-  return false;
-}
-
-bool
-BaseType::needs_generic_substitutions () const
-{
-  return false;
-}
-
 const RustIdent &
 BaseType::get_ident () const
 {
@@ -821,6 +809,128 @@ BaseType::is_concrete () const
   return false;
 }
 
+bool
+BaseType::has_subsititions_defined () const
+{
+  const TyTy::BaseType *x = destructure ();
+  switch (x->get_kind ())
+    {
+    case INFER:
+    case BOOL:
+    case CHAR:
+    case INT:
+    case UINT:
+    case FLOAT:
+    case USIZE:
+    case ISIZE:
+    case NEVER:
+    case STR:
+    case DYNAMIC:
+    case ERROR:
+    case FNPTR:
+    case ARRAY:
+    case SLICE:
+    case POINTER:
+    case REF:
+    case TUPLE:
+    case PARAM:
+    case PLACEHOLDER:
+      return false;
+
+      case PROJECTION: {
+       const ProjectionType &p = *static_cast<const ProjectionType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (p);
+       return ref.has_substitutions ();
+      }
+      break;
+
+      case FNDEF: {
+       const FnType &fn = *static_cast<const FnType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (fn);
+       return ref.has_substitutions ();
+      }
+      break;
+
+      case ADT: {
+       const ADTType &adt = *static_cast<const ADTType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (adt);
+       return ref.has_substitutions ();
+      }
+      break;
+
+      case CLOSURE: {
+       const ClosureType &closure = *static_cast<const ClosureType *> (x);
+       const SubstitutionRef &ref
+         = static_cast<const SubstitutionRef &> (closure);
+       return ref.has_substitutions ();
+      }
+      break;
+    }
+
+  return false;
+}
+
+bool
+BaseType::needs_generic_substitutions () const
+{
+  const TyTy::BaseType *x = destructure ();
+  switch (x->get_kind ())
+    {
+    case INFER:
+    case BOOL:
+    case CHAR:
+    case INT:
+    case UINT:
+    case FLOAT:
+    case USIZE:
+    case ISIZE:
+    case NEVER:
+    case STR:
+    case DYNAMIC:
+    case ERROR:
+    case FNPTR:
+    case ARRAY:
+    case SLICE:
+    case POINTER:
+    case REF:
+    case TUPLE:
+    case PARAM:
+    case PLACEHOLDER:
+      return false;
+
+      case PROJECTION: {
+       const ProjectionType &p = *static_cast<const ProjectionType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (p);
+       return ref.needs_substitution ();
+      }
+      break;
+
+      case FNDEF: {
+       const FnType &fn = *static_cast<const FnType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (fn);
+       return ref.needs_substitution ();
+      }
+      break;
+
+      case ADT: {
+       const ADTType &adt = *static_cast<const ADTType *> (x);
+       const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (adt);
+       return ref.needs_substitution ();
+      }
+      break;
+
+      case CLOSURE: {
+       const ClosureType &closure = *static_cast<const ClosureType *> (x);
+       const SubstitutionRef &ref
+         = static_cast<const SubstitutionRef &> (closure);
+       return ref.needs_substitution ();
+      }
+      break;
+    }
+
+  return false;
+}
+
 // InferType
 
 InferType::InferType (HirId ref, InferTypeKind infer_kind, Location locus,
@@ -3352,23 +3462,12 @@ ProjectionType::get_name () const
   return as_string ();
 }
 
-bool
-ProjectionType::needs_generic_substitutions () const
-{
-  return needs_substitution ();
-}
-
-bool
-ProjectionType::has_subsititions_defined () const
-{
-  return has_substitutions ();
-}
-
 const BaseType *
 ProjectionType::get () const
 {
   return base;
 }
+
 BaseType *
 ProjectionType::get ()
 {
index 24ec47ef261c30596c7aeeb8bd64b91d7c95895a..8fd680d8d81025a50bd9545b3e49e534c7cbb80e 100644 (file)
@@ -154,14 +154,13 @@ public:
   const RustIdent &get_ident () const;
   Location get_locus () const;
 
+  bool has_subsititions_defined () const;
+  bool needs_generic_substitutions () const;
+
   /* Returns a pointer to a clone of this. The caller is responsible for
    * releasing the memory of the returned ty. */
   virtual BaseType *clone () const = 0;
 
-  virtual bool has_subsititions_defined () const;
-
-  virtual bool needs_generic_substitutions () const;
-
 protected:
   BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident,
            std::set<HirId> refs = std::set<HirId> ());
@@ -562,16 +561,6 @@ public:
 
   BaseType *clone () const final override;
 
-  bool needs_generic_substitutions () const override final
-  {
-    return needs_substitution ();
-  }
-
-  bool has_subsititions_defined () const override final
-  {
-    return has_substitutions ();
-  }
-
   size_t number_of_variants () const { return variants.size (); }
 
   std::vector<VariantDef *> &get_variants () { return variants; }
@@ -718,16 +707,6 @@ public:
 
   BaseType *clone () const final override;
 
-  bool needs_generic_substitutions () const override final
-  {
-    return needs_substitution ();
-  }
-
-  bool has_subsititions_defined () const override final
-  {
-    return has_substitutions ();
-  }
-
   FnType *
   handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
@@ -839,16 +818,6 @@ public:
 
   BaseType *clone () const final override;
 
-  bool needs_generic_substitutions () const override final
-  {
-    return needs_substitution ();
-  }
-
-  bool has_subsititions_defined () const override final
-  {
-    return has_substitutions ();
-  }
-
   ClosureType *
   handle_substitions (SubstitutionArgumentMappings &mappings) override final;
 
@@ -1312,10 +1281,6 @@ public:
 
   std::string get_name () const override final;
 
-  bool needs_generic_substitutions () const override final;
-
-  bool has_subsititions_defined () const override final;
-
   const BaseType *get () const;
   BaseType *get ();