Skip to content

Commit ab51394

Browse files
committed
fix(raw_transfer): disable layout assertions on some 32-bit platforms (#13716)
Fixes #13694. Some 32-bit platforms give `u64` and `f64` alignment of 8, and others alignment of 4. WASM32 uses alignment 8, and layout calculator assumes that. Skip layout assertions for platforms where alignment is 4, because we know some layouts are wrong for those platforms, and it causes compilation failure in debug builds. But retain the assertions for other 32-bit platforms (notably WASM), to make sure they remain correct. This will make it easier to extend raw transfer support to WASM later on.
1 parent 6dd4107 commit ab51394

File tree

8 files changed

+19
-8
lines changed

8 files changed

+19
-8
lines changed

crates/oxc_allocator/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const _: () = {
1818
};
1919

2020
#[cfg(target_pointer_width = "32")]
21-
const _: () = {
21+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
2222
// Padding: 3 bytes
2323
assert!(size_of::<FixedSizeAllocatorMetadata>() == 12);
2424
assert!(align_of::<FixedSizeAllocatorMetadata>() == 4);

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ const _: () = {
16121612
};
16131613

16141614
#[cfg(target_pointer_width = "32")]
1615-
const _: () = {
1615+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
16161616
// Padding: 1 bytes
16171617
assert!(size_of::<Program>() == 88);
16181618
assert!(align_of::<Program>() == 4);

crates/oxc_linter/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const _: () = {
1818
};
1919

2020
#[cfg(target_pointer_width = "32")]
21-
const _: () = {
21+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
2222
// Padding: 3 bytes
2323
assert!(size_of::<RawTransferMetadata2>() == 16);
2424
assert!(align_of::<RawTransferMetadata2>() == 8);

crates/oxc_regular_expression/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const _: () = {
166166
};
167167

168168
#[cfg(target_pointer_width = "32")]
169-
const _: () = {
169+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
170170
// Padding: 0 bytes
171171
assert!(size_of::<Pattern>() == 32);
172172
assert!(align_of::<Pattern>() == 4);

crates/oxc_span/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const _: () = {
3333
};
3434

3535
#[cfg(target_pointer_width = "32")]
36-
const _: () = {
36+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
3737
// Padding: 0 bytes
3838
assert!(size_of::<Span>() == 8);
3939
assert!(align_of::<Span>() == 4);

crates/oxc_syntax/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const _: () = {
100100
};
101101

102102
#[cfg(target_pointer_width = "32")]
103-
const _: () = {
103+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
104104
// Padding: 0 bytes
105105
assert!(size_of::<NonMaxU32>() == 4);
106106
assert!(align_of::<NonMaxU32>() == 4);

napi/parser/src/generated/assert_layouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const _: () = {
6666
};
6767

6868
#[cfg(target_pointer_width = "32")]
69-
const _: () = {
69+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
7070
// Padding: 0 bytes
7171
assert!(size_of::<RawTransferData>() == 188);
7272
assert!(align_of::<RawTransferData>() == 4);

tasks/ast_tools/src/generators/assert_layouts.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,20 @@ fn template(krate: &str, assertions_64: &TokenStream, assertions_32: &TokenStrea
684684
#[cfg(target_pointer_width = "64")]
685685
const _: () = { #assertions_64 };
686686

687+
// Some 32-bit platforms have 8-byte alignment for `u64` and `f64`, while others have 4-byte alignment.
688+
//
689+
// Skip these assertions on 32-bit platforms where `u64` / `f64` have 4-byte alignment, because
690+
// some layout calculations may be incorrect. https://github.com/oxc-project/oxc/issues/13694
691+
//
692+
// At present 32-bit layouts aren't relied on by any code, so it's fine if they're incorrect for now.
693+
// However, raw transfer will be supported on WASM32 in future, and layout calculations are correct
694+
// for WASM32 at present. So keep these assertions for WASM, to ensure changes to AST or this codegen
695+
// don't break anything.
687696
///@@line_break
688697
#[cfg(target_pointer_width = "32")]
689-
const _: () = { #assertions_32 };
698+
const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
699+
#assertions_32
700+
};
690701

691702
///@@line_break
692703
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]

0 commit comments

Comments
 (0)