public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] gccrs: autoderef unconstify so we can use in non const contexts Date: Tue, 28 Feb 2023 22:37:29 +0000 (GMT) [thread overview] Message-ID: <20230228223729.EE14D3858C62@sourceware.org> (raw) https://gcc.gnu.org/g:0632bfbf63449ed4d963d3a29aff1deb0b07e65f commit 0632bfbf63449ed4d963d3a29aff1deb0b07e65f Author: Philip Herron <herron.philip@googlemail.com> Date: Mon Feb 27 17:05:13 2023 +0000 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 Diff: --- gcc/rust/backend/rust-compile-base.h | 8 ++++---- gcc/rust/backend/rust-compile.cc | 17 ++++++++------- gcc/rust/typecheck/rust-autoderef.cc | 16 +++++++-------- gcc/rust/typecheck/rust-autoderef.h | 32 ++++++++++++++--------------- gcc/rust/typecheck/rust-coercion.cc | 2 +- gcc/rust/typecheck/rust-coercion.h | 2 +- gcc/rust/typecheck/rust-hir-dot-operator.cc | 4 ++-- gcc/rust/typecheck/rust-hir-dot-operator.h | 5 ++--- 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 4f039d2328e..a8f8f2d50dd 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 db08b3d595b..32179010855 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 658ddd7c2e9..b2cddb3f6b0 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 5f05c0489d1..1d5dacfc55d 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 7a3f51aa419..c07ee733514 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 69442e5a260..0a55b8598d8 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 84fa8d4f08b..4a291e13e5b 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 e14baf3f87d..75927ff5ae2 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
reply other threads:[~2023-02-28 22:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230228223729.EE14D3858C62@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).