Skip to content

transpile: fix atomic intrinsics in edition 2024 #1658

Open
kkysen wants to merge 8 commits intomasterfrom
kkysen/transpile-edition-2024-atomics
Open

transpile: fix atomic intrinsics in edition 2024 #1658
kkysen wants to merge 8 commits intomasterfrom
kkysen/transpile-edition-2024-atomics

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Mar 14, 2026

Most of these commits are refactoring things to be in a shape where adding edition 2024 support is simple. Then the last commit, 07c2635, actually adds edition 2024 support.

) -> TranslationResult<WithStmts<Box<Expr>>> {
self.use_feature("core_intrinsics");

// Emit `atomic_cxchg(a0, a1, a2).idx`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these comments I left as is. I'm not sure how to phrase them with edition 2024, and also even with just edition 2021, this leaves out cxchgweak.

kkysen added a commit that referenced this pull request Mar 14, 2026
This fixes the following differences with edition 2024:
* [x] `#[unsafe(no_mangle)]`
* [x] `#[unsafe(export_name = "")]`
* [x] `#[unsafe(link_section = "")]`
* [x] `unsafe extern "C" {`
* [ ] `unsafe fn`s and `safe fn`s in `unsafe extern "C" {}`s
  * not required, default to `unsafe fn`s
* [x] `#![feature(stdsimd)]` removed and split up
* [x] stabilized `#![feature(raw_ref_op)]` removed
* [x] stabilized `#![feature(label_break_value)]` removed
* [x] stabilized `#![feature(asm)]` removed
* [x] `[profile.release] strip = "debuginfo"` being the default
* [ ] (#1658) updated atomic intrinsics (`atomics.c`)
* [ ] `gen` reserved keyword (`keywords.c`)
* [ ] (#1657) updated `VaListImpl` (`varargs.c`)
* [ ] `#[warn(unsafe_op_in_unsafe_fn)]` enabled by default
* In `tests/unit/`, we add `#![allow(unsafe_op_in_unsafe_fn)]` for now.
* Proper fix of an outer `unsafe` block in `unsafe fn`s (or
finer-grained ones) we can do later.
* [ ] (#1656) `pref_align_of` removed
(rust-lang/rust#141803)
  * used to translate `__alignof`
  * no alternative, so may have to drop support

This also runs the correct `rustfmt`, as we were previously just picking
up whichever one `rustup` resolved.

* Fixes #1298.

This updates all of the transpiler snapshot tests and `tests/unit/`
tests that work on edition 2024 with the above fixes. The remaining
fixes I'll fix in separate PRs, as they might be trickier.
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-varargs branch from 5bb5fea to 6ede792 Compare March 14, 2026 06:06
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-atomics branch from 07c2635 to 7cc2ca4 Compare March 14, 2026 06:07
@kkysen kkysen changed the base branch from kkysen/transpile-edition-2024-varargs to master March 14, 2026 06:08
@kkysen kkysen changed the title transpile: add edition 2024 support for atomic intrinsics transpile: fix atomic intrinsics in edition 2024 Mar 14, 2026
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-atomics branch from 7cc2ca4 to b535b6d Compare March 14, 2026 06:09
In edition 2024 (not sure exactly what nightly),
atomic intrinsics became const generic over the `Ordering`.

At the moment, this is re-parsed with `syn::parse_str`
instead of building it with `mk()`/`Builder`.
Codex suggested this because `Builder` doesn't support const generic expressions.
We could add support in `c2rust-ast-builder`, although parsing with `syn` seems simpler to me.
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-atomics branch from b535b6d to 15bb618 Compare March 14, 2026 06:13
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.

1 participant