diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-11 12:55:30 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-03-17 10:34:36 +0000 |
commit | 35da2edceb744c679b920af34ab98708ac444582 (patch) | |
tree | 5027387b9a5bcf2fda9acdda83d4106e3dc86cee | |
parent | 01c741adc217fe270239ce2543e119f5f96d241d (diff) | |
download | gcc-35da2edceb744c679b920af34ab98708ac444582.zip gcc-35da2edceb744c679b920af34ab98708ac444582.tar.gz gcc-35da2edceb744c679b920af34ab98708ac444582.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 147 | ||||
-rw-r--r-- | 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 c6db0a8..2fe6803 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 05b5099..e4c714f 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 (); |