From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id CE272385841C; Tue, 28 Feb 2023 22:37:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE272385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677623839; bh=v8IMevTehwlo/dGpACzLRi0rPGpwzeZ9L7bHmaFm6DI=; h=From:To:Subject:Date:From; b=vE0kPURxpX5cmI8TwJvphokRLYTALm16VO1/CtA2kYV2+iKWDPjFUQW1tah1Xfmp+ UNxW9JjgZzgpizueMS9s+dJz2voKkX/IkQA4gWqT0sgxCZjFsROUwI8NwkR5PtRWbJ IJjwoIYbBv0JtsVNum+p/57gW8qwmbqMmmpdDZCw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] gccrs: Make coercion sites autoderef cycle optional X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: bd4556fb65c64396fc6a429bc03b58932dc3c263 X-Git-Newrev: e164f32df23b309963bf17bf725cd8fcae58d2d5 Message-Id: <20230228223719.CE272385841C@sourceware.org> Date: Tue, 28 Feb 2023 22:37:19 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e164f32df23b309963bf17bf725cd8fcae58d2d5 commit e164f32df23b309963bf17bf725cd8fcae58d2d5 Author: Philip Herron Date: Mon Feb 27 14:16:29 2023 +0000 gccrs: Make coercion sites autoderef cycle optional Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-casts.cc (TypeCastRules::check): update to new interface * typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): likewise (TypeCoercionRules::TryCoerce): likewise (TypeCoercionRules::TypeCoercionRules): likewise * typecheck/rust-coercion.h: likewise * typecheck/rust-type-util.cc (coercion_site): likewise Diff: --- gcc/rust/typecheck/rust-casts.cc | 3 ++- gcc/rust/typecheck/rust-coercion.cc | 13 +++++++------ gcc/rust/typecheck/rust-coercion.h | 10 ++++++---- gcc/rust/typecheck/rust-type-util.cc | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index 987542e59c4..0ecb50f7d1d 100644 --- a/gcc/rust/typecheck/rust-casts.cc +++ b/gcc/rust/typecheck/rust-casts.cc @@ -39,7 +39,8 @@ TypeCastRules::check () { // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/cast.rs#L565-L582 auto possible_coercion - = TypeCoercionRules::TryCoerce (from.get_ty (), to.get_ty (), locus); + = TypeCoercionRules::TryCoerce (from.get_ty (), to.get_ty (), locus, + true /*allow-autoderef*/); if (!possible_coercion.is_error ()) return possible_coercion; diff --git a/gcc/rust/typecheck/rust-coercion.cc b/gcc/rust/typecheck/rust-coercion.cc index fdc8bdd7acb..7a3f51aa419 100644 --- a/gcc/rust/typecheck/rust-coercion.cc +++ b/gcc/rust/typecheck/rust-coercion.cc @@ -25,25 +25,26 @@ namespace Resolver { TypeCoercionRules::CoercionResult TypeCoercionRules::Coerce (TyTy::BaseType *receiver, TyTy::BaseType *expected, - Location locus) + Location locus, bool allow_autoderef) { - TypeCoercionRules resolver (expected, locus, true); + TypeCoercionRules resolver (expected, locus, true, allow_autoderef); bool ok = resolver.do_coercion (receiver); return ok ? resolver.try_result : CoercionResult::get_error (); } TypeCoercionRules::CoercionResult TypeCoercionRules::TryCoerce (TyTy::BaseType *receiver, - TyTy::BaseType *expected, Location locus) + TyTy::BaseType *expected, Location locus, + bool allow_autoderef) { - TypeCoercionRules resolver (expected, locus, false); + TypeCoercionRules resolver (expected, locus, false, allow_autoderef); bool ok = resolver.do_coercion (receiver); return ok ? resolver.try_result : CoercionResult::get_error (); } TypeCoercionRules::TypeCoercionRules (TyTy::BaseType *expected, Location locus, - bool emit_errors) - : AutoderefCycle (false), mappings (Analysis::Mappings::get ()), + bool emit_errors, bool allow_autoderef) + : AutoderefCycle (!allow_autoderef), mappings (Analysis::Mappings::get ()), context (TypeCheckContext::get ()), expected (expected), locus (locus), try_result (CoercionResult::get_error ()), emit_errors (emit_errors) {} diff --git a/gcc/rust/typecheck/rust-coercion.h b/gcc/rust/typecheck/rust-coercion.h index d0fc0f97079..69442e5a260 100644 --- a/gcc/rust/typecheck/rust-coercion.h +++ b/gcc/rust/typecheck/rust-coercion.h @@ -42,10 +42,12 @@ public: }; static CoercionResult Coerce (TyTy::BaseType *receiver, - TyTy::BaseType *expected, Location locus); + TyTy::BaseType *expected, Location locus, + bool allow_autoderef); static CoercionResult TryCoerce (TyTy::BaseType *receiver, - TyTy::BaseType *expected, Location locus); + TyTy::BaseType *expected, Location locus, + bool allow_autoderef); CoercionResult coerce_unsafe_ptr (TyTy::BaseType *receiver, TyTy::PointerType *expected, @@ -66,8 +68,8 @@ public: void object_unsafe_error (Location expr_locus, Location lhs, Location rhs); protected: - TypeCoercionRules (TyTy::BaseType *expected, Location locus, - bool emit_errors); + TypeCoercionRules (TyTy::BaseType *expected, Location locus, bool emit_errors, + bool allow_autoderef); bool select (const TyTy::BaseType &autoderefed) override; diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc index ff7c805c943..da9a724aca8 100644 --- a/gcc/rust/typecheck/rust-type-util.cc +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -186,7 +186,8 @@ coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, return expr; // can we autoderef it? - auto result = TypeCoercionRules::Coerce (expr, expected, locus); + auto result = TypeCoercionRules::Coerce (expr, expected, locus, + true /*allow-autodref*/); // the result needs to be unified TyTy::BaseType *receiver = expr;