public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: refactor TyTy::BaseType::is_unit to not use virtual dispatch
@ 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:712aa0027c6fa6ea06560f0a797208bab19fbb24
commit 712aa0027c6fa6ea06560f0a797208bab19fbb24
Author: Philip Herron <herron.philip@googlemail.com>
Date: Fri Mar 10 14:31:50 2023 +0000
gccrs: refactor TyTy::BaseType::is_unit to not use virtual dispatch
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (BaseType::is_unit): new implementation
(ErrorType::is_unit): remove
(TupleType::is_unit): likewise
(NeverType::is_unit): likewise
(PlaceholderType::is_unit): likewise
(ProjectionType::is_unit): likewise
* typecheck/rust-tyty.h: update header
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-tyty.cc | 81 +++++++++++++++++++++++++----------------
gcc/rust/typecheck/rust-tyty.h | 34 +++--------------
2 files changed, 55 insertions(+), 60 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 3e399fd862e..dbd4b5c7ae4 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -188,6 +188,56 @@ BaseType::is_equal (const BaseType &other) const
bool
BaseType::is_unit () const
{
+ const TyTy::BaseType *x = destructure ();
+ switch (x->get_kind ())
+ {
+ case PARAM:
+ case PROJECTION:
+ case PLACEHOLDER:
+ case FNPTR:
+ case FNDEF:
+ case ARRAY:
+ case SLICE:
+ case POINTER:
+ case REF:
+ case CLOSURE:
+ case INFER:
+ case BOOL:
+ case CHAR:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case USIZE:
+ case ISIZE:
+
+ case STR:
+ case DYNAMIC:
+ case ERROR:
+ return false;
+
+ // FIXME ! is coerceable to () so we need to fix that
+ case NEVER:
+ return true;
+
+ case TUPLE: {
+ const TupleType &tuple = *static_cast<const TupleType *> (x);
+ return tuple.num_fields () == 0;
+ }
+
+ case ADT: {
+ const ADTType &adt = *static_cast<const ADTType *> (x);
+ if (adt.is_enum ())
+ return false;
+
+ for (const auto &variant : adt.get_variants ())
+ {
+ if (variant->num_fields () > 0)
+ return false;
+ }
+
+ return true;
+ }
+ }
return false;
}
@@ -813,12 +863,6 @@ ErrorType::ErrorType (HirId ref, HirId ty_ref, std::set<HirId> refs)
{Resolver::CanonicalPath::create_empty (), Location ()}, refs)
{}
-bool
-ErrorType::is_unit () const
-{
- return true;
-}
-
std::string
ErrorType::get_name () const
{
@@ -1388,12 +1432,6 @@ TupleType::get_unit_type (HirId ref)
return new TupleType (ref, Linemap::predeclared_location ());
}
-bool
-TupleType::is_unit () const
-{
- return this->fields.empty ();
-}
-
size_t
TupleType::num_fields () const
{
@@ -3172,12 +3210,6 @@ NeverType::get_name () const
return as_string ();
}
-bool
-NeverType::is_unit () const
-{
- return true;
-}
-
void
NeverType::accept_vis (TyVisitor &vis)
{
@@ -3241,13 +3273,6 @@ PlaceholderType::get_name () const
return as_string ();
}
-bool
-PlaceholderType::is_unit () const
-{
- rust_assert (can_resolve ());
- return resolve ()->is_unit ();
-}
-
std::string
PlaceholderType::get_symbol () const
{
@@ -3371,12 +3396,6 @@ ProjectionType::ProjectionType (
base (base), trait (trait), item (item)
{}
-bool
-ProjectionType::is_unit () const
-{
- return false;
-}
-
std::string
ProjectionType::get_name () const
{
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index d49768eb53d..47f55163277 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -85,19 +85,15 @@ public:
virtual ~BaseType ();
HirId get_ref () const;
-
void set_ref (HirId id);
HirId get_ty_ref () const;
-
void set_ty_ref (HirId id);
virtual void accept_vis (TyVisitor &vis) = 0;
-
virtual void accept_vis (TyConstVisitor &vis) const = 0;
virtual std::string as_string () const = 0;
-
virtual std::string get_name () const = 0;
// similar to unify but does not actually perform type unification but
@@ -119,19 +115,20 @@ public:
virtual bool is_equal (const BaseType &other) const;
bool satisfies_bound (const TypeBoundPredicate &predicate) const;
-
bool bounds_compatible (const BaseType &other, Location locus,
bool emit_error) const;
-
void inherit_bounds (const BaseType &other);
-
void inherit_bounds (
const std::vector<TyTy::TypeBoundPredicate> &specified_bounds);
- virtual bool is_unit () const;
+ // is_unit returns whether this is just a unit-struct
+ bool is_unit () const;
+ // is_concrete returns true if the type is fully resolved to concrete
+ // primitives
bool is_concrete () const;
+ // return the type-kind
TypeKind get_kind () const;
/* Returns a pointer to a clone of this. The caller is responsible for
@@ -238,8 +235,6 @@ public:
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
- bool is_unit () const override;
-
std::string as_string () const override;
bool can_eq (const BaseType *other, bool emit_errors) const override final;
@@ -340,8 +335,6 @@ public:
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
- bool is_unit () const override;
-
std::string as_string () const override;
bool can_eq (const BaseType *other, bool emit_errors) const override final;
@@ -564,17 +557,6 @@ public:
bool is_union () const { return adt_kind == UNION; }
bool is_enum () const { return adt_kind == ENUM; }
- bool is_unit () const override
- {
- if (number_of_variants () == 0)
- return true;
-
- if (number_of_variants () == 1)
- return variants.at (0)->num_fields () == 0;
-
- return false;
- }
-
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
@@ -1297,8 +1279,6 @@ public:
BaseType *monomorphized_clone () const final override;
std::string get_name () const override final;
-
- bool is_unit () const override;
};
// used at the type in associated types in traits
@@ -1323,8 +1303,6 @@ public:
std::string get_name () const override final;
- bool is_unit () const override;
-
std::string get_symbol () const;
void set_associated_type (HirId ref);
@@ -1370,8 +1348,6 @@ public:
std::string get_name () const override final;
- bool is_unit () const override;
-
bool needs_generic_substitutions () const override final;
bool supports_substitutions () const override final;
^ 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: refactor TyTy::BaseType::is_unit to not use virtual dispatch 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).