Skip to content

stabilize c-style varargs for system, sysv64, win64, efiapi, aapcs #144066

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jul 17, 2025

This stabilizes extern block declarations of variadic functions with the system, sysv64, win64, efiapi, aapcs ABIs. This corresponds to the extended_varargs_abi_support and extern_system_varargs feature gates.

The feature gates were split up since it seemed like there might be further discussion needed for what exactly "system" ABI variadic functions should do, but a consensus has meanwhile been reached: they shall behave like "C" functions. IOW, the ABI of a "system" function is (bold part is new in this PR):

  • "stdcall" for win32 targets for non-variadic functions
  • "C" for everything else

This had been previously stabilized without FCP in #116161, which got reverted in #136897. There was also a "fun" race condition involved with the system ABI being added to the list of variadic-supporting ABIs between the creation and merge of #116161.

There was a question raised here whether t-lang even needs to be involved for a change like this. Not sure if that has meanwhile been clarified? The behavior of the "system" ABI (a Rust-specific ABI) definitely feels like t-lang territory to me.

Fixes #100189, #136946
Cc @rust-lang/lang

Stabilization report

General design

What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

AFAIK there is no RFC. The tracking issues are

What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

The only controversial point is whether "system" ABI functions should support variadics.

Note that "system" is already a magic ABI we introduced to "do the right thing". This just makes it do the right thing in more cases.

Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

Actually defining variadic functions in Rust remains unstable, under the c_variadic feature gate.

Has a Call for Testing period been conducted? If so, what feedback was received?

Does any OSS nightly users use this feature? For instance, a useful indication might be "search <grep.app> for #![feature(FEATURE_NAME)] and had N results".

There was no call for testing.

A search brings up https://github.com/rust-osdev/uefi-rs/blob/main/uefi-raw/src/table/boot.rs using this for "efiapi". THis doesn't seem widely used, but it is an "obvious" gap in our support for c-variadics.

Implementation quality

All rustc does here is forward the ABI to LLVM so there's lot a lot to say here...

Summarize the major parts of the implementation and provide links into the code (or to PRs)

An example for async closures: https://rustc-dev-guide.rust-lang.org/coroutine-closures.html.

The check for allowed variadic ABIs is here.

The special handling of "system" is here.

Summarize existing test coverage of this feature

Consider what the "edges" of this feature are. We're particularly interested in seeing tests that assure us about exactly what nearby things we're not stabilizing.

Within each test, include a comment at the top describing the purpose of the test and what set of invariants it intends to demonstrate. This is a great help to those reviewing the tests at stabilization time.

  • What does the test coverage landscape for this feature look like?
    • Tests for compiler errors when you use the feature wrongly or make mistakes?
    • Tests for the feature itself:
      • Limits of the feature (so failing compilation)
      • Exercises of edge cases of the feature
      • Tests that checks the feature works as expected (where applicable, //@ run-pass).
    • Are there any intentional gaps in test coverage?

Link to test folders or individual tests (ui/codegen/assembly/run-make tests, etc.).

This PR adds a codegen test ensuring we emit the correct LLVM IR: tests/codegen/cffi/c-variadic-ffi.rs.
There is an existing test ensuring that we keep rejecting variadics for ABIs where that is not supported (tests/ui/c-variadic/variadic-ffi-1.rs).

The test ensuring that we do not stabilize defining c-variadic functions is tests/ui/feature-gates/feature-gate-c_variadic.rs.

What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

None that I am aware of.

What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None that I am aware of.

Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization

@Soveu added sysv64, win64, efiapi, aapcs to the list of ABIs that allow variadics, @beepster4096 added system. @workingjubilee recently refactored the ABI handling in the compiler, also affecting this feature.

Which tools need to be adjusted to support this feature. Has this work been done?

Consider rustdoc, clippy, rust-analyzer, rustfmt, rustup, docs.rs.

Maybe RA needs to be taught about the new allowed ABIs? No idea how precisely they mirror what exactly rustc accepts and rejects here.

Type system and execution rules

What compilation-time checks are done that are needed to prevent undefined behavior?

(Be sure to link to tests demonstrating that these tests are being done.)

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

Does the feature's implementation need checks to prevent UB or is it sound by default and needs opt in in places to perform the dangerous/unsafe operations? If it is not sound by default, what is the rationale?

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

Can users use this feature to introduce undefined behavior, or use this feature to break the abstraction of Rust and expose the underlying assembly-level implementation? (Describe.)

Nothing new here, this just expands the existing support for calling variadic functions to more ABIs.

What updates are needed to the reference/specification? (link to PRs when they exist)

Common interactions

Does this feature introduce new expressions and can they produce temporaries? What are the lifetimes of those temporaries?

No.

What other unstable features may be exposed by this feature?

None.

@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

HIR ty lowering was modified

cc @fmease

@RalfJung RalfJung added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-nominated Nominated for discussion during a lang team meeting. T-lang Relevant to the language team and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 17, 2025
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the extern-c-variadics branch from 9c870d3 to e5330ce Compare July 17, 2025 12:05
@RalfJung RalfJung force-pushed the extern-c-variadics branch from e5330ce to 496a9d6 Compare July 17, 2025 12:12
@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Jul 18, 2025
@Soveu
Copy link
Contributor

Soveu commented Jul 18, 2025

Looks great :) Thanks for pushing this topic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-nominated Nominated for discussion during a lang team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for extended_varargs_abi_support
6 participants