aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-03-10 13:10:11 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-03-17 10:34:36 +0000
commit254208dc7aea43712f46eb3d732d17d0d6551bfc (patch)
tree814168b8d1bde27c40167b552553b5a67e3356b2
parent0e010fc08b42cf4379e2ad1b51518c22a7f82186 (diff)
downloadgcc-254208dc7aea43712f46eb3d732d17d0d6551bfc.zip
gcc-254208dc7aea43712f46eb3d732d17d0d6551bfc.tar.gz
gcc-254208dc7aea43712f46eb3d732d17d0d6551bfc.tar.bz2
gccrs: reuse destructure code in compilation of types
We can just return error_mark_node instead of our own custom recursion limit checker code. This makes the backend more reuseable in error states. gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::TyTyResolveCompile): call destructure (TyTyResolveCompile::compile): use error_mark_node (TyTyResolveCompile::visit): use error_mark_node * backend/rust-compile-type.h: remove recursive ops Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/backend/rust-compile-type.cc51
-rw-r--r--gcc/rust/backend/rust-compile-type.h1
2 files changed, 21 insertions, 31 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index a1db6ad..879b89f 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -30,7 +30,7 @@ static const std::string RUST_ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR";
TyTyResolveCompile::TyTyResolveCompile (Context *ctx, bool trait_object_mode)
: ctx (ctx), trait_object_mode (trait_object_mode),
- translated (error_mark_node), recurisve_ops (0)
+ translated (error_mark_node)
{}
tree
@@ -38,7 +38,8 @@ TyTyResolveCompile::compile (Context *ctx, const TyTy::BaseType *ty,
bool trait_object_mode)
{
TyTyResolveCompile compiler (ctx, trait_object_mode);
- ty->accept_vis (compiler);
+ const TyTy::BaseType *destructured = ty->destructure ();
+ destructured->accept_vis (compiler);
if (compiler.translated != error_mark_node
&& TYPE_NAME (compiler.translated) != NULL)
@@ -98,6 +99,24 @@ TyTyResolveCompile::visit (const TyTy::InferType &)
}
void
+TyTyResolveCompile::visit (const TyTy::ParamType &)
+{
+ translated = error_mark_node;
+}
+
+void
+TyTyResolveCompile::visit (const TyTy::ProjectionType &type)
+{
+ translated = error_mark_node;
+}
+
+void
+TyTyResolveCompile::visit (const TyTy::PlaceholderType &type)
+{
+ translated = error_mark_node;
+}
+
+void
TyTyResolveCompile::visit (const TyTy::ClosureType &type)
{
auto mappings = ctx->get_mappings ();
@@ -138,34 +157,6 @@ TyTyResolveCompile::visit (const TyTy::ClosureType &type)
}
void
-TyTyResolveCompile::visit (const TyTy::ProjectionType &type)
-{
- type.get ()->accept_vis (*this);
-}
-
-void
-TyTyResolveCompile::visit (const TyTy::PlaceholderType &type)
-{
- type.resolve ()->accept_vis (*this);
-}
-
-void
-TyTyResolveCompile::visit (const TyTy::ParamType &param)
-{
- if (recurisve_ops++ >= rust_max_recursion_depth)
- {
- rust_error_at (Location (),
- "%<recursion depth%> count exceeds limit of %i (use "
- "%<frust-max-recursion-depth=%> to increase the limit)",
- rust_max_recursion_depth);
- translated = error_mark_node;
- return;
- }
-
- param.resolve ()->accept_vis (*this);
-}
-
-void
TyTyResolveCompile::visit (const TyTy::FnType &type)
{
Backend::typed_identifier receiver;
diff --git a/gcc/rust/backend/rust-compile-type.h b/gcc/rust/backend/rust-compile-type.h
index 4fea6ba..acaa80a 100644
--- a/gcc/rust/backend/rust-compile-type.h
+++ b/gcc/rust/backend/rust-compile-type.h
@@ -70,7 +70,6 @@ private:
Context *ctx;
bool trait_object_mode;
tree translated;
- int recurisve_ops;
};
} // namespace Compile