Skip to content

codegen: Compile extern types as C void - #4834

Merged
CohenArthur merged 1 commit into
masterfrom
extern-type-compile-to-void
Sep 10, 2026
Merged

CohenArthur merged 1 commit into
masterfrom
extern-type-compile-to-void

Conversation

@CohenArthur

Copy link
Copy Markdown
Member

Per Rust's RFC 1861 (https://rust-lang.github.io/rfcs/1861-extern-types.html), extern types are FFI-safe types that are dynamically sized, and should thus compile down to regular empty types like C's void type. They are to always be used with an indirection, which means they are effectively always a regular pointer (not a pointer + metadata like a lot of pointers in Rust) to C's void type.

Closes #1922. We eventually need to work on adding checks to external types, but as they are currently implemented as types not implementing Sized, a lot of their typechecking behavior is covered.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Change extern type codegen from empty struct to the void type node.

Per Rust's RFC 1861 (https://rust-lang.github.io/rfcs/1861-extern-types.html), extern types
are FFI-safe types that are dynamically sized, and should thus compile down to regular empty
types like C's void type. They are to always be used with an indirection, which means they are
effectively always a regular pointer (not a pointer + metadata like a lot of pointers in Rust) to
C's void type.

Closes #1922. We eventually need to work on adding checks to external types, but as
they are currently implemented as types not implementing `Sized`, a lot of their typechecking
behavior is covered.

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Change extern type codegen from
	empty struct to the void type node.
@CohenArthur
CohenArthur added this pull request to the merge queue Sep 10, 2026
Merged via the queue into master with commit 930d05a Sep 10, 2026
13 checks passed
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.

Handle extern type declarations

3 participants