Skip to content

Commit 0632bfb

Browse files
committed
gccrs: autoderef unconstify so we can use in non const contexts
Signed-off-by: Philip Herron <[email protected]> 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
1 parent ea139aa commit 0632bfb

8 files changed

+42
-44
lines changed

gcc/rust/backend/rust-compile-base.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class HIRCompileBase
4040
protected:
4141
Context *get_context () { return ctx; }
4242

43-
tree coercion_site (HirId id, tree rvalue, const TyTy::BaseType *actual,
44-
const TyTy::BaseType *expected, Location lvalue_locus,
43+
tree coercion_site (HirId id, tree rvalue, TyTy::BaseType *actual,
44+
TyTy::BaseType *expected, Location lvalue_locus,
4545
Location rvalue_locus);
46-
tree coercion_site1 (tree rvalue, const TyTy::BaseType *actual,
47-
const TyTy::BaseType *expected, Location lvalue_locus,
46+
tree coercion_site1 (tree rvalue, TyTy::BaseType *actual,
47+
TyTy::BaseType *expected, Location lvalue_locus,
4848
Location rvalue_locus);
4949

5050
tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,

gcc/rust/backend/rust-compile.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ CompileCrate::go ()
5454
// Shared methods in compilation
5555

5656
tree
57-
HIRCompileBase::coercion_site (HirId id, tree rvalue,
58-
const TyTy::BaseType *rval,
59-
const TyTy::BaseType *lval,
60-
Location lvalue_locus, Location rvalue_locus)
57+
HIRCompileBase::coercion_site (HirId id, tree rvalue, TyTy::BaseType *rval,
58+
TyTy::BaseType *lval, Location lvalue_locus,
59+
Location rvalue_locus)
6160
{
6261
std::vector<Resolver::Adjustment> *adjustments = nullptr;
6362
bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (id, &adjustments);
@@ -70,15 +69,15 @@ HIRCompileBase::coercion_site (HirId id, tree rvalue,
7069
}
7170

7271
tree
73-
HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval,
74-
const TyTy::BaseType *lval,
75-
Location lvalue_locus, Location rvalue_locus)
72+
HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval,
73+
TyTy::BaseType *lval, Location lvalue_locus,
74+
Location rvalue_locus)
7675
{
7776
if (rvalue == error_mark_node)
7877
return error_mark_node;
7978

80-
const TyTy::BaseType *actual = rval->destructure ();
81-
const TyTy::BaseType *expected = lval->destructure ();
79+
TyTy::BaseType *actual = rval->destructure ();
80+
TyTy::BaseType *expected = lval->destructure ();
8281

8382
if (expected->get_kind () == TyTy::TypeKind::REF)
8483
{

gcc/rust/typecheck/rust-autoderef.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Resolver {
2626

2727
static bool
2828
resolve_operator_overload_fn (
29-
Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
29+
Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
3030
TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
3131
Adjustment::AdjustmentType *requires_ref_adjustment);
3232

@@ -40,7 +40,7 @@ Adjuster::adjust_type (const std::vector<Adjustment> &adjustments)
4040
}
4141

4242
Adjustment
43-
Adjuster::try_deref_type (const TyTy::BaseType *ty,
43+
Adjuster::try_deref_type (TyTy::BaseType *ty,
4444
Analysis::RustLangItem::ItemType deref_lang_item)
4545
{
4646
HIR::ImplItem *impl_item = nullptr;
@@ -85,7 +85,7 @@ Adjuster::try_deref_type (const TyTy::BaseType *ty,
8585
}
8686

8787
Adjustment
88-
Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
88+
Adjuster::try_raw_deref_type (TyTy::BaseType *ty)
8989
{
9090
bool is_valid_type = ty->get_kind () == TyTy::TypeKind::REF;
9191
if (!is_valid_type)
@@ -99,7 +99,7 @@ Adjuster::try_raw_deref_type (const TyTy::BaseType *ty)
9999
}
100100

101101
Adjustment
102-
Adjuster::try_unsize_type (const TyTy::BaseType *ty)
102+
Adjuster::try_unsize_type (TyTy::BaseType *ty)
103103
{
104104
bool is_valid_type = ty->get_kind () == TyTy::TypeKind::ARRAY;
105105
if (!is_valid_type)
@@ -121,7 +121,7 @@ Adjuster::try_unsize_type (const TyTy::BaseType *ty)
121121

122122
static bool
123123
resolve_operator_overload_fn (
124-
Analysis::RustLangItem::ItemType lang_item_type, const TyTy::BaseType *ty,
124+
Analysis::RustLangItem::ItemType lang_item_type, TyTy::BaseType *ty,
125125
TyTy::FnType **resolved_fn, HIR::ImplItem **impl_item,
126126
Adjustment::AdjustmentType *requires_ref_adjustment)
127127
{
@@ -292,9 +292,9 @@ AutoderefCycle::try_hook (const TyTy::BaseType &)
292292
{}
293293

294294
bool
295-
AutoderefCycle::cycle (const TyTy::BaseType *receiver)
295+
AutoderefCycle::cycle (TyTy::BaseType *receiver)
296296
{
297-
const TyTy::BaseType *r = receiver;
297+
TyTy::BaseType *r = receiver;
298298
while (true)
299299
{
300300
rust_debug ("autoderef try 1: {%s}", r->debug_str ().c_str ());
@@ -382,7 +382,7 @@ AutoderefCycle::cycle (const TyTy::BaseType *receiver)
382382
}
383383

384384
bool
385-
AutoderefCycle::try_autoderefed (const TyTy::BaseType *r)
385+
AutoderefCycle::try_autoderefed (TyTy::BaseType *r)
386386
{
387387
try_hook (*r);
388388

gcc/rust/typecheck/rust-autoderef.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Adjustment
4040
};
4141

4242
// ctor for all adjustments except derefs
43-
Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
44-
const TyTy::BaseType *expected)
43+
Adjustment (AdjustmentType type, TyTy::BaseType *actual,
44+
TyTy::BaseType *expected)
4545
: Adjustment (type, actual, expected, nullptr, nullptr,
4646
AdjustmentType::ERROR)
4747
{}
4848

4949
static Adjustment get_op_overload_deref_adjustment (
50-
AdjustmentType type, const TyTy::BaseType *actual,
51-
const TyTy::BaseType *expected, TyTy::FnType *fn, HIR::ImplItem *deref_item,
50+
AdjustmentType type, TyTy::BaseType *actual, TyTy::BaseType *expected,
51+
TyTy::FnType *fn, HIR::ImplItem *deref_item,
5252
Adjustment::AdjustmentType requires_ref_adjustment)
5353
{
5454
rust_assert (type == DEREF || type == DEREF_MUT);
@@ -58,8 +58,8 @@ class Adjustment
5858

5959
AdjustmentType get_type () const { return type; }
6060

61-
const TyTy::BaseType *get_actual () const { return actual; }
62-
const TyTy::BaseType *get_expected () const { return expected; }
61+
TyTy::BaseType *get_actual () const { return actual; }
62+
TyTy::BaseType *get_expected () const { return expected; }
6363

6464
std::string as_string () const
6565
{
@@ -110,8 +110,8 @@ class Adjustment
110110
HIR::ImplItem *get_deref_hir_item () const { return deref_item; }
111111

112112
private:
113-
Adjustment (AdjustmentType type, const TyTy::BaseType *actual,
114-
const TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
113+
Adjustment (AdjustmentType type, TyTy::BaseType *actual,
114+
TyTy::BaseType *expected, TyTy::FnType *deref_operator_fn,
115115
HIR::ImplItem *deref_item,
116116
Adjustment::AdjustmentType requires_ref_adjustment)
117117
: type (type), actual (actual), expected (expected),
@@ -120,8 +120,8 @@ class Adjustment
120120
{}
121121

122122
AdjustmentType type;
123-
const TyTy::BaseType *actual;
124-
const TyTy::BaseType *expected;
123+
TyTy::BaseType *actual;
124+
TyTy::BaseType *expected;
125125

126126
// - only used for deref operator_overloads
127127
//
@@ -140,12 +140,12 @@ class Adjuster
140140
TyTy::BaseType *adjust_type (const std::vector<Adjustment> &adjustments);
141141

142142
static Adjustment
143-
try_deref_type (const TyTy::BaseType *ty,
143+
try_deref_type (TyTy::BaseType *ty,
144144
Analysis::RustLangItem::ItemType deref_lang_item);
145145

146-
static Adjustment try_raw_deref_type (const TyTy::BaseType *ty);
146+
static Adjustment try_raw_deref_type (TyTy::BaseType *ty);
147147

148-
static Adjustment try_unsize_type (const TyTy::BaseType *ty);
148+
static Adjustment try_unsize_type (TyTy::BaseType *ty);
149149

150150
private:
151151
const TyTy::BaseType *base;
@@ -158,15 +158,15 @@ class AutoderefCycle
158158

159159
virtual ~AutoderefCycle ();
160160

161-
virtual bool select (const TyTy::BaseType &autoderefed) = 0;
161+
virtual bool select (TyTy::BaseType &autoderefed) = 0;
162162

163163
// optional: this is a chance to hook in to grab predicate items on the raw
164164
// type
165165
virtual void try_hook (const TyTy::BaseType &);
166166

167-
virtual bool cycle (const TyTy::BaseType *receiver);
167+
virtual bool cycle (TyTy::BaseType *receiver);
168168

169-
bool try_autoderefed (const TyTy::BaseType *r);
169+
bool try_autoderefed (TyTy::BaseType *r);
170170

171171
bool autoderef_flag;
172172
std::vector<Adjustment> adjustments;

gcc/rust/typecheck/rust-coercion.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
373373
}
374374

375375
bool
376-
TypeCoercionRules::select (const TyTy::BaseType &autoderefed)
376+
TypeCoercionRules::select (TyTy::BaseType &autoderefed)
377377
{
378378
rust_debug (
379379
"autoderef type-coercion select autoderefed={%s} can_eq expected={%s}",

gcc/rust/typecheck/rust-coercion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TypeCoercionRules : protected AutoderefCycle
7171
TypeCoercionRules (TyTy::BaseType *expected, Location locus, bool emit_errors,
7272
bool allow_autoderef);
7373

74-
bool select (const TyTy::BaseType &autoderefed) override;
74+
bool select (TyTy::BaseType &autoderefed) override;
7575

7676
bool do_coercion (TyTy::BaseType *receiver);
7777

gcc/rust/typecheck/rust-hir-dot-operator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MethodResolver::MethodResolver (bool autoderef_flag,
2929
{}
3030

3131
std::set<MethodCandidate>
32-
MethodResolver::Probe (const TyTy::BaseType *receiver,
32+
MethodResolver::Probe (TyTy::BaseType *receiver,
3333
const HIR::PathIdentSegment &segment_name,
3434
bool autoderef_flag)
3535
{
@@ -46,7 +46,7 @@ MethodResolver::try_hook (const TyTy::BaseType &r)
4646
}
4747

4848
bool
49-
MethodResolver::select (const TyTy::BaseType &receiver)
49+
MethodResolver::select (TyTy::BaseType &receiver)
5050
{
5151
struct impl_item_candidate
5252
{

gcc/rust/typecheck/rust-hir-dot-operator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class MethodResolver : private TypeCheckBase, protected AutoderefCycle
5454
};
5555

5656
static std::set<MethodCandidate>
57-
Probe (const TyTy::BaseType *receiver,
58-
const HIR::PathIdentSegment &segment_name,
57+
Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
5958
bool autoderef_flag = false);
6059

6160
static std::vector<predicate_candidate> get_predicate_items (
@@ -68,7 +67,7 @@ class MethodResolver : private TypeCheckBase, protected AutoderefCycle
6867

6968
void try_hook (const TyTy::BaseType &r) override;
7069

71-
bool select (const TyTy::BaseType &receiver) override;
70+
bool select (TyTy::BaseType &receiver) override;
7271

7372
private:
7473
// search

0 commit comments

Comments
 (0)