Unverified Commit cde6fad2 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

refactor(turbo-rcstr): drop unsupported 16-byte pointer width (#98355)

## What?

Removes turbo-rcstr's 16-byte/128-bit pointer representation and the
unused `atom_size_64` feature plumbing. Unsupported pointer widths now
fail with an error that names the supported 32-bit and 64-bit widths.

## Why?

This follows up on review feedback from #97577. The previous negative
cfg made unknown pointer widths fall through to the 64-bit
representation, while the 16-bit implementation and `atom_size_64`
features had no users. Making both supported widths explicit keeps
representation assumptions visible and produces a useful failure for
unsupported targets.

## How?

The narrow tagged-value layout is now specific to 32-bit targets, and
the pointer-sized layout is specific to 64-bit targets. `atom_size_128`
remains unchanged. The dead feature declarations are removed from
turbo-rcstr and its proc-macro crate.

## Verification

- `cargo test -p turbo-rcstr --lib`
- `cargo test -p turbo-rcstr --lib --target wasm32-wasip1-threads`
- `cargo check -p next-napi-bindings`
- `cargo check -p next-napi-bindings --target wasm32-wasip1-threads`
- `cargo clippy -p turbo-rcstr -p turbo-rcstr-macros -- -D warnings`
- `cargo clippy -p turbo-rcstr -p turbo-rcstr-macros --target
wasm32-wasip1-threads -- -D warnings`
- `cargo fmt --all -- --check`

<!-- NEXT_JS_LLM -->

<!-- fleet 7cfc7d6e-efc8-4ef3-b81c-b90f71291bb0 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent d940cd30
...@@ -9,11 +9,10 @@ proc-macro = true ...@@ -9,11 +9,10 @@ proc-macro = true
bench = false bench = false
[features] [features]
# Mirror the threshold-affecting features of `turbo-rcstr`. The consuming # Mirror the threshold-affecting feature of `turbo-rcstr`. The consuming crate
# crate routes them via `turbo-rcstr/atom_size_*` -> `turbo-rcstr-macros/atom_size_*` # routes it via `turbo-rcstr/atom_size_128` -> `turbo-rcstr-macros/atom_size_128`
# so the proc macro can compute the correct `MAX_INLINE_LEN` at expansion time # so the proc macro can compute the correct `MAX_INLINE_LEN` at expansion time
# instead of leaving an ambiguous range that needs a runtime const branch. # instead of leaving an ambiguous range that needs a runtime const branch.
atom_size_64 = []
atom_size_128 = [] atom_size_128 = []
[lints] [lints]
......
...@@ -5,7 +5,6 @@ edition = "2024" ...@@ -5,7 +5,6 @@ edition = "2024"
license = "MIT" license = "MIT"
[features] [features]
atom_size_64 = ["turbo-rcstr-macros/atom_size_64"]
atom_size_128 = ["turbo-rcstr-macros/atom_size_128"] atom_size_128 = ["turbo-rcstr-macros/atom_size_128"]
napi = ["dep:napi"] napi = ["dep:napi"]
......
...@@ -37,18 +37,16 @@ ...@@ -37,18 +37,16 @@
//! Reading the value back as an integer (`get_ptr`, `get_value`, `tag_byte`) only ever happens at //! Reading the value back as an integer (`get_ptr`, `get_value`, `tag_byte`) only ever happens at
//! run time, where pointer → integer is perfectly legal. //! run time, where pointer → integer is perfectly legal.
#[cfg(not(any( #[cfg(not(any(target_pointer_width = "32", feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_64",
feature = "atom_size_128"
)))]
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use std::{num::NonZeroU8, os::raw::c_void, ptr::NonNull, slice}; use std::{num::NonZeroU8, os::raw::c_void, ptr::NonNull, slice};
use self::raw_types::*; use self::raw_types::*;
use crate::TAG_MASK; use crate::TAG_MASK;
#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
compile_error!("turbo-rcstr only supports 32-bit and 64-bit pointer widths");
#[cfg(feature = "atom_size_128")] #[cfg(feature = "atom_size_128")]
mod raw_types { mod raw_types {
pub type RawTaggedValue = u128; pub type RawTaggedValue = u128;
...@@ -57,26 +55,20 @@ mod raw_types { ...@@ -57,26 +55,20 @@ mod raw_types {
/// The narrow-pointer arm: an 8-byte value built from a real pointer plus a byte payload, so that /// The narrow-pointer arm: an 8-byte value built from a real pointer plus a byte payload, so that
/// both constructors stay const-evaluable. See the module docs. /// both constructors stay const-evaluable. See the module docs.
#[cfg(all( #[cfg(all(target_pointer_width = "32", not(feature = "atom_size_128")))]
any(target_pointer_width = "32", target_pointer_width = "16"),
not(feature = "atom_size_128")
))]
mod raw_types { mod raw_types {
use std::ptr::NonNull; use std::ptr::NonNull;
pub type RawTaggedValue = u64; pub type RawTaggedValue = u64;
/// Padding that brings the value up to 8 bytes, sized so that there is none left over. /// Padding that brings the value up to 8 bytes without leaving any implicit padding.
#[cfg(target_pointer_width = "32")]
pub type Payload = [u8; 4]; pub type Payload = [u8; 4];
#[cfg(target_pointer_width = "16")]
pub type Payload = [u8; 6];
// Both layouts are declared unconditionally so that the layout assertions for *both* are // Both layouts are declared unconditionally so that the layout assertions for *both* are
// compiled on every target; only the alias below is conditional. Otherwise the big-endian // compiled on every target; only the alias below is conditional. Otherwise the big-endian
// invariant would never be checked on a little-endian host. // invariant would never be checked on a little-endian host.
// //
// `align(8)` is required, not cosmetic: a pointer field only forces 4-byte (or 2-byte) // `align(8)` is required, not cosmetic: a pointer field only forces 4-byte
// alignment, but the value is read back as a `u64` to extract the tag, and wasm traps on an // alignment, but the value is read back as a `u64` to extract the tag, and wasm traps on an
// unaligned 64-bit load with `RuntimeError: operation does not support unaligned accesses`. // unaligned 64-bit load with `RuntimeError: operation does not support unaligned accesses`.
// Aligning to the width of the integer view keeps that read legal without adding padding. // Aligning to the width of the integer view keeps that read legal without adding padding.
...@@ -131,11 +123,7 @@ mod raw_types { ...@@ -131,11 +123,7 @@ mod raw_types {
); );
} }
#[cfg(not(any( #[cfg(all(target_pointer_width = "64", not(feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_128"
)))]
mod raw_types { mod raw_types {
pub type RawTaggedValue = usize; pub type RawTaggedValue = usize;
pub type RawTaggedNonZeroValue = std::ptr::NonNull<()>; pub type RawTaggedNonZeroValue = std::ptr::NonNull<()>;
...@@ -167,10 +155,7 @@ impl TaggedValue { ...@@ -167,10 +155,7 @@ impl TaggedValue {
pub const fn new_ptr<T>(value: NonNull<T>) -> Self { pub const fn new_ptr<T>(value: NonNull<T>) -> Self {
// A pointer → pointer cast, which const evaluation permits. See the module docs for why // A pointer → pointer cast, which const evaluation permits. See the module docs for why
// the narrow-pointer arm cannot store a bare integer here. // the narrow-pointer arm cannot store a bare integer here.
#[cfg(all( #[cfg(all(target_pointer_width = "32", not(feature = "atom_size_128")))]
any(target_pointer_width = "32", target_pointer_width = "16"),
not(feature = "atom_size_128")
))]
{ {
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
{ {
...@@ -202,11 +187,7 @@ impl TaggedValue { ...@@ -202,11 +187,7 @@ impl TaggedValue {
} }
} }
#[cfg(not(any( #[cfg(all(target_pointer_width = "64", not(feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_128"
)))]
{ {
Self { Self {
value: value.cast(), value: value.cast(),
...@@ -216,12 +197,7 @@ impl TaggedValue { ...@@ -216,12 +197,7 @@ impl TaggedValue {
#[inline(always)] #[inline(always)]
pub const fn new_tag(value: NonZeroU8) -> Self { pub const fn new_tag(value: NonZeroU8) -> Self {
#[cfg(not(any( #[cfg(not(any(target_pointer_width = "32", feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_64",
feature = "atom_size_128"
)))]
{ {
// A provenance-free integer → pointer conversion for the pointer representation. // A provenance-free integer → pointer conversion for the pointer representation.
Self { Self {
...@@ -230,12 +206,7 @@ impl TaggedValue { ...@@ -230,12 +206,7 @@ impl TaggedValue {
), ),
} }
} }
#[cfg(any( #[cfg(any(target_pointer_width = "32", feature = "atom_size_128"))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_64",
feature = "atom_size_128"
))]
{ {
// An integer → pointer transmute, which const evaluation permits. // An integer → pointer transmute, which const evaluation permits.
let value = value.get() as RawTaggedValue; let value = value.get() as RawTaggedValue;
...@@ -250,10 +221,7 @@ impl TaggedValue { ...@@ -250,10 +221,7 @@ impl TaggedValue {
#[inline(always)] #[inline(always)]
pub fn get_ptr(&self) -> *const c_void { pub fn get_ptr(&self) -> *const c_void {
#[cfg(all( #[cfg(all(target_pointer_width = "32", not(feature = "atom_size_128")))]
any(target_pointer_width = "32", target_pointer_width = "16"),
not(feature = "atom_size_128")
))]
{ {
// The tag lives in the low bits of the pointer itself (`DYNAMIC_TAG` sets one), so // The tag lives in the low bits of the pointer itself (`DYNAMIC_TAG` sets one), so
// mask it before use — otherwise a dynamic string's `Arc` is dereferenced two bytes // mask it before use — otherwise a dynamic string's `Arc` is dereferenced two bytes
...@@ -265,11 +233,7 @@ impl TaggedValue { ...@@ -265,11 +233,7 @@ impl TaggedValue {
{ {
(self.value.get() as usize & !(TAG_MASK as usize)) as _ (self.value.get() as usize & !(TAG_MASK as usize)) as _
} }
#[cfg(not(any( #[cfg(not(any(target_pointer_width = "32", feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_128"
)))]
{ {
self.value self.value
.as_ptr() .as_ptr()
...@@ -281,36 +245,20 @@ impl TaggedValue { ...@@ -281,36 +245,20 @@ impl TaggedValue {
#[inline(always)] #[inline(always)]
fn get_value(&self) -> RawTaggedValue { fn get_value(&self) -> RawTaggedValue {
#[cfg(not(any( #[cfg(not(any(target_pointer_width = "32", feature = "atom_size_128")))]
target_pointer_width = "32",
target_pointer_width = "16",
feature = "atom_size_64",
feature = "atom_size_128"
)))]
{ {
// Read the pointer representation's address without exposing provenance. // Read the pointer representation's address without exposing provenance.
self.value.addr().get() self.value.addr().get()
} }
#[cfg(all( #[cfg(all(target_pointer_width = "32", not(feature = "atom_size_128")))]
any(target_pointer_width = "32", target_pointer_width = "16"),
not(feature = "atom_size_128")
))]
{ {
// The layout is guaranteed padding-free and 8-aligned above, so reading the whole // The layout is guaranteed padding-free and 8-aligned above, so reading the whole
// value as an integer is well defined. Again, run time only. // value as an integer is well defined. Again, run time only.
unsafe { std::mem::transmute::<RawTaggedNonZeroValue, RawTaggedValue>(self.value) } unsafe { std::mem::transmute::<RawTaggedNonZeroValue, RawTaggedValue>(self.value) }
} }
#[cfg(all( #[cfg(all(
any( any(target_pointer_width = "32", feature = "atom_size_128"),
target_pointer_width = "32", not(all(target_pointer_width = "32", not(feature = "atom_size_128")))
target_pointer_width = "16",
feature = "atom_size_64",
feature = "atom_size_128"
),
not(all(
any(target_pointer_width = "32", target_pointer_width = "16"),
not(feature = "atom_size_128")
))
))] ))]
{ {
unsafe { unsafe {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment