gnu/gcc/85e795910cf794ea9b32f94f2d987861285685f8 gccrs: Generate backend drop flags for conditional moves
Generate runtime Drop flags for Conditional Drops.
Use BIR analysis results to identify locals that need Drop flags and the moves that clear those flags.
The HIR backend sets a flag when initialization, clears it after a move, and checks it before cleanup.
gcc/rust/ChangeLog:
* backend/rust-compile-context.h
(Context::insert_drop_flag): New function.
(Context::lookup_drop_flag): Likewise.
(Context::drop_flags): New member.
* backend/rust-compile-drop-builder.cc
(DropBuilder::maybe_create_drop_flag): New function.
(DropBuilder::drop_flag_assignment): Likewise.
* backend/rust-compile-drop-builder.h
(DropBuilder::maybe_create_drop_flag): New declaration.
(DropBuilder::drop_flag_assignment): Likewise.
* backend/rust-compile-drop.cc
(CompileDrop::build_current_scope_drop_cleanup): Check Drop flags before
running conditional Drops.
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Set the Drop flag after initialization.
* backend/rust-compile-stmt.cc
(CompileStmt::visit): Create Drop flags and clear them after moves.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Pass expression HirIds to BIR.
* checks/errors/borrowck/rust-bir-builder-internal.h
(AbstractBuilder::push_assignment): Pass move-site HirIds.
(AbstractExprBuilder::return_place): Likewise.
* checks/errors/borrowck/rust-bir-drop-analysis.cc
(is_straight_line): Remove.
(record_drop_for_backend): Rename from
record_drop_for_straight_line_backend.
(annotate_drop_statements): Record conditional Drops and move
sources.
(DropAnalysis::clear): Clear the new analysis results.
(DropAnalysis::needs_drop_flag): New function.
(DropAnalysis::lookup_move_source): Likewise.
(DropAnalysis::analyze): Record results for the backend.
* checks/errors/borrowck/rust-bir-drop-analysis.h
(DropAnalysis::needs_drop_flag): New declaration.
(DropAnalysis::lookup_move_source): Likewise.
(DropAnalysis::conditionally_dropped): New member.
(DropAnalysis::move_sources): Likewise.
* checks/errors/borrowck/rust-bir.h
(Statement::make_assignment): Accept a move-site HirId.
(Statement::Statement): Likewise.
(Statement::get_move_site): New function.
(Statement::move_site): New member.
gcc/testsuite/ChangeLog:
* rust/execute/drop-conditional-move.rs: New test.
12 files changed