diff mbox series

[111/125] gccrs: borrowck: Unify BIR terminilogy (node->statement)

Message ID 20240801145809.366388-113-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:57 p.m. UTC
From: Jakub Dupak <dev@jakubdupak.com>

gcc/rust/ChangeLog:

	* checks/errors/borrowck/bir-design-notes.md (nodes): Rename node to statement.
	(Nodes): Rename node to statement.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
	Rename node to statement.
	* checks/errors/borrowck/rust-bir-builder-internal.h: Rename node to statement.
	* checks/errors/borrowck/rust-bir-builder.h: Rename node to statement.
	* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Rename node to statement.
	(Dump::visit): Rename node to statement.
	* checks/errors/borrowck/rust-bir-dump.h (class Dump): Rename node to statement.
	* checks/errors/borrowck/rust-bir-visitor.h (class Node): Rename node to statement.
	(class Statement): Rename node to statement.
	* checks/errors/borrowck/rust-bir.h (class Node): Rename node to statement.
	(class Statement): Rename node to statement.
	(class AbstractExpr): Rename node to statement.
	(struct Function): Rename node to statement.
	(struct BasicBlock): Rename node to statement.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
 .../errors/borrowck/bir-design-notes.md       | 13 ++---
 .../borrowck/rust-bir-builder-expr-stmt.cc    |  2 +-
 .../borrowck/rust-bir-builder-internal.h      |  7 +--
 .../checks/errors/borrowck/rust-bir-builder.h |  4 +-
 .../checks/errors/borrowck/rust-bir-dump.cc   | 51 ++++++++++---------
 .../checks/errors/borrowck/rust-bir-dump.h    |  6 +--
 .../checks/errors/borrowck/rust-bir-visitor.h |  4 +-
 gcc/rust/checks/errors/borrowck/rust-bir.h    | 34 ++++++-------
 8 files changed, 62 insertions(+), 59 deletions(-)
diff mbox series

Patch

diff --git a/gcc/rust/checks/errors/borrowck/bir-design-notes.md b/gcc/rust/checks/errors/borrowck/bir-design-notes.md
index ad622cd7228..e2edc20ffa8 100644
--- a/gcc/rust/checks/errors/borrowck/bir-design-notes.md
+++ b/gcc/rust/checks/errors/borrowck/bir-design-notes.md
@@ -108,7 +108,7 @@ 
 - Declaration of locals: `let _0: i32;`, where `_0` is the return value (even if it is of the unit type). Arguments are not listed here, they are
   listed in the function header.
 - A list of basic blocks: `bb0: { ... }`. The basic block name is the `bb` prefix followed by a number.
-- Each basic block consists of a list of BIR nodes (instructions). Instruction can be either assigned to a local (place) or be a statement.
+- Each basic block consists of a list of BIR statements. Instruction can be either assigned to a local (place) or be a statement.
   Instructions take locals (places) as arguments.
 - Each basic block is terminated with a control flow instruction followed by a list of destinations:
     - `goto -> bb3;` - a goto instruction with a single destination.
@@ -126,16 +126,17 @@ 
 
 ### Basic Blocks
 
-A basic block is identified by its index in the function's basic block list. It contains a list of BIR nodes (instructions) and a list of successor
+A basic block is identified by its index in the function's basic block list.
+It contains a list of BIR statements and a list of successor
 basic block indices in CFG.
 
-### BIR Nodes (Instructions)
+### BIR Statements
 
-BIR nodes are of three categories:
+BIR statements are of three categories:
 
 - An assignment of an expression to a local (place).
 - A control flow operation (switch, return).
-- A special node (not executable) node, which carries additional information for borrow-checking (`StorageDead`, `StorageLive`).
+- A special statement (not executable), which carries additional information for borrow-checking (`StorageDead`, `StorageLive`).
 
 #### Expressions
 
@@ -147,7 +148,7 @@ 
 - `Operator<ARITY>` represents any kind of operation, except the following, where special information is needed either for borrow-checking or for
   better debugging.
 - `BorrowExpr` represents a borrow operation.
