Skip to content

Improve box - #4767

Merged
philberty merged 2 commits into
Rust-GCC:masterfrom
nsvke:improve-box
Aug 16, 2026
Merged

Improve box#4767
philberty merged 2 commits into
Rust-GCC:masterfrom
nsvke:improve-box

Conversation

@nsvke

@nsvke nsvke commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This patch introduces DST support for box, allowing it to correctly
handle unsized types.

It also implements the auto-deref mechanism for box. This ensures that
method dispatch, indexing, and tuple field access work correctly.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (compile_box): Remove DST guard.
(build_box_inner_ptr): Add fat pointer control.
(CompileExpr::visit): Add auto-deref for box.
(HIRCompileBase::resolve_deref_adjustment): Return fat or thin
pointer.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Add auto-deref for box.
* typecheck/rust-tyty.cc (ADTType::is_box): New function.
* typecheck/rust-tyty.h (class BaseType): New declaration.

gcc/testsuite/ChangeLog:

* rust/execute/box-dispatch-1.rs: New test.
* rust/execute/box-dispatch-2.rs: New test.
* rust/execute/unsized-adt-size.rs: Format test.

This patch implements the 'dispatch_from_dyn' lang item specifically for
'Box'. While there are other smart pointers and types that require this
lang item for dynamic dispatch, they are omitted in this patch as they
are not yet fully supported by the compiler.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Handle Box
receivers correctly during dynamic dispatch.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::try_hook):
Extract the inner type of a Box to resolve trait methods.
* util/rust-lang-item.cc (Rust::LangItem::lang_items): Register
dispatch_from_dyn to the BiMap.
* util/rust-lang-item.h (class LangItem): Add DISPATCH_FROM_DYN
to the Kind enum.

gcc/testsuite/ChangeLog:

* rust/execute/box-dispatch-from-dyn.rs: New test.

@nsvke
nsvke marked this pull request as ready for review August 10, 2026 09:19

@philberty philberty 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.

LGTM nice work

@philberty
philberty added this pull request to the merge queue Aug 15, 2026
@philberty
philberty removed this pull request from the merge queue due to a manual request Aug 15, 2026
@philberty

Copy link
Copy Markdown
Member

oh wait i see there is a base mr to this

nsvke added 2 commits August 16, 2026 00:41
This patch introduces DST support for box, allowing it to correctly
handle unsized types.

It also implements the auto-deref mechanism for box. This ensures that
method dispatch, indexing, and tuple field access work correctly.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (compile_box): Remove DST guard.
	(build_box_inner_ptr): Add fat pointer control.
	(CompileExpr::visit): Add auto-deref for box.
	(HIRCompileBase::resolve_deref_adjustment): Return fat or thin
	pointer.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	Add auto-deref for box.
	* typecheck/rust-tyty.cc (ADTType::is_box): New function.
	* typecheck/rust-tyty.h (class BaseType): New declaration.

gcc/testsuite/ChangeLog:

	* rust/execute/box-dispatch-1.rs: New test.
	* rust/execute/box-dispatch-2.rs: New test.
	* rust/execute/unsized-adt-size.rs: Format test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
This patch implements the 'dispatch_from_dyn' lang item specifically for
'Box'. While there are other smart pointers and types that require this
lang item for dynamic dispatch, they are omitted in this patch as they
are not yet fully supported by the compiler.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Handle Box
	receivers correctly during dynamic dispatch.
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::try_hook):
	Extract the inner type of a Box to resolve trait methods.
	* util/rust-lang-item.cc (Rust::LangItem::lang_items): Register
	dispatch_from_dyn to the BiMap.
	* util/rust-lang-item.h (class LangItem): Add DISPATCH_FROM_DYN
	to the Kind enum.

gcc/testsuite/ChangeLog:

	* rust/execute/box-dispatch-from-dyn.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
@philberty
philberty enabled auto-merge August 15, 2026 21:49
@philberty
philberty added this pull request to the merge queue Aug 15, 2026
Merged via the queue into Rust-GCC:master with commit d09ba8e Aug 16, 2026
12 of 13 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in libcore 1.49 Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants