public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Get rid of lambdas within AST::StructStruct
@ 2022-06-08 11:55 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:55 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0
commit 8c3ad67d19b7e74b1c89a6ad42f2bb0c5fb172e0
Author: David Faust <david.faust@oracle.com>
Date: Mon Dec 13 13:43:28 2021 -0800
Get rid of lambdas within AST::StructStruct
These constructs make working with the IR needlessly complicated for
static analysis. Replace with simple for loops, and delete the old
StructStruct::iterate () method.
Fixes: #714
Diff:
---
gcc/rust/ast/rust-item.h | 9 --------
gcc/rust/hir/rust-ast-lower-item.h | 36 ++++++++++++++++----------------
gcc/rust/hir/rust-ast-lower-stmt.h | 36 ++++++++++++++++----------------
gcc/rust/resolve/rust-ast-resolve-item.h | 4 +---
gcc/rust/resolve/rust-ast-resolve-stmt.h | 4 +---
5 files changed, 38 insertions(+), 51 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index e319d743794..16a9108165c 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1975,15 +1975,6 @@ public:
std::vector<StructField> &get_fields () { return fields; }
const std::vector<StructField> &get_fields () const { return fields; }
- void iterate (std::function<bool (StructField &)> cb)
- {
- for (auto &field : fields)
- {
- if (!cb (field))
- return;
- }
- }
-
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index d4c0306f343..2a8c9bbbc7e 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -215,28 +215,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h
index b617991d928..237c6356380 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -203,28 +203,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index e697f1c53b4..e8e6b8d0120 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -308,11 +308,9 @@ public:
if (struct_decl.has_where_clause ())
ResolveWhereClause::Resolve (struct_decl.get_where_clause ());
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index a4043656441..16f5b9afd07 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -237,11 +237,9 @@ public:
}
}
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 11:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:55 [gcc/devel/rust/master] Get rid of lambdas within AST::StructStruct Thomas Schwinge
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).