-- `AssignmentExpr` holds a place for a node of assignment (i.e., no operation is done on the place, it is just assigned).
+- `AssignmentExpr` holds a place for an assignment statement (i.e., no operation is done on the place, it is just assigned).
 - `CallExpr` represents a function call.
     - For functions, the callable is represented by a constant place (see below). (E.i. all calls use the same constant place.)
     - For closures and function pointers, the callable is represented by a (non-constant) place.
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index ead6e403661..2c916294ca7 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -419,7 +419,7 @@  ExprStmtBuilder::visit (HIR::ReturnExpr &ret)
     {
       push_assignment (RETURN_VALUE_PLACE, visit_expr (*ret.get_expr ()));
     }
-  ctx.get_current_bb ().statements.emplace_back (Node::Kind::RETURN);
+  ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
 }
 
 void
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index b4192677261..eef0f916408 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -177,7 +177,7 @@  protected:
     return ctx.place_db.add_variable (nodeid, ty);
   }
 
-protected: // Helpers to add BIR nodes
+protected: // Helpers to add BIR statements
   void push_assignment (PlaceId lhs, AbstractExpr *rhs)
   {
     ctx.get_current_bb ().statements.emplace_back (lhs, rhs);
@@ -199,14 +199,15 @@  protected: // Helpers to add BIR nodes
 		    std::initializer_list<BasicBlockId> destinations = {})
   {
     auto copy = make_arg (switch_val);
-    ctx.get_current_bb ().statements.emplace_back (Node::Kind::SWITCH, copy);
+    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::SWITCH,
+						   copy);
     ctx.get_current_bb ().successors.insert (
       ctx.get_current_bb ().successors.end (), destinations);
   }
 
   void push_goto (BasicBlockId bb)
   {
-    ctx.get_current_bb ().statements.emplace_back (Node::Kind::GOTO);
+    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::GOTO);
     if (bb != INVALID_BB) // INVALID_BB means the goto will be resolved later.
       ctx.get_current_bb ().successors.push_back (bb);
   }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index 509929bc684..9bed96c660f 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -77,13 +77,13 @@  private:
     if (body.has_expr () && !lookup_type (body)->is_unit ())
       {
 	push_assignment (RETURN_VALUE_PLACE, translated);
-	ctx.get_current_bb ().statements.emplace_back (Node::Kind::RETURN);
+	ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
       }
     else if (!ctx.get_current_bb ().is_terminated ())
       {
 	push_assignment (RETURN_VALUE_PLACE,
 			 ctx.place_db.get_constant (lookup_type (body)));
-	ctx.get_current_bb ().statements.emplace_back (Node::Kind::RETURN);
+	ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
       }
   };
 };
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 3e49bc76933..3684ad7b889 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -135,20 +135,21 @@  Dump::go (bool enable_simplify_cfg)
     }
 
   // Print BBs.
