From 254208dc7aea43712f46eb3d732d17d0d6551bfc Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 10 Mar 2023 13:10:11 +0000 Subject: 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 --- gcc/rust/backend/rust-compile-type.cc | 51 +++++++++++++++-------------------- gcc/rust/backend/rust-compile-type.h | 1 - 2 files changed, 21 insertions(+), 31 deletions(-) (limited to 'gcc/rust/backend') 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 ¶m) -{ - if (recurisve_ops++ >= rust_max_recursion_depth) - { - rust_error_at (Location (), - "% count exceeds limit of %i (use " - "% 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 -- cgit v1.1