Skip to content

Commit

Permalink
borrowck: Refactor and BIR improvements
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop): Move.
	(ExprStmtBuilder::get_label_ctx): Move.
	(ExprStmtBuilder::get_unnamed_loop_ctx): Moved.
	(ExprStmtBuilder::visit): BIR improvements.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Refactor.
	* checks/errors/borrowck/rust-bir-builder-internal.h (class LifetimeResolver):
	Refactor.
	(struct BuilderContext): Move.Refactor.
	(optional_from_ptr): Map on null ptr.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h (class LazyBooleanExprBuilder):
	Refactor.
	* checks/errors/borrowck/rust-bir-builder-pattern.h: Refactor.
	* checks/errors/borrowck/rust-bir-builder-struct.h (class StructBuilder): Refactor.
	* checks/errors/borrowck/rust-bir-builder.h: Refactor.
	* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Refactor.
	(Dump::visit): Refactor.
	(Dump::visit_place): Refactor.
	(Dump::visit_move_place): Refactor.
	(Dump::visit_lifetime): Refactor.
	* checks/errors/borrowck/rust-bir-dump.h: Refactor.
	* checks/errors/borrowck/rust-bir-place.h: Refactor.

Signed-off-by: Jakub Dupak <[email protected]>
  • Loading branch information
jdupak authored and CohenArthur committed Oct 26, 2023
1 parent 325dd9e commit 2a1a373
Show file tree
Hide file tree
Showing 10 changed files with 508 additions and 415 deletions.
285 changes: 137 additions & 148 deletions gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@
namespace Rust {
namespace BIR {

/**
* Compiles expressions into a BIR place.
* See AbstractExprBuilder for API usage docs (mainly `return_place` and
* `return_expr`).
*/
class ExprStmtBuilder : public AbstractExprBuilder, public HIR::HIRStmtVisitor
{
PlaceId expr_return_place = INVALID_PLACE;

public:
explicit ExprStmtBuilder (BuilderContext &ctx) : AbstractExprBuilder (ctx) {}

PlaceId build (HIR::Expr &expr) { return visit_expr (expr); }
/** Entry point. */
PlaceId build (HIR::Expr &expr, PlaceId place = INVALID_PLACE)
{
return visit_expr (expr, place);
}

private:
template <typename T>
Expand All @@ -46,17 +53,19 @@ class ExprStmtBuilder : public AbstractExprBuilder, public HIR::HIRStmtVisitor
return result;
}

BuilderContext::LoopAndLabelInfo &setup_loop (HIR::BaseLoopExpr &expr);
/** Common infrastructure for loops. */
BuilderContext::LoopAndLabelCtx &setup_loop (HIR::BaseLoopExpr &expr);

BuilderContext::LoopAndLabelCtx &get_label_ctx (HIR::Lifetime &label);
BuilderContext::LoopAndLabelCtx &get_unnamed_loop_ctx ();

protected: // Expr
// TODO: test when compiles
void visit (HIR::ClosureExpr &expr) override;
void visit (HIR::StructExprStructFields &fields) override;
void visit (HIR::StructExprStruct &expr) override;
void visit (HIR::LiteralExpr &expr) override;
void visit (HIR::BorrowExpr &expr) override;
void visit (HIR::DereferenceExpr &expr) override;
// TODO: desugar in AST->HIR
void visit (HIR::ErrorPropagationExpr &expr) override;
void visit (HIR::NegationExpr &expr) override;
void visit (HIR::ArithmeticOrLogicalExpr &expr) override;
Expand All @@ -71,7 +80,7 @@ class ExprStmtBuilder : public AbstractExprBuilder, public HIR::HIRStmtVisitor
void visit (HIR::TupleExpr &expr) override;
void visit (HIR::TupleIndexExpr &expr) override;
void visit (HIR::CallExpr &expr) override;
void visit (HIR::MethodCallExpr &expr) override {}
void visit (HIR::MethodCallExpr &expr) override;
void visit (HIR::FieldAccessExpr &expr) override;
void visit (HIR::BlockExpr &block) override;
void visit (HIR::ContinueExpr &cont) override;
Expand All @@ -96,7 +105,7 @@ class ExprStmtBuilder : public AbstractExprBuilder, public HIR::HIRStmtVisitor
void visit (HIR::AwaitExpr &expr) override;
void visit (HIR::AsyncBlockExpr &expr) override;

// Nodes not containing executable code. Nothing to do.
protected: // Nodes not containing executable code. Nothing to do.
void visit (HIR::QualifiedPathInExpression &expr) override;
void visit (HIR::PathInExpression &expr) override;

Expand All @@ -119,9 +128,8 @@ class ExprStmtBuilder : public AbstractExprBuilder, public HIR::HIRStmtVisitor

void visit (HIR::ExprStmt &stmt) override;

protected: // Unused
protected: // Ignored.
// Only executable code of a single function/method is translated.
// All other items are ignored.
void visit (HIR::EnumItemTuple &tuple) override {}
void visit (HIR::EnumItemStruct &a_struct) override {}
void visit (HIR::EnumItem &item) override {}
Expand Down
Loading

0 comments on commit 2a1a373

Please sign in to comment.