-  for (node_bb = 0; node_bb < func.basic_blocks.size (); ++node_bb)
+  for (statement_bb = 0; statement_bb < func.basic_blocks.size ();
+       ++statement_bb)
     {
-      if (bb_fold_map[node_bb] != node_bb)
+      if (bb_fold_map[statement_bb] != statement_bb)
 	continue; // This BB was folded.
 
-      if (func.basic_blocks[node_bb].statements.empty ()
-	  && func.basic_blocks[node_bb].successors.empty ())
+      if (func.basic_blocks[statement_bb].statements.empty ()
+	  && func.basic_blocks[statement_bb].successors.empty ())
 	continue;
 
       bb_terminated = false;
 
-      BasicBlock &bb = func.basic_blocks[node_bb];
+      BasicBlock &bb = func.basic_blocks[statement_bb];
       stream << "\n";
-      stream << indentation << "bb" << bb_fold_map[node_bb] << ": {\n";
+      stream << indentation << "bb" << bb_fold_map[statement_bb] << ": {\n";
       for (auto &stmt : bb.statements)
 	{
 	  stream << indentation << indentation;
@@ -166,49 +167,49 @@  Dump::go (bool enable_simplify_cfg)
   stream << "}\n";
 }
 void
-Dump::visit (Node &node)
+Dump::visit (Statement &stmt)
 {
-  node_place = node.get_place ();
-  switch (node.get_kind ())
+  statement_place = stmt.get_place ();
+  switch (stmt.get_kind ())
     {
-      case Node::Kind::ASSIGNMENT: {
-	visit_place (node.get_place ());
+      case Statement::Kind::ASSIGNMENT: {
+	visit_place (stmt.get_place ());
 	stream << " = ";
-	node.get_expr ().accept_vis (*this);
+	stmt.get_expr ().accept_vis (*this);
 	break;
       }
-    case Node::Kind::SWITCH:
+    case Statement::Kind::SWITCH:
       stream << "switchInt(";
-      visit_move_place (node.get_place ());
+      visit_move_place (stmt.get_place ());
       stream << ") -> [";
-      print_comma_separated (stream, func.basic_blocks[node_bb].successors,
+      print_comma_separated (stream, func.basic_blocks[statement_bb].successors,
 			     [this] (BasicBlockId succ) {
 			       stream << "bb" << bb_fold_map[succ];
 			     });
       stream << "]";
       bb_terminated = true;
       break;
-    case Node::Kind::RETURN:
+    case Statement::Kind::RETURN:
       stream << "return";
       bb_terminated = true;
       break;
-    case Node::Kind::GOTO:
+    case Statement::Kind::GOTO:
       stream << "goto -> bb"
-	     << bb_fold_map[func.basic_blocks[node_bb].successors.at (0)];
+	     << bb_fold_map[func.basic_blocks[statement_bb].successors.at (0)];
       bb_terminated = true;
       break;
-    case Node::Kind::STORAGE_DEAD:
+    case Statement::Kind::STORAGE_DEAD:
       stream << "StorageDead(";
-      visit_move_place (node.get_place ());
+      visit_move_place (stmt.get_place ());
       stream << ")";
       break;
-    case Node::Kind::STORAGE_LIVE:
+    case Statement::Kind::STORAGE_LIVE:
       stream << "StorageLive(";
-      visit_move_place (node.get_place ());
+      visit_move_place (stmt.get_place ());
       stream << ")";
       break;
     }
-  node_place = INVALID_PLACE;
+  statement_place = INVALID_PLACE;
 }
 
 void
@@ -261,7 +262,7 @@  void
 Dump::visit (BorrowExpr &expr)
 {
   stream << "&";
-  visit_lifetime (node_place);
+  visit_lifetime (statement_place);
   visit_place (expr.get_place ());
 }
 
@@ -307,7 +308,7 @@  Dump::visit (CallExpr &expr)
 			   visit_move_place (place_id);
 			 });
   stream << ") -> [";
-  print_comma_separated (stream, func.basic_blocks[node_bb].successors,
+  print_comma_separated (stream, func.basic_blocks[statement_bb].successors,
 			 [this] (BasicBlockId succ) {
 			   stream << "bb" << bb_fold_map[succ];
 			 });
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index b6407a8528a..7ee94d749e3 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -37,8 +37,8 @@  class Dump : public Visitor
   std::vector<BasicBlockId> bb_fold_map;
   std::vector<PlaceId> place_map;
 
-  PlaceId node_place = INVALID_PLACE;
-  BasicBlockId node_bb = INVALID_BB;
+  PlaceId statement_place = INVALID_PLACE;
+  BasicBlockId statement_bb = INVALID_BB;
   bool bb_terminated = false;
 
 public:
@@ -49,7 +49,7 @@  public:
   void go (bool enable_simplify_cfg = false);
 
 protected:
-  void visit (Node &node) override;
+  void visit (Statement &stmt) override;
   void visit_place (PlaceId place_id);
   void visit_move_place (PlaceId place_id);
   void visit (BorrowExpr &expr) override;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
index 8c6053d2362..0b3a4bddbec 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
@@ -22,7 +22,7 @@ 
 namespace Rust {
 namespace BIR {
 
-class Node;
+class Statement;
 class InitializerExpr;
 template <unsigned N> class Operator;
 class Assignment;
@@ -32,7 +32,7 @@  class CallExpr;
 class Visitor
 {
 public:
-  virtual void visit (Node &node) = 0;
+  virtual void visit (Statement &stmt) = 0;
   virtual void visit (InitializerExpr &expr) = 0;
   virtual void visit (Operator<1> &expr) = 0;
   virtual void visit (Operator<2> &expr) = 0;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h b/gcc/rust/checks/errors/borrowck/rust-bir.h
index aa97eac17b4..746b2dc7e38 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -27,23 +27,23 @@  namespace Rust {
 namespace BIR {
 
 struct BasicBlock;
-class Node;
+class Statement;
 class AbstractExpr;
 
 /**
  * Top-level entity of the Borrow-checker IR (BIR).
- * It represents a single function (method, closure, etc.), which is also the
- * basic unit of Polonius borrow-checking.
+ * It represents a single function (method, closure, etc.), which is the
+ * basic unit of borrow-checking.
  */
 struct Function
 {
   PlaceDB place_db;
-  std::vector<PlaceId> arguments; // Only used for dump.
+  std::vector<PlaceId> arguments;
   std::vector<BasicBlock> basic_blocks;
 };
 
-/** Single "instruction" of BIR. */
-class Node
+/** Single statement of BIR. */
+class Statement
 {
 public:
   enum class Kind
@@ -68,12 +68,12 @@  private:
   std::unique_ptr<AbstractExpr> expr;
 
 public:
-  Node (PlaceId lhs, AbstractExpr *rhs)
+  Statement (PlaceId lhs, AbstractExpr *rhs)
     : kind (Kind::ASSIGNMENT), place (lhs), expr (rhs)
   {}
 
-  explicit Node (Kind kind, PlaceId place = INVALID_PLACE,
-		 AbstractExpr *expr = nullptr)
+  explicit Statement (Kind kind, PlaceId place = INVALID_PLACE,
+		      AbstractExpr *expr = nullptr)
     : kind (kind), place (place), expr (expr)
   {}
 
@@ -92,7 +92,7 @@  static constexpr BasicBlockId INVALID_BB
 struct BasicBlock
 {
   // BIR "instructions".
-  std::vector<Node> statements;
+  std::vector<Statement> statements;
   // A basic block can end with: goto, return or switch
   std::vector<BasicBlockId> successors;
 
@@ -103,9 +103,9 @@  public:
       return false;
     switch (statements.back ().get_kind ())
       {
-      case Node::Kind::GOTO:
-      case Node::Kind::RETURN:
-      case Node::Kind::SWITCH:
+      case Statement::Kind::GOTO:
+      case Statement::Kind::RETURN:
+      case Statement::Kind::SWITCH:
 	return true;
       default:
 	return false;
@@ -115,11 +115,11 @@  public:
   WARN_UNUSED_RESULT bool is_goto_terminated () const
   {
     return is_terminated ()
-	   && statements.back ().get_kind () == Node::Kind::GOTO;
+	   && statements.back ().get_kind () == Statement::Kind::GOTO;
   }
 };
 
-// Rhs expression of BIR assignment node (abstract).
+// Rhs expression of BIR assignment statements (abstract).
 class AbstractExpr : public Visitable
 {
 };
@@ -163,8 +163,8 @@  public:
 };
 
 /**
- * This expression is only to be used inside the assignment node and acts as
- * identity wrapper for a place value. It is separated from `Operator<1>` to
+ * This expression is only to be used inside the assignment statement and acts
+ * as identity wrapper for a place value. It is separated from `Operator<1>` to
  * render it more explicitly in the dump.
  */
 class Assignment : public VisitableImpl<AbstractExpr, Assignment>