aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc147
-rw-r--r--gcc/rust/typecheck/rust-tyty.h41
2 files changed, 126 insertions, 62 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 651becb..508940e 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 24ec47e..8fd680d 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 ();