public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Remove lambda iterator from HIR::MethodCallExpr
@ 2022-06-08 11:38 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6cd07341b1057961bebc8c11d70909ccac781113

commit 6cd07341b1057961bebc8c11d70909ccac781113
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Tue Oct 5 14:30:58 2021 +0100

    Remove lambda iterator from HIR::MethodCallExpr
    
    This removes the bad code style lambda iterators for arguments. They are
    a bad design choice for static analysis code since the user of the api
    looses scope to break/return outside from the caller api. This will need
    to be added to a style-guide in the future.
    
    Fixes: #709

Diff:
---
 gcc/rust/backend/rust-compile.cc    | 23 ++++++++++----------
 gcc/rust/hir/tree/rust-hir-expr.h   | 16 ++++----------
 gcc/rust/lint/rust-lint-marklive.cc |  6 ++----
 gcc/rust/typecheck/rust-tyty.cc     | 42 +++++++++++++++++++------------------
 4 files changed, 39 insertions(+), 48 deletions(-)

diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index d6c60668821..d1fd064d895 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -224,12 +224,12 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
 
       std::vector<Bexpression *> args;
       args.push_back (self_argument);
-      expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
-	Bexpression *compiled_expr = CompileExpr::Compile (p, ctx);
-	rust_assert (compiled_expr != nullptr);
-	args.push_back (compiled_expr);
-	return true;
-      });
+      for (auto &argument : expr.get_arguments ())
+	{
+	  Bexpression *compiled_expr
+	    = CompileExpr::Compile (argument.get (), ctx);
+	  args.push_back (compiled_expr);
+	}
 
       Bexpression *fn_expr
 	= ctx->get_backend ()->var_expression (fn_convert_expr_tmp,
@@ -414,12 +414,11 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
   args.push_back (self);
 
   // normal args
-  expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
-    Bexpression *compiled_expr = CompileExpr::Compile (p, ctx);
-    rust_assert (compiled_expr != nullptr);
-    args.push_back (compiled_expr);
-    return true;
-  });
+  for (auto &argument : expr.get_arguments ())
+    {
+      Bexpression *compiled_expr = CompileExpr::Compile (argument.get (), ctx);
+      args.push_back (compiled_expr);
+    }
 
   auto fncontext = ctx->peek_fn ();
   translated
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index d66640d6f39..1d8af6beb4e 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -1725,21 +1725,13 @@ public:
 
   PathExprSegment get_method_name () const { return method_name; };
 
-  std::vector<std::unique_ptr<Expr> > &get_params () { return params; }
-  const std::vector<std::unique_ptr<Expr> > &get_params () const
-  {
-    return params;
-  }
-
   size_t num_params () const { return params.size (); }
 
-  void iterate_params (std::function<bool (Expr *)> cb)
+  std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; }
+
+  const std::vector<std::unique_ptr<Expr> > &get_arguments () const
   {
-    for (auto &param : params)
-      {
-	if (!cb (param.get ()))
-	  return;
-      }
+    return params;
   }
 
 protected:
diff --git a/gcc/rust/lint/rust-lint-marklive.cc b/gcc/rust/lint/rust-lint-marklive.cc
index 087129131d1..4b095ab45bd 100644
--- a/gcc/rust/lint/rust-lint-marklive.cc
+++ b/gcc/rust/lint/rust-lint-marklive.cc
@@ -149,10 +149,8 @@ MarkLive::visit (HIR::MethodCallExpr &expr)
 {
   expr.get_receiver ()->accept_vis (*this);
   visit_path_segment (expr.get_method_name ());
-  expr.iterate_params ([&] (HIR::Expr *param) -> bool {
-    param->accept_vis (*this);
-    return true;
-  });
+  for (auto &argument : expr.get_arguments ())
+    argument->accept_vis (*this);
 
   // Trying to find the method definition and mark it alive.
   NodeId ast_node_id = expr.get_mappings ().get_nodeid ();
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 8de9d9d42a8..64eab3008c0 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2561,29 +2561,31 @@ TypeCheckMethodCallExpr::visit (FnType &type)
     }
 
   size_t i = 1;
-  call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
-    auto fnparam = type.param_at (i);
-    auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
-    if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
-      {
-	rust_error_at (param->get_locus (),
-		       "failed to resolve type for argument expr in CallExpr");
-	return false;
-      }
+  for (auto &argument : call.get_arguments ())
+    {
+      auto fnparam = type.param_at (i);
+      auto argument_expr_tyty
+	= Resolver::TypeCheckExpr::Resolve (argument.get (), false);
+      if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+	{
+	  rust_error_at (
+	    argument->get_locus (),
+	    "failed to resolve type for argument expr in CallExpr");
+	  return;
+	}
 
-    auto resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
-    if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
-      {
-	rust_error_at (param->get_locus (),
-		       "Type Resolution failure on parameter");
-	return false;
-      }
+      auto resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
+      if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+	{
+	  rust_error_at (argument->get_locus (),
+			 "Type Resolution failure on parameter");
+	  return;
+	}
 
-    context->insert_type (param->get_mappings (), resolved_argument_type);
+      context->insert_type (argument->get_mappings (), resolved_argument_type);
 
-    i++;
-    return true;
-  });
+      i++;
+    }
 
   if (i != num_args_to_call)
     {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 11:38 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:38 [gcc/devel/rust/master] Remove lambda iterator from HIR::MethodCallExpr 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).