diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-10 13:10:11 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:21:10 +0100 |
commit | f0f04b256ceee2c8d7a24f0e0fcd8a0894fa48db (patch) | |
tree | aca8ca8f8a72454cb041f2afc7e486f70aa8aee1 /gcc | |
parent | ef24a5b55876c38c73d8d8813df230b515936466 (diff) | |
download | gcc-f0f04b256ceee2c8d7a24f0e0fcd8a0894fa48db.zip gcc-f0f04b256ceee2c8d7a24f0e0fcd8a0894fa48db.tar.gz gcc-f0f04b256ceee2c8d7a24f0e0fcd8a0894fa48db.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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 51 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-type.h | 1 |
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 21a627e..f0c6547 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 (), - "%<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 437f20b..3abf143 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 |