gccrs: Refactor handle_substitutions to take a reference

This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc: refactor to take a reference
	* typecheck/rust-tyty-subst.cc: likewise
	(SubstitutionRef::get_substitution_arguments): likewise
	(SubstitutionRef::infer_substitions): likewise
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
	(TupleType::handle_substitions): likewise
	(FnType::handle_substitions): likewise
	(ClosureType::handle_substitions): likewise
	(ArrayType::handle_substitions): likewise
	(SliceType::handle_substitions): likewise
	(ReferenceType::handle_substitions): likewise
	(PointerType::handle_substitions): likewise
	(ParamType::handle_substitions): likewise
	(ProjectionType::handle_substitions): likewise
	* typecheck/rust-tyty.h: likewise
This commit is contained in:
Philip Herron
2023-01-27 18:28:06 +00:00
committed by Arthur Cohen
parent 1019fd6337
commit dcb2e571ac
5 changed files with 34 additions and 26 deletions

View File

@@ -444,7 +444,7 @@ TypeBoundPredicate::is_error () const
BaseType *
TypeBoundPredicate::handle_substitions (
SubstitutionArgumentMappings subst_mappings)
SubstitutionArgumentMappings &subst_mappings)
{
for (auto &sub : get_substs ())
{

View File

@@ -488,7 +488,13 @@ SubstitutionRef::was_substituted () const
return !needs_substitution ();
}
SubstitutionArgumentMappings
SubstitutionArgumentMappings &
SubstitutionRef::get_substitution_arguments ()
{
return used_arguments;
}
const SubstitutionArgumentMappings &
SubstitutionRef::get_substitution_arguments () const
{
return used_arguments;
@@ -697,7 +703,7 @@ SubstitutionRef::infer_substitions (Location locus)
SubstitutionArgumentMappings infer_arguments (std::move (args),
{} /* binding_arguments */,
locus);
return handle_substitions (std::move (infer_arguments));
return handle_substitions (infer_arguments);
}
SubstitutionArgumentMappings

View File

@@ -199,7 +199,8 @@ public:
bool was_substituted () const;
SubstitutionArgumentMappings get_substitution_arguments () const;
SubstitutionArgumentMappings &get_substitution_arguments ();
const SubstitutionArgumentMappings &get_substitution_arguments () const;
// this is the count of type params that are not substituted fuly
size_t num_required_substitutions () const;
@@ -301,7 +302,7 @@ public:
bool monomorphize ();
// TODO comment
virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings)
virtual BaseType *handle_substitions (SubstitutionArgumentMappings &mappings)
= 0;
SubstitutionArgumentMappings get_used_arguments () const;

View File

@@ -1148,7 +1148,7 @@ handle_substitions (SubstitutionArgumentMappings &subst_mappings,
}
ADTType *
ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
{
ADTType *adt = static_cast<ADTType *> (clone ());
adt->set_ty_ref (mappings->get_next_hir_id ());
@@ -1333,7 +1333,7 @@ TupleType::monomorphized_clone () const
}
TupleType *
TupleType::handle_substitions (SubstitutionArgumentMappings mappings)
TupleType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
auto mappings_table = Analysis::Mappings::get ();
@@ -1474,7 +1474,7 @@ FnType::monomorphized_clone () const
}
FnType *
FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
{
FnType *fn = static_cast<FnType *> (clone ());
fn->set_ty_ref (mappings->get_next_hir_id ());
@@ -1742,7 +1742,7 @@ ClosureType::monomorphized_clone () const
}
ClosureType *
ClosureType::handle_substitions (SubstitutionArgumentMappings mappings)
ClosureType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
gcc_unreachable ();
return nullptr;
@@ -1862,7 +1862,7 @@ ArrayType::monomorphized_clone () const
}
ArrayType *
ArrayType::handle_substitions (SubstitutionArgumentMappings mappings)
ArrayType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
auto mappings_table = Analysis::Mappings::get ();
@@ -1945,7 +1945,7 @@ SliceType::monomorphized_clone () const
}
SliceType *
SliceType::handle_substitions (SubstitutionArgumentMappings mappings)
SliceType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
auto mappings_table = Analysis::Mappings::get ();
@@ -2704,7 +2704,7 @@ ReferenceType::monomorphized_clone () const
}
ReferenceType *
ReferenceType::handle_substitions (SubstitutionArgumentMappings mappings)
ReferenceType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
auto mappings_table = Analysis::Mappings::get ();
@@ -2870,7 +2870,7 @@ PointerType::monomorphized_clone () const
}
PointerType *
PointerType::handle_substitions (SubstitutionArgumentMappings mappings)
PointerType::handle_substitions (SubstitutionArgumentMappings &mappings)
{
auto mappings_table = Analysis::Mappings::get ();
@@ -3047,7 +3047,7 @@ ParamType::is_equal (const BaseType &other) const
}
ParamType *
ParamType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
{
SubstitutionArg arg = SubstitutionArg::error ();
bool ok = subst_mappings.get_argument_for_symbol (this, &arg);
@@ -3492,7 +3492,8 @@ ProjectionType::monomorphized_clone () const
}
ProjectionType *
ProjectionType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
ProjectionType::handle_substitions (
SubstitutionArgumentMappings &subst_mappings)
{
// // do we really need to substitute this?
// if (base->needs_generic_substitutions () || base->contains_type_parameters

View File

@@ -304,7 +304,7 @@ public:
bool is_concrete () const override final;
ParamType *handle_substitions (SubstitutionArgumentMappings mappings);
ParamType *handle_substitions (SubstitutionArgumentMappings &mappings);
private:
std::string symbol;
@@ -379,7 +379,7 @@ public:
std::string get_name () const override final;
TupleType *handle_substitions (SubstitutionArgumentMappings mappings);
TupleType *handle_substitions (SubstitutionArgumentMappings &mappings);
private:
std::vector<TyVar> fields;
@@ -427,7 +427,7 @@ public:
// WARNING THIS WILL ALWAYS RETURN NULLPTR
BaseType *
handle_substitions (SubstitutionArgumentMappings mappings) override final;
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
bool is_error () const;
@@ -682,7 +682,7 @@ public:
}
ADTType *
handle_substitions (SubstitutionArgumentMappings mappings) override final;
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
private:
std::string identifier;
@@ -815,7 +815,7 @@ public:
}
FnType *
handle_substitions (SubstitutionArgumentMappings mappings) override final;
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
ABI get_abi () const { return abi; }
@@ -965,7 +965,7 @@ public:
}
ClosureType *
handle_substitions (SubstitutionArgumentMappings mappings) override final;
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
TyTy::TupleType &get_parameters () const { return *parameters; }
TyTy::BaseType &get_result_type () const { return *result_type.get_tyty (); }
@@ -1024,7 +1024,7 @@ public:
HIR::Expr &get_capacity_expr () const { return capacity_expr; }
ArrayType *handle_substitions (SubstitutionArgumentMappings mappings);
ArrayType *handle_substitions (SubstitutionArgumentMappings &mappings);
private:
TyVar element_type;
@@ -1070,7 +1070,7 @@ public:
return get_element_type ()->is_concrete ();
}
SliceType *handle_substitions (SubstitutionArgumentMappings mappings);
SliceType *handle_substitions (SubstitutionArgumentMappings &mappings);
private:
TyVar element_type;
@@ -1321,7 +1321,7 @@ public:
bool is_concrete () const override final;
ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings);
ReferenceType *handle_substitions (SubstitutionArgumentMappings &mappings);
Mutability mutability () const;
@@ -1364,7 +1364,7 @@ public:
bool is_concrete () const override final;
PointerType *handle_substitions (SubstitutionArgumentMappings mappings);
PointerType *handle_substitions (SubstitutionArgumentMappings &mappings);
Mutability mutability () const;
bool is_mutable () const;
@@ -1500,7 +1500,7 @@ public:
bool is_concrete () const override final;
ProjectionType *
handle_substitions (SubstitutionArgumentMappings mappings) override final;
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
private:
BaseType *base;