gccrs: Refactor CompileDrop and add DropBuilder#4586
Conversation
| } | ||
|
|
||
| private: | ||
| friend class DropBuilder; |
There was a problem hiding this comment.
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 (); | ||
|
|
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Looks really good so far!
| std::vector<DropCandidate> &peek_block_drop_candidates (); | ||
|
|
||
| private: | ||
| Context *ctx; |
There was a problem hiding this comment.
| Context *ctx; | |
| Context &ctx; |
There was a problem hiding this comment.
Thanks, I updated DropBuilder to store Context by reference!
a7fea0d to
cf5c49f
Compare
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>
cf5c49f to
fa2c4c8
Compare
This PR refactors the Drop helper API without changing behavior.
CompileDropnow keeps the compileContextas a member instead of passing it to each method.ContexttoDropBuilder,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 onDropBuilder.gcc/rust/ChangeLog: