From 7ec57f2e7c79a5a99bef7613e6c9b957711a887e Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 10 Mar 2023 18:13:01 +0000 Subject: [PATCH] gccrs: tyty get rid of useless virtuals This removes can_substitute and contains_type_parameters which were confusing interfaces to act as a proxy to the SubstitionRef types. This replaces them with a single base implementation which is much easier to debug and follow. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): update to use new interface (TypeCheckExpr::resolve_root_path): likewise (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise (TypeCheckType::resolve_root_path): likewise * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): likewise * typecheck/rust-tyty.cc (BaseType::supports_substitutions): likewise (BaseType::can_substitute): remove (BaseType::contains_type_parameters): remove (handle_substitions): cleanup (TupleType::handle_substitions): update (FnType::handle_substitions): update (ProjectionType::supports_substitutions): update * typecheck/rust-tyty.h: update header Signed-off-by: Philip Herron --- .../typecheck/rust-hir-type-check-path.cc | 6 +-- .../typecheck/rust-hir-type-check-type.cc | 6 +-- gcc/rust/typecheck/rust-tyty-subst.cc | 2 +- gcc/rust/typecheck/rust-tyty.cc | 37 +++---------------- gcc/rust/typecheck/rust-tyty.h | 18 --------- 5 files changed, 12 insertions(+), 57 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 292dcd648356..ef77c5dbc4f1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -110,7 +110,7 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) // turbo-fish segment path:: if (item_seg.has_generic_args ()) { - if (!infered->can_substitute ()) + if (!infered->has_subsititions_defined ()) { rust_error_at (item_seg.get_locus (), "substitutions not supported for %s", @@ -269,7 +269,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, // turbo-fish segment path:: if (seg.has_generic_args ()) { - if (!lookup->can_substitute ()) + if (!lookup->has_subsititions_defined ()) { rust_error_at (expr.get_locus (), "substitutions not supported for %s", @@ -437,7 +437,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, if (seg.has_generic_args ()) { - if (!tyseg->can_substitute ()) + if (!tyseg->has_subsititions_defined ()) { rust_error_at (expr_locus, "substitutions not supported for %s", tyseg->as_string ().c_str ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 4a7f03708e39..4da3aa0dd044 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -242,7 +242,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) // turbo-fish segment path:: if (generic_seg.has_generic_args ()) { - if (!translated->can_substitute ()) + if (!translated->has_subsititions_defined ()) { rust_error_at (item_seg->get_locus (), "substitutions not supported for %s", @@ -386,7 +386,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, HIR::TypePathSegmentGeneric *generic_segment = static_cast (seg.get ()); - if (!lookup->can_substitute ()) + if (!lookup->has_subsititions_defined ()) { rust_error_at (path.get_locus (), "TypePath %s declares generic arguments but the " @@ -482,7 +482,7 @@ TypeCheckType::resolve_segments ( HIR::TypePathSegmentGeneric *generic_segment = static_cast (seg.get ()); - if (!tyseg->can_substitute ()) + if (!tyseg->has_subsititions_defined ()) { rust_error_at (expr_locus, "substitutions not supported for %s", tyseg->as_string ().c_str ()); diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 6e4c28a572f0..5ff76411ab91 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -648,7 +648,7 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) return SubstitutionArgumentMappings::error (); // this resolved default might already contain default parameters - if (resolved->contains_type_parameters ()) + if (!resolved->is_concrete ()) { SubstitutionArgumentMappings intermediate (mappings, binding_arguments, diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 84533072a746..651becb8457c 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -257,36 +257,18 @@ BaseType::append_reference (HirId id) combined.insert (id); } -bool -BaseType::supports_substitutions () const -{ - return false; -} - bool BaseType::has_subsititions_defined () const { return false; } -bool -BaseType::can_substitute () const -{ - return supports_substitutions () && has_subsititions_defined (); -} - bool BaseType::needs_generic_substitutions () const { return false; } -bool -BaseType::contains_type_parameters () const -{ - return !is_concrete (); -} - const RustIdent & BaseType::get_ident () const { @@ -1446,7 +1428,7 @@ handle_substitions (SubstitutionArgumentMappings &subst_mappings, } } } - else if (fty->has_subsititions_defined () || fty->contains_type_parameters ()) + else if (fty->has_subsititions_defined () || !fty->is_concrete ()) { BaseType *concrete = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); @@ -1629,7 +1611,7 @@ TupleType::handle_substitions (SubstitutionArgumentMappings &mappings) for (size_t i = 0; i < tuple->fields.size (); i++) { TyVar &field = fields.at (i); - if (field.get_tyty ()->contains_type_parameters ()) + if (!field.get_tyty ()->is_concrete ()) { BaseType *concrete = Resolver::SubstMapperInternal::Resolve (field.get_tyty (), @@ -1783,8 +1765,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) } } } - else if (fty->needs_generic_substitutions () - || fty->contains_type_parameters ()) + else if (fty->needs_generic_substitutions () || !fty->is_concrete ()) { BaseType *concrete = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); @@ -1831,8 +1812,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) } } } - else if (fty->has_subsititions_defined () - || fty->contains_type_parameters ()) + else if (fty->has_subsititions_defined () || !fty->is_concrete ()) { BaseType *concrete = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); @@ -3378,12 +3358,6 @@ ProjectionType::needs_generic_substitutions () const return needs_substitution (); } -bool -ProjectionType::supports_substitutions () const -{ - return true; -} - bool ProjectionType::has_subsititions_defined () const { @@ -3486,8 +3460,7 @@ ProjectionType::handle_substitions ( } } } - else if (fty->needs_generic_substitutions () - || fty->contains_type_parameters ()) + else if (fty->needs_generic_substitutions () || !fty->is_concrete ()) { BaseType *concrete = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 0f261b3bdc58..24ec47ef261c 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -137,17 +137,10 @@ public: // get_combined_refs returns the chain of node refs involved in unification std::set get_combined_refs () const; - void append_reference (HirId id); - bool can_substitute () const; - - bool contains_type_parameters () const; - std::string mappings_str () const; - std::string debug_str () const; - void debug () const; // FIXME this will eventually go away @@ -159,15 +152,12 @@ public: const BaseType *destructure () const; const RustIdent &get_ident () const; - Location get_locus () 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 supports_substitutions () const; - virtual bool has_subsititions_defined () const; virtual bool needs_generic_substitutions () const; @@ -577,8 +567,6 @@ public: return needs_substitution (); } - bool supports_substitutions () const override final { return true; } - bool has_subsititions_defined () const override final { return has_substitutions (); @@ -735,8 +723,6 @@ public: return needs_substitution (); } - bool supports_substitutions () const override final { return true; } - bool has_subsititions_defined () const override final { return has_substitutions (); @@ -858,8 +844,6 @@ public: return needs_substitution (); } - bool supports_substitutions () const override final { return true; } - bool has_subsititions_defined () const override final { return has_substitutions (); @@ -1330,8 +1314,6 @@ public: bool needs_generic_substitutions () const override final; - bool supports_substitutions () const override final; - bool has_subsititions_defined () const override final; const BaseType *get () const; -- 2.47.2