-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit aad36fb
authored
Unrolled build for #144066
Rollup merge of #144066 - RalfJung:extern-c-variadics, r=workingjubilee
stabilize c-style varargs for sysv64, win64, efiapi, aapcs
This has been split up so the PR now only contains the extended_varargs_abi_support stabilization; "system" has been moved to #145954.
**Previous (combined) PR description:**
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](#136946 (comment)) 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](#119587) to the list of variadic-supporting ABIs between the creation and merge of #116161.
There was a question raised [here](#116161 (comment)) 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
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
- #100189
- #136946
> ### 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.
- Pro: This allows crates like windows-rs to consistently use "system", see e.g. microsoft/windows-rs#3626.
- Cons: `@workingjubilee` had some implementation concerns, but I think those have been [resolved](#136946 (comment)). EDIT: turns out Jubilee still has concerns (she mentioned that in a DM); I'll let her express those.
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. In particular, it means that on Windows one can almost always just do
```rust
extern "system" {
// put all the things here
}
```
and it'll do the right thing, rather than having to split imports into non-varargs and varargs, with the varargs in a separate `extern "C"` block (and risking accidentally putting a non-vararg there).
(I am saying "almost" always because some Windows API functions actually use cdecl, not stdcall, on x86. Those of course need to go in `extern "C"` blocks.)
> ### 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](#44930).
> ## 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](https://github.com/rust-lang/rust/blob/9c870d30e2d6434c9e9a004b450c5ccffdf3d844/compiler/rustc_hir_analysis/src/lib.rs#L109-L126).
The special handling of "system" is [here](https://github.com/rust-lang/rust/blob/c24914ec8329b22ec7bcaa6ab534a784b2bd8ab9/compiler/rustc_target/src/spec/abi_map.rs#L82-L85).
> ### 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.).
Prior PRs add a codegen test for all ABIs and tests actually calling extern variadic functions for sysv64 and win64:
- #144359
- #144379
We don't have a way of executing uefi target code in the test suite, so it's unclear how to fully test efiapi. aapcs could probably be done? (But note that we have hardly an such actually-calling-functions tests for ABI things, we almost entirely rely on codegen tests.)
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)
- rust-lang/reference#1936
> ## 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.File tree
28 files changed
+128
-162
lines changed- compiler
- rustc_abi/src
- rustc_ast_passes
- rustc_feature/src
- rustc_hir_analysis/src
- check
- hir_ty_lowering
- library/std/src
- src/doc/unstable-book/src/language-features
- tests
- codegen-llvm/cffi
- ui
- abi
- c-variadic
- cmse-nonsecure/cmse-nonsecure-entry
- feature-gates
- mir
- parser
28 files changed
+128
-162
lines changedLines changed: 22 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 | + | ||
10 | + | ||
9 | 11 |
| |
10 | 12 |
| |
11 | 13 |
| |
| |||
226 | 228 |
| |
227 | 229 |
| |
228 | 230 |
| |
231 | + | ||
232 | + | ||
233 | + | ||
234 | + | ||
235 | + | ||
236 | + | ||
237 | + | ||
229 | 238 |
| |
230 | 239 |
| |
231 | 240 |
| |
| |||
238 | 247 |
| |
239 | 248 |
| |
240 | 249 |
| |
241 | - | ||
250 | + | ||
251 | + | ||
252 | + | ||
253 | + | ||
254 | + | ||
242 | 255 |
| |
243 | 256 |
| |
244 | 257 |
| |
258 | + | ||
245 | 259 |
| |
246 | 260 |
| |
247 | 261 |
| |
248 | 262 |
| |
249 | 263 |
| |
264 | + | ||
265 | + | ||
250 | 266 |
| |
251 | 267 |
| |
252 | 268 |
| |
253 | 269 |
| |
254 | 270 |
| |
255 | 271 |
| |
256 | - | ||
257 | - | ||
272 | + | ||
273 | + | ||
274 | + | ||
275 | + | ||
276 | + | ||
258 | 277 |
| |
259 | 278 |
| |
260 | 279 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 | + | ||
67 | + | ||
66 | 68 |
| |
67 | 69 |
| |
68 | 70 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
57 | 57 |
| |
58 | 58 |
| |
59 | 59 |
| |
60 | - | ||
60 | + | ||
61 | 61 |
| |
62 | 62 |
| |
63 | 63 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
203 | 203 |
| |
204 | 204 |
| |
205 | 205 |
| |
206 | + | ||
207 | + | ||
208 | + | ||
206 | 209 |
| |
207 | 210 |
| |
208 | 211 |
| |
|
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
492 | 492 |
| |
493 | 493 |
| |
494 | 494 |
| |
495 | - | ||
496 | - | ||
497 | - | ||
498 | 495 |
| |
499 | 496 |
| |
500 | 497 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
978 | 978 |
| |
979 | 979 |
| |
980 | 980 |
| |
981 | - | ||
981 | + | ||
982 | 982 |
| |
983 | 983 |
| |
984 | 984 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
98 | 98 |
| |
99 | 99 |
| |
100 | 100 |
| |
101 | - | ||
101 | + | ||
102 | 102 |
| |
103 | 103 |
| |
104 | 104 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
52 | 52 |
| |
53 | 53 |
| |
54 | 54 |
| |
55 | + | ||
55 | 56 |
| |
56 | 57 |
| |
57 | 58 |
| |
58 | 59 |
| |
59 | - | ||
60 | 60 |
| |
61 | 61 |
| |
62 | 62 |
| |
| |||
2412 | 2412 |
| |
2413 | 2413 |
| |
2414 | 2414 |
| |
2415 | - | ||
2415 | + | ||
2416 | 2416 |
| |
2417 | 2417 |
| |
2418 | 2418 |
| |
|
Lines changed: 23 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
90 | 90 |
| |
91 | 91 |
| |
92 | 92 |
| |
93 | - | ||
93 | + | ||
94 | 94 |
| |
95 | 95 |
| |
96 | 96 |
| |
| |||
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
102 | - | ||
103 | 102 |
| |
104 | 103 |
| |
105 | 104 |
| |
| |||
108 | 107 |
| |
109 | 108 |
| |
110 | 109 |
| |
111 | - | ||
112 | - | ||
113 | - | ||
114 | - | ||
115 | - | ||
116 | - | ||
117 | - | ||
118 | - | ||
110 | + | ||
111 | + | ||
112 | + | ||
119 | 113 |
| |
120 | 114 |
| |
121 | 115 |
| |
122 | - | ||
123 | - | ||
124 | - | ||
125 | - | ||
126 | - | ||
127 | - | ||
128 | - | ||
129 | - | ||
130 | - | ||
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | ||
135 | - | ||
136 | - | ||
137 | - | ||
138 | - | ||
139 | - | ||
140 | - | ||
116 | + | ||
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | ||
121 | + | ||
122 | + | ||
123 | + | ||
124 | + | ||
141 | 125 |
| |
142 | - | ||
143 | - | ||
126 | + | ||
127 | + | ||
128 | + | ||
129 | + | ||
130 | + | ||
131 | + | ||
132 | + | ||
133 | + | ||
134 | + | ||
135 | + | ||
144 | 136 |
| |
145 | - | ||
146 | - | ||
147 | - | ||
148 | - | ||
149 | 137 |
| |
150 | - | ||
151 | 138 |
| |
152 | 139 |
| |
153 | 140 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
290 | 290 |
| |
291 | 291 |
| |
292 | 292 |
| |
293 | - | ||
294 | 293 |
| |
295 | 294 |
| |
296 | 295 |
| |
|
0 commit comments