]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
gccrs: reuse destructure code in compilation of types
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 10 Mar 2023 13:10:11 +0000 (13:10 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 17 Mar 2023 10:34:36 +0000 (10:34 +0000)
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>
gcc/rust/backend/rust-compile-type.cc
gcc/rust/backend/rust-compile-type.h

index a1db6ade9fbd10bdb24cc6f5cbbb0ce295b3551a..879b89fe1f186f031e00b22da9dc7fbe64f55f23 100644 (file)
@@ -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)
@@ -97,6 +98,24 @@ TyTyResolveCompile::visit (const TyTy::InferType &)
   translated = error_mark_node;
 }
 
+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)
 {
@@ -137,34 +156,6 @@ TyTyResolveCompile::visit (const TyTy::ClosureType &type)
                                                type.get_ident ().locus);
 }
 
-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)
 {
index 4fea6baa37955e0b72feae70c3e9d283042f7f04..acaa80a982fcf07b8b79225f646a1878c22943cb 100644 (file)
@@ -70,7 +70,6 @@ private:
   Context *ctx;
   bool trait_object_mode;
   tree translated;
-  int recurisve_ops;
 };
 
 } // namespace Compile