Skip to content

[WIP] Drop trait demo#4457

Draft
Islam-Imad wants to merge 1 commit intoRust-GCC:masterfrom
Islam-Imad:DropTraitDemo
Draft

[WIP] Drop trait demo#4457
Islam-Imad wants to merge 1 commit intoRust-GCC:masterfrom
Islam-Imad:DropTraitDemo

Conversation

@Islam-Imad
Copy link
Contributor

@Islam-Imad Islam-Imad commented Mar 3, 2026

The Datum system is the central point for tracking values as they flow through expression compilation. Instead of letting raw tree nodes flow through expression we will have a rich Datum that holds other important info like drop and value kind.

The Drop Place is used to hold all needed information to drop a variable and track its state at runtime if this variable is initialized or uninitialized or partially initialized.

cc @philberty

@Islam-Imad Islam-Imad marked this pull request as draft March 3, 2026 14:14
@Islam-Imad Islam-Imad force-pushed the DropTraitDemo branch 2 times, most recently from 5c558e0 to e84ed4c Compare March 18, 2026 09:23
Basic Infra to handle drop trait implementation.

ChangeLog:

	* .gitignore: Hide Zed editor files.

gcc/rust/ChangeLog:

	* Make-lang.in: Add datum.h and drop.h.
	* backend/rust-compile-context.h (RUST_COMPILE_CONTEXT): Add
	methods to hold cleanup and drop place.
	* backend/rust-compile-expr.cc (CompileExpr::CompileExpr): Wrap
	raw tree node inside datum with type and kind.
	(CompileExpr::CompileDatum): New API method to get datum.
	(CompileExpr::visit): Set datum after setting translated.
	* backend/rust-compile-expr.h (RUST_COMPILE_EXPR): Add
	CompileDatum API.
	* backend/rust-compile-stmt.cc (CompileStmt::visit): Add cleanup
	for ExprStmt, setup drop_flag state in let statement.
	* backend/rust-compile-var-decl.h (RUST_COMPILE_VAR_DECL): Create
	and store drop path/place for new declared variables.
	* rust-backend.h (block_add_statements_with_cleanups): New
	header function.
	* rust-gcc.cc (block_add_statements_with_cleanups): Wrap block
	body and cleanup into try_finally.
	* typecheck/rust-hir-type-check.h: Add method to get
	associated_traits_to_impls.
	* util/rust-lang-item.cc: Register drop lang item.
	* util/rust-lang-item.h: Register drop lang item.
	* backend/rust-compile-datum.cc: Implementation for datum.h.
	* backend/rust-compile-datum.h: Introduce the Datum system for
	tracking values through expression compilation.
	* backend/rust-compile-drop.cc: Implementation for drop.h.
	* backend/rust-compile-drop.h: Introduce Drop Place to track
	variable state and runtime cleanup information.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/drop-struct.rs: Add basic drop test.

Signed-off-by: Islam-Imad <islamimad404@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant