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] typecheck: Refactor cast_site
Date: Tue, 28 Feb 2023 22:36:29 +0000 (GMT) [thread overview]
Message-ID: <20230228223629.15D293858416@sourceware.org> (raw)
https://gcc.gnu.org/g:0d4a4475e9fbd972bdbcf8e0bcf6f3be3db2f00f
commit 0d4a4475e9fbd972bdbcf8e0bcf6f3be3db2f00f
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Feb 23 19:00:07 2023 +0100
typecheck: Refactor cast_site
Refactor cast_site to be a simple function in rust-type-util.h.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::cast_site):
Remove cast_site.
* typecheck/rust-hir-type-check-base.h: Remove cast_site
prototype.
* typecheck/rust-type-util.cc (cast_site): Add cast_site.
* typecheck/rust-type-util.h (cast_site): Add cast_site
prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/typecheck/rust-hir-type-check-base.cc | 35 --------------------------
gcc/rust/typecheck/rust-hir-type-check-base.h | 4 ---
gcc/rust/typecheck/rust-type-util.cc | 35 ++++++++++++++++++++++++++
gcc/rust/typecheck/rust-type-util.h | 4 +++
4 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 0c54a05ced1..b87ed017583 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -17,7 +17,6 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-type-check-base.h"
-#include "rust-casts.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-type-check-implitem.h"
#include "rust-hir-type-check-item.h"
@@ -348,40 +347,6 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, Location locus)
return repr;
}
-TyTy::BaseType *
-TypeCheckBase::cast_site (HirId id, TyTy::TyWithLocation from,
- TyTy::TyWithLocation to, Location cast_locus)
-{
- rust_debug ("cast_site id={%u} from={%s} to={%s}", id,
- from.get_ty ()->debug_str ().c_str (),
- to.get_ty ()->debug_str ().c_str ());
-
- auto context = TypeCheckContext::get ();
- if (from.get_ty ()->get_kind () == TyTy::TypeKind::ERROR
- || to.get_ty ()->get_kind () == TyTy::TypeKind::ERROR)
- return to.get_ty ();
-
- // do the cast
- auto result = TypeCastRules::resolve (cast_locus, from, to);
-
- // we assume error has already been emitted
- if (result.is_error ())
- return to.get_ty ();
-
- // the result needs to be unified
- TyTy::BaseType *casted_result = result.tyty;
- rust_debug ("cast_default_unify(a={%s}, b={%s})",
- casted_result->debug_str ().c_str (),
- to.get_ty ()->debug_str ().c_str ());
-
- TyTy::BaseType *casted
- = unify_site (id, to,
- TyTy::TyWithLocation (casted_result, from.get_locus ()),
- cast_locus);
- context->insert_cast_autoderef_mappings (id, std::move (result.adjustments));
- return casted;
-}
-
void
TypeCheckBase::resolve_generic_params (
const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h
index e6f0e3c4305..fe25a4285a0 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -34,10 +34,6 @@ class TypeCheckBase
public:
virtual ~TypeCheckBase () {}
- static TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation from,
- TyTy::TyWithLocation to,
- Location cast_locus);
-
protected:
TypeCheckBase ();
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index 16b0a240589..dbd10366fd7 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -24,6 +24,7 @@
#include "rust-hir-type-check.h"
#include "rust-hir-visitor.h"
#include "rust-name-resolver.h"
+#include "rust-casts.h"
#include "rust-unify.h"
#include "rust-coercion.h"
@@ -154,5 +155,39 @@ coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
return coerced;
}
+TyTy::BaseType *
+cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,
+ Location cast_locus)
+{
+ rust_debug ("cast_site id={%u} from={%s} to={%s}", id,
+ from.get_ty ()->debug_str ().c_str (),
+ to.get_ty ()->debug_str ().c_str ());
+
+ auto context = TypeCheckContext::get ();
+ if (from.get_ty ()->get_kind () == TyTy::TypeKind::ERROR
+ || to.get_ty ()->get_kind () == TyTy::TypeKind::ERROR)
+ return to.get_ty ();
+
+ // do the cast
+ auto result = TypeCastRules::resolve (cast_locus, from, to);
+
+ // we assume error has already been emitted
+ if (result.is_error ())
+ return to.get_ty ();
+
+ // the result needs to be unified
+ TyTy::BaseType *casted_result = result.tyty;
+ rust_debug ("cast_default_unify(a={%s}, b={%s})",
+ casted_result->debug_str ().c_str (),
+ to.get_ty ()->debug_str ().c_str ());
+
+ TyTy::BaseType *casted
+ = unify_site (id, to,
+ TyTy::TyWithLocation (casted_result, from.get_locus ()),
+ cast_locus);
+ context->insert_cast_autoderef_mappings (id, std::move (result.adjustments));
+ return casted;
+}
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h
index 764ec4d7b81..01333d8b984 100644
--- a/gcc/rust/typecheck/rust-type-util.h
+++ b/gcc/rust/typecheck/rust-type-util.h
@@ -41,6 +41,10 @@ TyTy::BaseType *
coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
Location coercion_locus);
+TyTy::BaseType *
+cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,
+ Location cast_locus);
+
} // namespace Resolver
} // namespace Rust
reply other threads:[~2023-02-28 22:36 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=20230228223629.15D293858416@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: link
Be 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).