aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-03-10 18:13:01 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-03-17 10:34:36 +0000
commit01c741adc217fe270239ce2543e119f5f96d241d (patch)
tree33ec6a4c8e896d99ba7fe89ca8f66833c0877324 /gcc
parentbab564903706658ce8fa3704b656eeb1dce53330 (diff)
downloadgcc-01c741adc217fe270239ce2543e119f5f96d241d.zip
gcc-01c741adc217fe270239ce2543e119f5f96d241d.tar.gz
gcc-01c741adc217fe270239ce2543e119f5f96d241d.tar.bz2
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 <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-path.cc6
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc6
-rw-r--r--gcc/rust/typecheck/rust-tyty-subst.cc2
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc37
-rw-r--r--gcc/rust/typecheck/rust-tyty.h18
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 9d9b294..04d507a 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::<ty>
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::<ty>
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 a91d15c..971038c 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::<ty>
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<HIR::TypePathSegmentGeneric *> (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<HIR::TypePathSegmentGeneric *> (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 d2f6cf6..5892c15 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 90d227c..c6db0a8 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -258,35 +258,17 @@ BaseType::append_reference (HirId 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);
@@ -3379,12 +3359,6 @@ ProjectionType::needs_generic_substitutions () const
}
bool
-ProjectionType::supports_substitutions () const
-{
- return true;
-}
-
-bool
ProjectionType::has_subsititions_defined () const
{
return has_substitutions ();
@@ -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 dfc02a9..05b5099 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<HirId> 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;