aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.h8
-rw-r--r--gcc/rust/backend/rust-compile-context.h53
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h9
-rw-r--r--gcc/rust/backend/rust-compile.cc19
-rw-r--r--gcc/rust/typecheck/rust-autoderef.h6
-rw-r--r--gcc/rust/typecheck/rust-hir-dot-operator.h9
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h7
-rw-r--r--gcc/rust/typecheck/rust-substitution-mapper.h50
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc12
-rw-r--r--gcc/rust/typecheck/rust-tyty.h15
10 files changed, 96 insertions, 92 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 4a81061..d741598 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -205,14 +205,14 @@ protected:
TyTy::BaseType *expected, Location locus);
Bexpression *coerce_to_dyn_object (Bexpression *compiled_ref,
- TyTy::BaseType *actual,
- TyTy::BaseType *expected,
- TyTy::DynamicObjectType *ty,
+ const TyTy::BaseType *actual,
+ const TyTy::BaseType *expected,
+ const TyTy::DynamicObjectType *ty,
Location locus);
Bexpression *
compute_address_for_trait_item (const Resolver::TraitItemReference *ref,
- TyTy::BaseType *receiver);
+ const TyTy::BaseType *receiver);
};
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 0da2198..fd2c0b5 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -340,10 +340,10 @@ private:
std::vector<::Bfunction *> func_decls;
};
-class TyTyResolveCompile : public TyTy::TyVisitor
+class TyTyResolveCompile : public TyTy::TyConstVisitor
{
public:
- static ::Btype *compile (Context *ctx, TyTy::BaseType *ty,
+ static ::Btype *compile (Context *ctx, const TyTy::BaseType *ty,
bool trait_object_mode = false)
{
TyTyResolveCompile compiler (ctx, trait_object_mode);
@@ -351,26 +351,25 @@ public:
return compiler.translated;
}
- void visit (TyTy::ErrorType &) override { gcc_unreachable (); }
+ void visit (const TyTy::ErrorType &) override { gcc_unreachable (); }
+ void visit (const TyTy::InferType &) override { gcc_unreachable (); }
- void visit (TyTy::InferType &) override { gcc_unreachable (); }
-
- void visit (TyTy::ProjectionType &type) override
+ void visit (const TyTy::ProjectionType &type) override
{
type.get ()->accept_vis (*this);
}
- void visit (TyTy::PlaceholderType &type) override
+ void visit (const TyTy::PlaceholderType &type) override
{
type.resolve ()->accept_vis (*this);
}
- void visit (TyTy::ParamType &param) override
+ void visit (const TyTy::ParamType &param) override
{
param.resolve ()->accept_vis (*this);
}
- void visit (TyTy::FnType &type) override
+ void visit (const TyTy::FnType &type) override
{
Backend::Btyped_identifier receiver;
std::vector<Backend::Btyped_identifier> parameters;
@@ -409,7 +408,7 @@ public:
ctx->get_mappings ()->lookup_location (type.get_ref ()));
}
- void visit (TyTy::FnPtr &type) override
+ void visit (const TyTy::FnPtr &type) override
{
Btype *result_type
= TyTyResolveCompile::compile (ctx, type.get_return_type ());
@@ -426,7 +425,7 @@ public:
ctx->get_mappings ()->lookup_location (type.get_ref ()));
}
- void visit (TyTy::ADTType &type) override
+ void visit (const TyTy::ADTType &type) override
{
if (ctx->lookup_compiled_types (type.get_ty_ref (), &translated, &type))
return;
@@ -434,7 +433,7 @@ public:
std::vector<Backend::Btyped_identifier> fields;
for (size_t i = 0; i < type.num_fields (); i++)
{
- TyTy::StructFieldType *field = type.get_field (i);
+ const TyTy::StructFieldType *field = type.get_field (i);
Btype *compiled_field_ty
= TyTyResolveCompile::compile (ctx, field->get_field_type ());
@@ -460,7 +459,7 @@ public:
ctx->insert_compiled_type (type.get_ty_ref (), named_struct, &type);
}
- void visit (TyTy::TupleType &type) override
+ void visit (const TyTy::TupleType &type) override
{
if (type.num_fields () == 0)
{
@@ -504,7 +503,7 @@ public:
translated = named_struct;
}
- void visit (TyTy::ArrayType &type) override
+ void visit (const TyTy::ArrayType &type) override
{
Btype *element_type
= TyTyResolveCompile::compile (ctx, type.get_element_type ());
@@ -512,7 +511,7 @@ public:
= ctx->get_backend ()->array_type (element_type, type.get_capacity ());
}
- void visit (TyTy::BoolType &type) override
+ void visit (const TyTy::BoolType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -520,7 +519,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::IntType &type) override
+ void visit (const TyTy::IntType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -528,7 +527,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::UintType &type) override
+ void visit (const TyTy::UintType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -536,7 +535,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::FloatType &type) override
+ void visit (const TyTy::FloatType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -544,7 +543,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::USizeType &type) override
+ void visit (const TyTy::USizeType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -552,7 +551,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::ISizeType &type) override
+ void visit (const TyTy::ISizeType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -560,7 +559,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::CharType &type) override
+ void visit (const TyTy::CharType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -568,7 +567,7 @@ public:
translated = compiled_type;
}
- void visit (TyTy::ReferenceType &type) override
+ void visit (const TyTy::ReferenceType &type) override
{
Btype *base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
@@ -583,7 +582,7 @@ public:
}
}
- void visit (TyTy::PointerType &type) override
+ void visit (const TyTy::PointerType &type) override
{
Btype *base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
@@ -598,7 +597,7 @@ public:
}
}
- void visit (TyTy::StrType &type) override
+ void visit (const TyTy::StrType &type) override
{
::Btype *compiled_type = nullptr;
bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
@@ -606,12 +605,12 @@ public:
translated = compiled_type;
}
- void visit (TyTy::NeverType &) override
+ void visit (const TyTy::NeverType &) override
{
translated = ctx->get_backend ()->unit_type ();
}
- void visit (TyTy::DynamicObjectType &type) override
+ void visit (const TyTy::DynamicObjectType &type) override
{
if (trait_object_mode)
{
@@ -661,7 +660,7 @@ public:
ctx->insert_compiled_type (type.get_ty_ref (), named_struct, &type);
}
- void visit (TyTy::ClosureType &type) override { gcc_unreachable (); }
+ void visit (const TyTy::ClosureType &type) override { gcc_unreachable (); }
private:
TyTyResolveCompile (Context *ctx, bool trait_object_mode)
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 1d3ad02..ace5e4c 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -34,7 +34,7 @@ class CompileInherentImplItem : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (TyTy::BaseType *self, HIR::ImplItem *item,
+ static Bexpression *Compile (const TyTy::BaseType *self, HIR::ImplItem *item,
Context *ctx, bool compile_fns,
TyTy::BaseType *concrete = nullptr,
bool is_query_mode = false,
@@ -309,14 +309,15 @@ public:
}
private:
- CompileInherentImplItem (TyTy::BaseType *self, Context *ctx, bool compile_fns,
- TyTy::BaseType *concrete, Location ref_locus)
+ CompileInherentImplItem (const TyTy::BaseType *self, Context *ctx,
+ bool compile_fns, TyTy::BaseType *concrete,
+ Location ref_locus)
: HIRCompileBase (ctx), self (self), compile_fns (compile_fns),
concrete (concrete), reference (ctx->get_backend ()->error_expression ()),
ref_locus (ref_locus)
{}
- TyTy::BaseType *self;
+ const TyTy::BaseType *self;
bool compile_fns;
TyTy::BaseType *concrete;
Bexpression *reference;
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 23a035f..56d3e40 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -234,8 +234,8 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
if (is_dyn_dispatch)
{
- TyTy::DynamicObjectType *dyn
- = static_cast<TyTy::DynamicObjectType *> (receiver->get_root ());
+ const TyTy::DynamicObjectType *dyn
+ = static_cast<const TyTy::DynamicObjectType *> (receiver->get_root ());
size_t offs = 0;
const Resolver::TraitItemReference *ref = nullptr;
@@ -763,8 +763,8 @@ HIRCompileBase::coercion_site (Bexpression *compiled_ref,
if (root_expected_kind == TyTy::TypeKind::DYNAMIC
&& root_actual_kind != TyTy::TypeKind::DYNAMIC)
{
- TyTy::DynamicObjectType *dyn
- = static_cast<TyTy::DynamicObjectType *> (expected->get_root ());
+ const TyTy::DynamicObjectType *dyn
+ = static_cast<const TyTy::DynamicObjectType *> (expected->get_root ());
return coerce_to_dyn_object (compiled_ref, actual, expected, dyn, locus);
}
@@ -773,9 +773,9 @@ HIRCompileBase::coercion_site (Bexpression *compiled_ref,
Bexpression *
HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
- TyTy::BaseType *actual,
- TyTy::BaseType *expected,
- TyTy::DynamicObjectType *ty,
+ const TyTy::BaseType *actual,
+ const TyTy::BaseType *expected,
+ const TyTy::DynamicObjectType *ty,
Location locus)
{
Btype *dynamic_object = TyTyResolveCompile::compile (ctx, ty);
@@ -814,7 +814,7 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
std::vector<Resolver::Adjustment> adjustments;
while (e->get_kind () == TyTy::TypeKind::REF)
{
- auto r = static_cast<TyTy::ReferenceType *> (e);
+ auto r = static_cast<const TyTy::ReferenceType *> (e);
e = r->get_base ();
if (r->is_mutable ())
@@ -845,7 +845,8 @@ HIRCompileBase::coerce_to_dyn_object (Bexpression *compiled_ref,
Bexpression *
HIRCompileBase::compute_address_for_trait_item (
- const Resolver::TraitItemReference *trait_item_ref, TyTy::BaseType *receiver)
+ const Resolver::TraitItemReference *trait_item_ref,
+ const TyTy::BaseType *receiver)
{
TyTy::BaseType *item_type = trait_item_ref->get_tyty ();
rust_assert (item_type->get_kind () == TyTy::TypeKind::FNDEF);
diff --git a/gcc/rust/typecheck/rust-autoderef.h b/gcc/rust/typecheck/rust-autoderef.h
index 7a9083d..3604910 100644
--- a/gcc/rust/typecheck/rust-autoderef.h
+++ b/gcc/rust/typecheck/rust-autoderef.h
@@ -34,13 +34,13 @@ public:
DEREF_REF
};
- Adjustment (AdjustmentType type, TyTy::BaseType *expected)
+ Adjustment (AdjustmentType type, const TyTy::BaseType *expected)
: type (type), expected (expected)
{}
AdjustmentType get_type () const { return type; }
- TyTy::BaseType *get_expected () const { return expected; }
+ const TyTy::BaseType *get_expected () const { return expected; }
std::string as_string () const
{
@@ -65,7 +65,7 @@ public:
private:
AdjustmentType type;
- TyTy::BaseType *expected;
+ const TyTy::BaseType *expected;
};
} // namespace Resolver
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.h b/gcc/rust/typecheck/rust-hir-dot-operator.h
index 279e67f..9c0cc43 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.h
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.h
@@ -35,10 +35,10 @@ class MethodResolution
{
public:
static PathProbeCandidate *
- Select (std::vector<PathProbeCandidate> &candidates, TyTy::BaseType *receiver,
- std::vector<Adjustment> &adjustments)
+ Select (std::vector<PathProbeCandidate> &candidates,
+ const TyTy::BaseType *receiver, std::vector<Adjustment> &adjustments)
{
- TyTy::BaseType *r = receiver;
+ const TyTy::BaseType *r = receiver;
while (true)
{
PathProbeCandidate *c = nullptr;
@@ -80,7 +80,8 @@ public:
// FIXME this needs to use deref trait and fall back to unsized to
// remove array syntax
- TyTy::ReferenceType *rr = static_cast<TyTy::ReferenceType *> (r);
+ const TyTy::ReferenceType *rr
+ = static_cast<const TyTy::ReferenceType *> (r);
r = rr->get_base ();
adjustments.push_back (
Adjustment (Adjustment::AdjustmentType::DEREF_REF, r));
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index b386763..83fafa6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -219,7 +219,7 @@ public:
// in order to probe of the correct type paths we need the root type, which
// strips any references
- TyTy::BaseType *root = receiver_tyty->get_root ();
+ const TyTy::BaseType *root = receiver_tyty->get_root ();
// https://doc.rust-lang.org/reference/expressions/method-call-expr.html
// method resolution is complex in rust once we start handling generics and
@@ -297,7 +297,7 @@ public:
if (root->get_kind () == TyTy::TypeKind::ADT)
{
- TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (root);
+ const TyTy::ADTType *adt = static_cast<const TyTy::ADTType *> (root);
if (adt->has_substitutions () && fn->needs_substitution ())
{
// consider the case where we have:
@@ -322,7 +322,8 @@ public:
auto s = fn->get_self_type ()->get_root ();
rust_assert (s->can_eq (adt, false));
rust_assert (s->get_kind () == TyTy::TypeKind::ADT);
- TyTy::ADTType *self_adt = static_cast<TyTy::ADTType *> (s);
+ const TyTy::ADTType *self_adt
+ = static_cast<const TyTy::ADTType *> (s);
// we need to grab the Self substitutions as the inherit type
// parameters for this
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index a6e7e80..b7c23fb 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -317,51 +317,51 @@ private:
TyTy::BaseType *resolved;
};
-class GetUsedSubstArgs : public TyTy::TyVisitor
+class GetUsedSubstArgs : public TyTy::TyConstVisitor
{
public:
- static TyTy::SubstitutionArgumentMappings From (TyTy::BaseType *from)
+ static TyTy::SubstitutionArgumentMappings From (const TyTy::BaseType *from)
{
GetUsedSubstArgs mapper;
from->accept_vis (mapper);
return mapper.args;
}
- void visit (TyTy::FnType &type) override
+ void visit (const TyTy::FnType &type) override
{
args = type.get_substitution_arguments ();
}
- void visit (TyTy::ADTType &type) override
+ void visit (const TyTy::ADTType &type) override
{
args = type.get_substitution_arguments ();
}
- void visit (TyTy::ClosureType &type) override
+ void visit (const TyTy::ClosureType &type) override
{
args = type.get_substitution_arguments ();
}
- void visit (TyTy::InferType &) override {}
- void visit (TyTy::TupleType &) override {}
- void visit (TyTy::FnPtr &) override {}
- void visit (TyTy::ArrayType &) override {}
- void visit (TyTy::BoolType &) override {}
- void visit (TyTy::IntType &) override {}
- void visit (TyTy::UintType &) override {}
- void visit (TyTy::FloatType &) override {}
- void visit (TyTy::USizeType &) override {}
- void visit (TyTy::ISizeType &) override {}
- void visit (TyTy::ErrorType &) override {}
- void visit (TyTy::CharType &) override {}
- void visit (TyTy::ReferenceType &) override {}
- void visit (TyTy::PointerType &) override {}
- void visit (TyTy::ParamType &) override {}
- void visit (TyTy::StrType &) override {}
- void visit (TyTy::NeverType &) override {}
- void visit (TyTy::PlaceholderType &) override {}
- void visit (TyTy::ProjectionType &) override {}
- void visit (TyTy::DynamicObjectType &) override {}
+ void visit (const TyTy::InferType &) override {}
+ void visit (const TyTy::TupleType &) override {}
+ void visit (const TyTy::FnPtr &) override {}
+ void visit (const TyTy::ArrayType &) override {}
+ void visit (const TyTy::BoolType &) override {}
+ void visit (const TyTy::IntType &) override {}
+ void visit (const TyTy::UintType &) override {}
+ void visit (const TyTy::FloatType &) override {}
+ void visit (const TyTy::USizeType &) override {}
+ void visit (const TyTy::ISizeType &) override {}
+ void visit (const TyTy::ErrorType &) override {}
+ void visit (const TyTy::CharType &) override {}
+ void visit (const TyTy::ReferenceType &) override {}
+ void visit (const TyTy::PointerType &) override {}
+ void visit (const TyTy::ParamType &) override {}
+ void visit (const TyTy::StrType &) override {}
+ void visit (const TyTy::NeverType &) override {}
+ void visit (const TyTy::PlaceholderType &) override {}
+ void visit (const TyTy::ProjectionType &) override {}
+ void visit (const TyTy::DynamicObjectType &) override {}
private:
GetUsedSubstArgs () : args (TyTy::SubstitutionArgumentMappings::error ()) {}
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index f08d8cb..969360e 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -114,13 +114,13 @@ BaseType::inherit_bounds (
}
}
-BaseType *
-BaseType::get_root ()
+const BaseType *
+BaseType::get_root () const
{
- BaseType *root = this;
+ const BaseType *root = this;
while (root->get_kind () == TyTy::REF)
{
- ReferenceType *r = static_cast<ReferenceType *> (root);
+ const ReferenceType *r = static_cast<const ReferenceType *> (root);
root = r->get_base ();
}
return root;
@@ -480,14 +480,14 @@ SubstitutionRef::adjust_mappings_for_this (
// this new substitution reference so ordering matters here
SubstitutionArgumentMappings
SubstitutionRef::solve_mappings_from_receiver_for_self (
- SubstitutionArgumentMappings &mappings)
+ SubstitutionArgumentMappings &mappings) const
{
std::vector<SubstitutionArg> resolved_mappings;
rust_assert (mappings.size () == get_num_substitutions ());
for (size_t i = 0; i < get_num_substitutions (); i++)
{
- SubstitutionParamMapping &param_mapping = substitutions.at (i);
+ const SubstitutionParamMapping &param_mapping = substitutions.at (i);
SubstitutionArg &arg = mappings.get_mappings ().at (i);
if (param_mapping.needs_substitution ())
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 8ab120e..f726069 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -337,7 +337,7 @@ public:
debug_str ().c_str ());
}
- BaseType *get_root ();
+ const BaseType *get_root () const;
protected:
BaseType (HirId ref, HirId ty_ref, TypeKind kind,
@@ -690,7 +690,7 @@ private:
class SubstitutionArg
{
public:
- SubstitutionArg (SubstitutionParamMapping *param, BaseType *argument)
+ SubstitutionArg (const SubstitutionParamMapping *param, BaseType *argument)
: param (std::move (param)), argument (argument)
{}
@@ -707,7 +707,7 @@ public:
BaseType *get_tyty () { return argument; }
- SubstitutionParamMapping *get_param_mapping () { return param; }
+ const SubstitutionParamMapping *get_param_mapping () { return param; }
static SubstitutionArg error () { return SubstitutionArg (nullptr, nullptr); }
@@ -725,7 +725,7 @@ public:
}
private:
- SubstitutionParamMapping *param;
+ const SubstitutionParamMapping *param;
BaseType *argument;
};
@@ -761,7 +761,7 @@ public:
{
for (auto &mapping : mappings)
{
- SubstitutionParamMapping *param = mapping.get_param_mapping ();
+ const SubstitutionParamMapping *param = mapping.get_param_mapping ();
const ParamType *p = param->get_param_ty ();
if (p->get_symbol ().compare (param_to_find->get_symbol ()) == 0)
@@ -884,7 +884,7 @@ public:
bool was_substituted () const { return !needs_substitution (); }
- SubstitutionArgumentMappings get_substitution_arguments ()
+ SubstitutionArgumentMappings get_substitution_arguments () const
{
return used_arguments;
}
@@ -943,7 +943,7 @@ public:
// we need to figure out relevant generic arguemts for self to apply to the
// fntype
SubstitutionArgumentMappings solve_mappings_from_receiver_for_self (
- SubstitutionArgumentMappings &mappings);
+ SubstitutionArgumentMappings &mappings) const;
BaseType *infer_substitions (Location locus)
{
@@ -1893,6 +1893,7 @@ public:
return has_substitutions ();
}
+ const BaseType *get () const { return base; }
BaseType *get () { return base; }
bool contains_type_parameters () const override