public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] Refactor TypeBoundPredicate to be below the definition for SubstitutionRef
Date: Wed,  8 Jun 2022 12:19:25 +0000 (GMT)	[thread overview]
Message-ID: <20220608121925.B476A3852765@sourceware.org> (raw)

https://gcc.gnu.org/g:9411c061aaeae0be39c678e0885472c37b112141

commit 9411c061aaeae0be39c678e0885472c37b112141
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Mon Mar 14 17:35:57 2022 +0000

    Refactor TypeBoundPredicate to be below the definition for SubstitutionRef
    
    This means TypeBoundPredicate will now be able to inherit all behaviours
    of normal generics so we do not duplicate the work in handling generics
    it will also allow us to more easily check for unconstrained type
    parameters on traits.

Diff:
---
 gcc/rust/typecheck/rust-tyty-bounds.cc |  54 ++++++++++++++
 gcc/rust/typecheck/rust-tyty.h         | 124 +++++++++++++--------------------
 2 files changed, 103 insertions(+), 75 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 1d1c481ce73..bc1e76ef69f 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -67,6 +67,10 @@ TypeCheckBase::resolve_trait_path (HIR::TypePath &path)
 
 namespace TyTy {
 
+TypeBoundPredicate::TypeBoundPredicate (DefId reference, Location locus)
+  : reference (reference), locus (locus), args (nullptr)
+{}
+
 std::string
 TypeBoundPredicate::as_string () const
 {
@@ -192,5 +196,55 @@ TypeBoundPredicateItem::needs_implementation () const
   return !get_raw_item ()->is_optional ();
 }
 
+// TypeBoundsMappings
+
+TypeBoundsMappings::TypeBoundsMappings (
+  std::vector<TypeBoundPredicate> specified_bounds)
+  : specified_bounds (specified_bounds)
+{}
+
+std::vector<TypeBoundPredicate> &
+TypeBoundsMappings::get_specified_bounds ()
+{
+  return specified_bounds;
+}
+
+const std::vector<TypeBoundPredicate> &
+TypeBoundsMappings::get_specified_bounds () const
+{
+  return specified_bounds;
+}
+
+size_t
+TypeBoundsMappings::num_specified_bounds () const
+{
+  return specified_bounds.size ();
+}
+
+std::string
+TypeBoundsMappings::raw_bounds_as_string () const
+{
+  std::string buf;
+  for (size_t i = 0; i < specified_bounds.size (); i++)
+    {
+      const TypeBoundPredicate &b = specified_bounds.at (i);
+      bool has_next = (i + 1) < specified_bounds.size ();
+      buf += b.get_name () + (has_next ? " + " : "");
+    }
+  return buf;
+}
+
+std::string
+TypeBoundsMappings::bounds_as_string () const
+{
+  return "bounds:[" + raw_bounds_as_string () + "]";
+}
+
+void
+TypeBoundsMappings::add_bound (TypeBoundPredicate predicate)
+{
+  specified_bounds.push_back (predicate);
+}
+
 } // namespace TyTy
 } // namespace Rust
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 82262abab09..d1c2170ba34 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -108,92 +108,24 @@ private:
   const Resolver::TraitItemReference *trait_item_ref;
 };
 
-class TypeBoundPredicate
-{
-public:
-  TypeBoundPredicate (DefId reference, Location locus)
-    : reference (reference), locus (locus), args (nullptr)
-  {}
-
-  std::string as_string () const;
-
-  const Resolver::TraitReference *get () const;
-
-  Location get_locus () const { return locus; }
-
-  std::string get_name () const;
-
-  // check that this predicate is object-safe see:
-  // https://doc.rust-lang.org/reference/items/traits.html#object-safety
-  bool is_object_safe (bool emit_error, Location locus) const;
-
-  void apply_generic_arguments (HIR::GenericArgs *generic_args);
-
-  bool contains_item (const std::string &search) const;
-
-  TypeBoundPredicateItem
-  lookup_associated_item (const std::string &search) const;
-
-  HIR::GenericArgs *get_generic_args () { return args; }
-
-  const HIR::GenericArgs *get_generic_args () const { return args; }
-
-  bool has_generic_args () const
-  {
-    if (args == nullptr)
-      return false;
-
-    return args->has_generic_args ();
-  }
-
-private:
-  DefId reference;
-  Location locus;
-  HIR::GenericArgs *args;
-};
-
 class TypeBoundsMappings
 {
 protected:
-  TypeBoundsMappings (std::vector<TypeBoundPredicate> specified_bounds)
-    : specified_bounds (specified_bounds)
-  {}
+  TypeBoundsMappings (std::vector<TypeBoundPredicate> specified_bounds);
 
 public:
-  std::vector<TypeBoundPredicate> &get_specified_bounds ()
-  {
-    return specified_bounds;
-  }
+  std::vector<TypeBoundPredicate> &get_specified_bounds ();
 
-  const std::vector<TypeBoundPredicate> &get_specified_bounds () const
-  {
-    return specified_bounds;
-  }
+  const std::vector<TypeBoundPredicate> &get_specified_bounds () const;
 
-  size_t num_specified_bounds () const { return specified_bounds.size (); }
+  size_t num_specified_bounds () const;
 
-  std::string raw_bounds_as_string () const
-  {
-    std::string buf;
-    for (size_t i = 0; i < specified_bounds.size (); i++)
-      {
-	const TypeBoundPredicate &b = specified_bounds.at (i);
-	bool has_next = (i + 1) < specified_bounds.size ();
-	buf += b.get_name () + (has_next ? " + " : "");
-      }
-    return buf;
-  }
+  std::string raw_bounds_as_string () const;
 
-  std::string bounds_as_string () const
-  {
-    return "bounds:[" + raw_bounds_as_string () + "]";
-  }
+  std::string bounds_as_string () const;
 
 protected:
-  void add_bound (TypeBoundPredicate predicate)
-  {
-    specified_bounds.push_back (predicate);
-  }
+  void add_bound (TypeBoundPredicate predicate);
 
   std::vector<TypeBoundPredicate> specified_bounds;
 };
@@ -1007,6 +939,48 @@ protected:
   SubstitutionArgumentMappings used_arguments;
 };
 
+class TypeBoundPredicate
+{
+public:
+  TypeBoundPredicate (DefId reference, Location locus);
+
+  std::string as_string () const;
+
+  const Resolver::TraitReference *get () const;
+
+  Location get_locus () const { return locus; }
+
+  std::string get_name () const;
+
+  // check that this predicate is object-safe see:
+  // https://doc.rust-lang.org/reference/items/traits.html#object-safety
+  bool is_object_safe (bool emit_error, Location locus) const;
+
+  void apply_generic_arguments (HIR::GenericArgs *generic_args);
+
+  bool contains_item (const std::string &search) const;
+
+  TypeBoundPredicateItem
+  lookup_associated_item (const std::string &search) const;
+
+  HIR::GenericArgs *get_generic_args () { return args; }
+
+  const HIR::GenericArgs *get_generic_args () const { return args; }
+
+  bool has_generic_args () const
+  {
+    if (args == nullptr)
+      return false;
+
+    return args->has_generic_args ();
+  }
+
+private:
+  DefId reference;
+  Location locus;
+  HIR::GenericArgs *args;
+};
+
 // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.VariantDef.html
 class VariantDef
 {


                 reply	other threads:[~2022-06-08 12:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608121925.B476A3852765@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).