public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: get rid of virtual dispatch for substitution proxys
@ 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:35da2edceb744c679b920af34ab98708ac444582
commit 35da2edceb744c679b920af34ab98708ac444582
Author: Philip Herron <herron.philip@googlemail.com>
Date: Sat Mar 11 12:55:30 2023 +0000
gccrs: get rid of virtual dispatch for substitution proxys
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>
Diff:
---
gcc/rust/typecheck/rust-tyty.cc | 147 +++++++++++++++++++++++++++++++++-------
gcc/rust/typecheck/rust-tyty.h | 41 +----------
2 files changed, 126 insertions(+), 62 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index c6db0a8907a..2fe6803d027 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -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 ()
{
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 05b50991f41..e4c714f03f3 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -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 ();
^ 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: get rid of virtual dispatch for substitution proxys 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).