Skip to content

gccrs: Refactor CompileDrop and add DropBuilder#4586

Open
Lishin1215 wants to merge 1 commit into
Rust-GCC:masterfrom
Lishin1215:refactor-compile-drop
Open

gccrs: Refactor CompileDrop and add DropBuilder#4586
Lishin1215 wants to merge 1 commit into
Rust-GCC:masterfrom
Lishin1215:refactor-compile-drop

Conversation

@Lishin1215

@Lishin1215 Lishin1215 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR refactors the Drop helper API without changing behavior.

  • CompileDrop now keeps the compile Context as a member instead of passing it to each method.
  • The drop candidate note/peek operations were moved from Context to DropBuilder,
    keeping the drop-specific API off the compile Context.

This is intended as a first step toward a dedicated Drop API.
Future work can decide whether higher-level APIs such as compile_drop_calls() should live on DropBuilder.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-compile-drop-builder.o.
* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): Update CompileDrop calls.
* backend/rust-compile-block.cc (CompileBlock::visit): Update CompileDrop calls.
* backend/rust-compile-context.h (Context): Allow DropBuilder to access drop candidate storage and move drop candidate APIs to DropBuilder.
* backend/rust-compile-drop.cc (CompileDrop::CompileDrop): Add constructor. (CompileDrop::type_has_drop_impl): Use stored Context member. (CompileDrop::compile_drop_call): Likewise. (CompileDrop::emit_current_scope_drop_calls): Use stored Context member and get drop candidates from DropBuilder.
* backend/rust-compile-drop.h: Store Context as a member.
* backend/rust-compile-pattern.cc (CompilePatternLet::visit): Use DropBuilder and update CompileDrop calls.
* backend/rust-compile-drop-builder.cc: New file.
* backend/rust-compile-drop-builder.h: New file.

}

private:
friend class DropBuilder;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept block_drop_candidates owned by Context for now because it is still updated together with push_block / pop_block.

DropBuilder only wraps the note/peek operations in this PR, so the storage ownership does not change yet.

Does this split look okay as a first step?


void note_simple_drop_candidate (HirId hirid, location_t locus);
std::vector<DropCandidate> &peek_block_drop_candidates ();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this first version, I kept DropBuilder small and limited it to the drop-candidate note/peek API.

I did not move compile_drop_call into it yet, because CompileDrop still handles turning the collected candidates into actual drop calls.

Does this match the direction you had in mind for the future Drop API?

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good so far!

std::vector<DropCandidate> &peek_block_drop_candidates ();

private:
Context *ctx;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Context *ctx;
Context &ctx;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated DropBuilder to store Context by reference!

@Lishin1215 Lishin1215 force-pushed the refactor-compile-drop branch from a7fea0d to cf5c49f Compare June 21, 2026 22:14
Refactor CompileDrop to keep Context as a member
instead of passing it to each method.

Move the drop candidate note/peek operations from
Context to DropBuilder. This keeps the drop-specific
API off the compile Context.

gcc/rust/ChangeLog:

	* Make-lang.in: Add rust-compile-drop-builder.o.
	* backend/rust-compile-base.cc
	(HIRCompileBase::compile_function_body):
	Update CompileDrop calls.
	* backend/rust-compile-block.cc (CompileBlock::visit):
	Update CompileDrop calls.
	* backend/rust-compile-context.h (Context): Allow
	DropBuilder to access drop candidate storage and move
	drop candidate APIs to DropBuilder.
	* backend/rust-compile-drop.cc (CompileDrop::CompileDrop):
	Add constructor.
	(CompileDrop::type_has_drop_impl): Use stored Context member.
	(CompileDrop::compile_drop_call): Likewise.
	(CompileDrop::emit_current_scope_drop_calls): Use stored
	Context member and get drop candidates from DropBuilder.
	* backend/rust-compile-drop.h: Store Context as a member.
	* backend/rust-compile-pattern.cc (CompilePatternLet::visit):
	Use DropBuilder and update CompileDrop calls.
	* backend/rust-compile-drop-builder.cc: New file.
	* backend/rust-compile-drop-builder.h: New file.

Signed-off-by: Lishin <lishin1008@gmail.com>
@Lishin1215 Lishin1215 force-pushed the refactor-compile-drop branch from cf5c49f to fa2c4c8 Compare June 23, 2026 17:32
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.

2 participants