public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: tyty get rid of useless virtuals
@ 2023-03-20  7:23 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-20  7:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:01c741adc217fe270239ce2543e119f5f96d241d

commit 01c741adc217fe270239ce2543e119f5f96d241d
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Fri Mar 10 18:13:01 2023 +0000

    gccrs: tyty get rid of useless virtuals
    
    This removes can_substitute and contains_type_parameters which were
    confusing interfaces to act as a proxy to the SubstitionRef types. This
    replaces them with a single base implementation which is much easier to
    debug and follow.
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): update to use new interface
            (TypeCheckExpr::resolve_root_path): likewise
            (TypeCheckExpr::resolve_segments): likewise
            * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
            (TypeCheckType::resolve_root_path): likewise
            * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): likewise
            * typecheck/rust-tyty.cc (BaseType::supports_substitutions): likewise
            (BaseType::can_substitute): remove
            (BaseType::contains_type_parameters): remove
            (handle_substitions): cleanup
            (TupleType::handle_substitions): update
            (FnType::handle_substitions): update
            (ProjectionType::supports_substitutions): update
            * typecheck/rust-tyty.h: update header
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc |  6 ++---
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  6 ++---
 gcc/rust/typecheck/rust-tyty-subst.cc          |  2 +-
 gcc/rust/typecheck/rust-tyty.cc                | 37 ++++----------------------
 gcc/rust/typecheck/rust-tyty.h                 | 18 -------------
 5 files changed, 12 insertions(+), 57 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 9d9b2949944..04d507a7446 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -110,7 +110,7 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
   // turbo-fish segment path::<ty>
   if (item_seg.has_generic_args ())
     {
-      if (!infered->can_substitute ())
+      if (!infered->has_subsititions_defined ())
 	{
 	  rust_error_at (item_seg.get_locus (),
 			 "substitutions not supported for %s",
@@ -269,7 +269,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
       // turbo-fish segment path::<ty>
       if (seg.has_generic_args ())
 	{
-	  if (!lookup->can_substitute ())
+	  if (!lookup->has_subsititions_defined ())
 	    {
 	      rust_error_at (expr.get_locus (),
 			     "substitutions not supported for %s",
@@ -437,7 +437,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
 
       if (seg.has_generic_args ())
 	{
-	  if (!tyseg->can_substitute ())
+	  if (!tyseg->has_subsititions_defined ())
 	    {
 	      rust_error_at (expr_locus, "substitutions not supported for %s",
 			     tyseg->as_string ().c_str ());
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index a91d15c8e2c..971038c56f6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -242,7 +242,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
       // turbo-fish segment path::<ty>
       if (generic_seg.has_generic_args ())
 	{
-	  if (!translated->can_substitute ())
+	  if (!translated->has_subsititions_defined ())
 	    {
 	      rust_error_at (item_seg->get_locus (),
 			     "substitutions not supported for %s",
@@ -386,7 +386,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
 	  HIR::TypePathSegmentGeneric *generic_segment
 	    = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ());
 
-	  if (!lookup->can_substitute ())
+	  if (!lookup->has_subsititions_defined ())
 	    {
 	      rust_error_at (path.get_locus (),
 			     "TypePath %s declares generic arguments but the "
@@ -482,7 +482,7 @@ TypeCheckType::resolve_segments (
 	  HIR::TypePathSegmentGeneric *generic_segment
 	    = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ());
 
-	  if (!tyseg->can_substitute ())
+	  if (!tyseg->has_subsititions_defined ())
 	    {
 	      rust_error_at (expr_locus, "substitutions not supported for %s",
 			     tyseg->as_string ().c_str ());
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index d2f6cf607d1..5892c15b2e1 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -648,7 +648,7 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args)
 	    return SubstitutionArgumentMappings::error ();
 
 	  // this resolved default might already contain default parameters
-	  if (resolved->contains_type_parameters ())
+	  if (!resolved->is_concrete ())
 	    {
 	      SubstitutionArgumentMappings intermediate (mappings,
 							 binding_arguments,
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 90d227c577a..c6db0a8907a 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -257,36 +257,18 @@ BaseType::append_reference (HirId id)
   combined.insert (id);
 }
 
-bool
-BaseType::supports_substitutions () const
-{
-  return false;
-}
-
 bool
 BaseType::has_subsititions_defined () const
 {
   return false;
 }
 
-bool
-BaseType::can_substitute () const
-{
-  return supports_substitutions () && has_subsititions_defined ();
-}
-
 bool
 BaseType::needs_generic_substitutions () const
 {
   return false;
 }
 
-bool
-BaseType::contains_type_parameters () const
-{
-  return !is_concrete ();
-}
-
 const RustIdent &
 BaseType::get_ident () const
 {
@@ -1446,7 +1428,7 @@ handle_substitions (SubstitutionArgumentMappings &subst_mappings,
 	    }
 	}
     }
-  else if (fty->has_subsititions_defined () || fty->contains_type_parameters ())
+  else if (fty->has_subsititions_defined () || !fty->is_concrete ())
     {
       BaseType *concrete
 	= Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
@@ -1629,7 +1611,7 @@ TupleType::handle_substitions (SubstitutionArgumentMappings &mappings)
   for (size_t i = 0; i < tuple->fields.size (); i++)
     {
       TyVar &field = fields.at (i);
-      if (field.get_tyty ()->contains_type_parameters ())
+      if (!field.get_tyty ()->is_concrete ())
 	{
 	  BaseType *concrete
 	    = Resolver::SubstMapperInternal::Resolve (field.get_tyty (),
@@ -1783,8 +1765,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 	    }
 	}
     }
-  else if (fty->needs_generic_substitutions ()
-	   || fty->contains_type_parameters ())
+  else if (fty->needs_generic_substitutions () || !fty->is_concrete ())
     {
       BaseType *concrete
 	= Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
@@ -1831,8 +1812,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 		}
 	    }
 	}
-      else if (fty->has_subsititions_defined ()
-	       || fty->contains_type_parameters ())
+      else if (fty->has_subsititions_defined () || !fty->is_concrete ())
 	{
 	  BaseType *concrete
 	    = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
@@ -3378,12 +3358,6 @@ ProjectionType::needs_generic_substitutions () const
   return needs_substitution ();
 }
 
-bool
-ProjectionType::supports_substitutions () const
-{
-  return true;
-}
-
 bool
 ProjectionType::has_subsititions_defined () const
 {
@@ -3486,8 +3460,7 @@ ProjectionType::handle_substitions (
 	    }
 	}
     }
-  else if (fty->needs_generic_substitutions ()
-	   || fty->contains_type_parameters ())
+  else if (fty->needs_generic_substitutions () || !fty->is_concrete ())
     {
       BaseType *concrete
 	= Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index dfc02a91126..05b50991f41 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -137,17 +137,10 @@ public:
 
   // get_combined_refs returns the chain of node refs involved in unification
   std::set<HirId> get_combined_refs () const;
-
   void append_reference (HirId id);
 
-  bool can_substitute () const;
-
-  bool contains_type_parameters () const;
-
   std::string mappings_str () const;
-
   std::string debug_str () const;
-
   void debug () const;
 
   // FIXME this will eventually go away
@@ -159,15 +152,12 @@ public:
   const BaseType *destructure () const;
 
   const RustIdent &get_ident () const;
-
   Location get_locus () 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 supports_substitutions () const;
-
   virtual bool has_subsititions_defined () const;
 
   virtual bool needs_generic_substitutions () const;
@@ -577,8 +567,6 @@ public:
     return needs_substitution ();
   }
 
-  bool supports_substitutions () const override final { return true; }
-
   bool has_subsititions_defined () const override final
   {
     return has_substitutions ();
@@ -735,8 +723,6 @@ public:
     return needs_substitution ();
   }
 
-  bool supports_substitutions () const override final { return true; }
-
   bool has_subsititions_defined () const override final
   {
     return has_substitutions ();
@@ -858,8 +844,6 @@ public:
     return needs_substitution ();
   }
 
-  bool supports_substitutions () const override final { return true; }
-
   bool has_subsititions_defined () const override final
   {
     return has_substitutions ();
@@ -1330,8 +1314,6 @@ public:
 
   bool needs_generic_substitutions () const override final;
 
-  bool supports_substitutions () const override final;
-
   bool has_subsititions_defined () const override final;
 
   const BaseType *get () const;

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

only message in thread, other threads:[~2023-03-20  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20  7:23 [gcc/devel/rust/master] gccrs: tyty get rid of useless virtuals 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).