aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-02-27 17:05:13 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-02-28 20:38:35 +0000
commit0632bfbf63449ed4d963d3a29aff1deb0b07e65f (patch)
treeb076365a6432bccdcbd22ae4fb3ab34238bbc0a8
parentea139aa3818bf07f3ad565dd00889f4caa171c14 (diff)
downloadgcc-0632bfbf63449ed4d963d3a29aff1deb0b07e65f.zip
gcc-0632bfbf63449ed4d963d3a29aff1deb0b07e65f.tar.gz
gcc-0632bfbf63449ed4d963d3a29aff1deb0b07e65f.tar.bz2
gccrs: autoderef unconstify so we can use in non const contexts
Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * backend/rust-compile-base.h: unconsify * backend/rust-compile.cc (HIRCompileBase::coercion_site): likewise (HIRCompileBase::coercion_site1): likewise * typecheck/rust-autoderef.cc (Adjuster::try_deref_type): likewise (Adjuster::try_raw_deref_type): likewise (Adjuster::try_unsize_type): likewise (AutoderefCycle::cycle): likewise (AutoderefCycle::try_autoderefed): likewise * typecheck/rust-autoderef.h: likewise * typecheck/rust-coercion.cc (TypeCoercionRules::select): likewise * typecheck/rust-coercion.h: likewise * typecheck/rust-hir-dot-operator.cc (MethodResolver::Probe): likewise (MethodResolver::select): likewise * typecheck/rust-hir-dot-operator.h: likewise
-rw-r--r--gcc/rust/backend/rust-compile-base.h8
-rw-r--r--gcc/rust/backend/rust-compile.cc17
-rw-r--r--gcc/rust/typecheck/rust-autoderef.cc16
-rw-r--r--gcc/rust/typecheck/rust-autoderef.h32
-rw-r--r--gcc/rust/typecheck/rust-coercion.cc2
-rw-r--r--gcc/rust/typecheck/rust-coercion.h2
-rw-r--r--gcc/rust/typecheck/rust-hir-dot-operator.cc4
-rw-r--r--gcc/rust/typecheck/rust-hir-dot-operator.h5
8 files changed, 42 insertions, 44 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 4f039d2..a8f8f2d 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -40,11 +40,11 @@ protected:
protected:
Context *get_context () { return ctx; }
- tree coercion_site (HirId id, tree rvalue, const TyTy::BaseType *actual,
- const TyTy::BaseType *expected, Location lvalue_locus,
+ tree coercion_site (HirId id, tree rvalue, TyTy::BaseType *actual,
+ TyTy::BaseType *expected, Location lvalue_locus,
Location rvalue_locus);
- tree coercion_site1 (tree rvalue, const TyTy::BaseType *actual,
- const TyTy::BaseType *expected, Location lvalue_locus,
+ tree coercion_site1 (tree rvalue, TyTy::BaseType *actual,
+ TyTy::BaseType *expected, Location lvalue_locus,
Location rvalue_locus);
tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index db08b3d..3217901 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -54,10 +54,9 @@ CompileCrate::go ()
// Shared methods in compilation
tree
-HIRCompileBase::coercion_site (HirId id, tree rvalue,
- const TyTy::BaseType *rval,
- const TyTy::BaseType *lval,
- Location lvalue_locus, Location rvalue_locus)
+HIRCompileBase::coercion_site (HirId id, tree rvalue, TyTy::BaseType *rval,
+ TyTy::BaseType *lval, Location lvalue_locus,
+ Location rvalue_locus)
{
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (id, &adjustments);
@@ -70,15 +69,15 @@ HIRCompileBase::coercion_site (HirId id, tree rvalue,
}
tree
-HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval,
- const TyTy::BaseType *lval,
- Location lvalue_locus, Location rvalue_locus)
+HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval,
+ TyTy::BaseType *lval, Location lvalue_locus,
+ Location rvalue_locus)
{
if (rvalue == error_mark_node)
return error_mark_node;
- const TyTy::BaseType *actual = rval->destructure ();
- const TyTy::BaseType *expected = lval->destructure ();
+ TyTy::BaseType *actual = rval->destructure ();
+ TyTy::BaseType *expected = lval->destructure ();
if (expected->get_kind () == TyTy::TypeKind::REF)
{
diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc
index 658ddd7..b2cddb3 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -26,7 +26,7 @@ namespace Resolver {
static bool
resolve_operator_overload_fn (
- Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
+ Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
Adjustment::AdjustmentType *requires_ref_adjustment);
@@ -40,7 +40,7 @@ Adjuster::adjust_type (const std::vector<Adjustment> &adjustments)
}
Adjustment
-Adjuster::try_deref_type (const TyTy::BaseType *ty,
+Adjuster::try_deref_type (TyTy::BaseType *ty,
Analysis::RustLangItem::ItemType deref_lang_item)
{
HIR::ImplItem *impl_item = nullptr;
@@ -85,7 +85,7 @@ Adjuster::try_deref_type (const TyTy::BaseType *ty,
}
Adjustment
-Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
+Adjuster::try_raw_deref_type (TyTy::BaseType *ty)
{
bool is_valid_type = ty->get_kind () == TyTy::TypeKind::REF;
if (!is_valid_type)
@@ -99,7 +99,7 @@ Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
}
Adjustment
-Adjuster::try_unsize_type (const TyTy::BaseType *ty)
+Adjuster::try_unsize_type (TyTy::BaseType *ty)
{
bool is_valid_type = ty->get_kind () == TyTy::TypeKind::ARRAY;
if (!is_valid_type)
@@ -121,7 +121,7 @@ Adjuster::try_unsize_type (const TyTy::BaseType *ty)
static bool
resolve_operator_overload_fn (
- Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
+ Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
Adjustment::AdjustmentType *requires_ref_adjustment)
{
@@ -292,9 +292,9 @@ AutoderefCycle::try_hook (const TyTy::BaseType &)
{}
bool
-AutoderefCycle::cycle (const TyTy::BaseType *receiver)
+AutoderefCycle::cycle (TyTy::BaseType *receiver)
{
- const TyTy::BaseType *r = receiver;
+ TyTy::BaseType *r = receiver;
while (true)
{
rust_debug ("autoderef try 1: {%s}", r->debug_str ().c_str ());
@@ -382,7 +382,7 @@ AutoderefCycle::cycle (const TyTy::BaseType *receiver)
}
bool
-AutoderefCycle::try_autoderefed (const TyTy::BaseType *r)
+AutoderefCycle::try_autoderefed (TyTy::BaseType *r)
{
try_hook (*r);
diff --git a/gcc/rust/typecheck/rust-autoderef.h b/gcc/rust/typecheck/rust-autoderef.h
index 5f05c04..1d5dacf 100644
--- a/gcc/rust/typecheck/rust-autoderef.h
+++ b/gcc/rust/typecheck/rust-autoderef.h
@@ -40,15 +40,15 @@ public:
};
// ctor for all adjustments except derefs
- Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
- const TyTy::BaseType *expected)
+ Adjustment (AdjustmentType type, TyTy::BaseType *actual,
+ TyTy::BaseType *expected)
: Adjustment (type, actual, expected, nullptr, nullptr,
AdjustmentType::ERROR)
{}
static Adjustment get_op_overload_deref_adjustment (
- AdjustmentType type, const TyTy::BaseType *actual,
- const TyTy::BaseType *expected, TyTy::FnType *fn, HIR::ImplItem *deref_item,
+ AdjustmentType type, TyTy::BaseType *actual, TyTy::BaseType *expected,
+ TyTy::FnType *fn, HIR::ImplItem *deref_item,
Adjustment::AdjustmentType requires_ref_adjustment)
{
rust_assert (type == DEREF || type == DEREF_MUT);
@@ -58,8 +58,8 @@ public:
AdjustmentType get_type () const { return type; }
- const TyTy::BaseType *get_actual () const { return actual; }
- const TyTy::BaseType *get_expected () const { return expected; }
+ TyTy::BaseType *get_actual () const { return actual; }
+ TyTy::BaseType *get_expected () const { return expected; }
std::string as_string () const
{
@@ -110,8 +110,8 @@ public:
HIR::ImplItem *get_deref_hir_item () const { return deref_item; }
private:
- Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
- const TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
+ Adjustment (AdjustmentType type, TyTy::BaseType *actual,
+ TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
HIR::ImplItem *deref_item,
Adjustment::AdjustmentType requires_ref_adjustment)
: type (type), actual (actual), expected (expected),
@@ -120,8 +120,8 @@ private:
{}
AdjustmentType type;
- const TyTy::BaseType *actual;
- const TyTy::BaseType *expected;
+ TyTy::BaseType *actual;
+ TyTy::BaseType *expected;
// - only used for deref operator_overloads
//
@@ -140,12 +140,12 @@ public:
TyTy::BaseType *adjust_type (const std::vector<Adjustment> &adjustments);
static Adjustment
- try_deref_type (const TyTy::BaseType *ty,
+ try_deref_type (TyTy::BaseType *ty,
Analysis::RustLangItem::ItemType deref_lang_item);
- static Adjustment try_raw_deref_type (const TyTy::BaseType *ty);
+ static Adjustment try_raw_deref_type (TyTy::BaseType *ty);
- static Adjustment try_unsize_type (const TyTy::BaseType *ty);
+ static Adjustment try_unsize_type (TyTy::BaseType *ty);
private:
const TyTy::BaseType *base;
@@ -158,15 +158,15 @@ protected:
virtual ~AutoderefCycle ();
- virtual bool select (const TyTy::BaseType &autoderefed) = 0;
+ virtual bool select (TyTy::BaseType &autoderefed) = 0;
// optional: this is a chance to hook in to grab predicate items on the raw
// type
virtual void try_hook (const TyTy::BaseType &);
- virtual bool cycle (const TyTy::BaseType *receiver);
+ virtual bool cycle (TyTy::BaseType *receiver);
- bool try_autoderefed (const TyTy::BaseType *r);
+ bool try_autoderefed (TyTy::BaseType *r);
bool autoderef_flag;
std::vector<Adjustment> adjustments;
diff --git a/gcc/rust/typecheck/rust-coercion.cc b/gcc/rust/typecheck/rust-coercion.cc
index 7a3f51a..c07ee73 100644
--- a/gcc/rust/typecheck/rust-coercion.cc
+++ b/gcc/rust/typecheck/rust-coercion.cc
@@ -373,7 +373,7 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
}
bool
-TypeCoercionRules::select (const TyTy::BaseType &autoderefed)
+TypeCoercionRules::select (TyTy::BaseType &autoderefed)
{
rust_debug (
"autoderef type-coercion select autoderefed={%s} can_eq expected={%s}",
diff --git a/gcc/rust/typecheck/rust-coercion.h b/gcc/rust/typecheck/rust-coercion.h
index 69442e5..0a55b85 100644
--- a/gcc/rust/typecheck/rust-coercion.h
+++ b/gcc/rust/typecheck/rust-coercion.h
@@ -71,7 +71,7 @@ protected:
TypeCoercionRules (TyTy::BaseType *expected, Location locus, bool emit_errors,
bool allow_autoderef);
- bool select (const TyTy::BaseType &autoderefed) override;
+ bool select (TyTy::BaseType &autoderefed) override;
bool do_coercion (TyTy::BaseType *receiver);
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index 84fa8d4..4a291e1 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -29,7 +29,7 @@ MethodResolver::MethodResolver (bool autoderef_flag,
{}
std::set<MethodCandidate>
-MethodResolver::Probe (const TyTy::BaseType *receiver,
+MethodResolver::Probe (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &segment_name,
bool autoderef_flag)
{
@@ -46,7 +46,7 @@ MethodResolver::try_hook (const TyTy::BaseType &r)
}
bool
-MethodResolver::select (const TyTy::BaseType &receiver)
+MethodResolver::select (TyTy::BaseType &receiver)
{
struct impl_item_candidate
{
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.h b/gcc/rust/typecheck/rust-hir-dot-operator.h
index e14baf3..75927ff 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.h
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.h
@@ -54,8 +54,7 @@ public:
};
static std::set<MethodCandidate>
- Probe (const TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &segment_name,
+ Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
bool autoderef_flag = false);
static std::vector<predicate_candidate> get_predicate_items (
@@ -68,7 +67,7 @@ protected:
void try_hook (const TyTy::BaseType &r) override;
- bool select (const TyTy::BaseType &receiver) override;
+ bool select (TyTy::BaseType &receiver) override;
private:
// search