-
Notifications
You must be signed in to change notification settings - Fork 71
Support enum as type of static variable with #[linkage] #565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. cc @rust-lang/compiler @rust-lang/compiler-contributors |
@rustbot second |
@rustbot label -final-comment-period +major-change-accepted |
…age attribute. Compiler MCP: rust-lang/compiler-team#565
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
Proposal
The status quo for working with weak function symbols in Rust is to define them as weak data symbols and then transmute them to function pointers (see the implementation of
weak!
). This is not only ugly, but is also incompatible with platforms where a data symbol does not have the same bitwise representation as a function symbol at the same address, as anticipated by the unsafe code guidelines for function pointers, which mention that not all platforms use identical representations. For example, the pointer authentication ABI uses some of the high-order bits of a function pointer for a signature based on the function type.This proposal aims to accommodate such platforms by making the function type part of the declaration, while at the same time allowing the implementation of
weak!
and other users of#[linkage]
to be simplified by avoiding the need to transmute.Specifically, the proposal is to allow declarations such as the following:
The static variable
foo
shall have the valueSome(foo)
iffoo
is defined, orNone
iffoo
is not defined; likewise forbar
.More formally, a static variable with a linkage attribute may be permitted to have an enumerator type with two variants, where one of the variants has no fields, and the other has a single field of one of the following non-nullable types:
The variants can appear in either order.
The value of the variable shall be initialized to the variant without a field if the symbol is not defined, or to the variant with a field if the symbol is defined, where the field has the same value that it would receive if a static variable or function of the same name and of the field's type were declared without the
#[linkage]
attribute.This can be implemented simply by allowing such an enum as the type of the static variable, because their in-memory representations are pointer sized and match how references to extern weak symbols are resolved by the linker or dynamic loader: zero if undefined, non-zero if defined.
Mentors or Reviewers
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: