public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Get rid of lambdas within AST::Union
@ 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:a9a7654d850a7140d1e0d636f2cc375308bb2c32
commit a9a7654d850a7140d1e0d636f2cc375308bb2c32
Author: David Faust <david.faust@oracle.com>
Date: Mon Dec 13 13:57:27 2021 -0800
Get rid of lambdas within AST::Union
These constructs make working with the IR needlessly complicated for
static analysis. Replace with simple for loops, and delete the old
Union::iterate () method.
Fixes: #716
Diff:
---
gcc/rust/ast/rust-item.h | 9 -------
gcc/rust/hir/rust-ast-lower-item.h | 40 ++++++++++++++++----------------
gcc/rust/hir/rust-ast-lower-stmt.h | 40 ++++++++++++++++----------------
gcc/rust/resolve/rust-ast-resolve-item.h | 4 +---
gcc/rust/resolve/rust-ast-resolve-stmt.h | 4 +---
5 files changed, 42 insertions(+), 55 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 16a9108165c..a18a8e6e42a 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -2472,15 +2472,6 @@ public:
std::vector<StructField> &get_variants () { return variants; }
const std::vector<StructField> &get_variants () const { return variants; }
- void iterate (std::function<bool (StructField &)> cb)
- {
- for (auto &variant : variants)
- {
- if (!cb (variant))
- return;
- }
- }
-
std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
{
return generic_params;
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index 2a8c9bbbc7e..60315dba0e3 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -325,28 +325,28 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::StructField> variants;
- union_decl.iterate ([&] (AST::StructField &variant) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (variant.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::StructField translated_variant (mapping, variant.get_field_name (),
- std::unique_ptr<HIR::Type> (type),
- vis, variant.get_locus (),
- variant.get_outer_attrs ());
+ for (AST::StructField &variant : union_decl.get_variants ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (variant.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- if (struct_field_name_exists (variants, translated_variant))
- return false;
+ HIR::StructField translated_variant (mapping, variant.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, variant.get_locus (),
+ variant.get_outer_attrs ());
- variants.push_back (std::move (translated_variant));
- return true;
- });
+ if (struct_field_name_exists (variants, translated_variant))
+ break;
+
+ variants.push_back (std::move (translated_variant));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, union_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 237c6356380..27fdd22f708 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -258,28 +258,28 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::StructField> variants;
- union_decl.iterate ([&] (AST::StructField &variant) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (variant.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::StructField translated_variant (mapping, variant.get_field_name (),
- std::unique_ptr<HIR::Type> (type),
- vis, variant.get_locus (),
- variant.get_outer_attrs ());
+ for (AST::StructField &variant : union_decl.get_variants ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (variant.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- if (struct_field_name_exists (variants, translated_variant))
- return false;
+ HIR::StructField translated_variant (mapping, variant.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, variant.get_locus (),
+ variant.get_outer_attrs ());
- variants.push_back (std::move (translated_variant));
- return true;
- });
+ if (struct_field_name_exists (variants, translated_variant))
+ break;
+
+ variants.push_back (std::move (translated_variant));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, union_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 e8e6b8d0120..b3035ed75f1 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -331,11 +331,9 @@ public:
if (union_decl.has_where_clause ())
ResolveWhereClause::Resolve (union_decl.get_where_clause ());
- union_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : union_decl.get_variants ())
ResolveType::go (field.get_field_type ().get (),
union_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 16f5b9afd07..ce6875c1fce 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -267,11 +267,9 @@ public:
}
}
- union_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : union_decl.get_variants ())
ResolveType::go (field.get_field_type ().get (),
union_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::Union 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).