Skip to content

Commit

Permalink
fix: correct layout calculation with folding tags. [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jul 28, 2024
1 parent 7363a62 commit 671d536
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 93 deletions.
16 changes: 8 additions & 8 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const _: () = {
assert!(align_of::<ArrayPattern<'static>>() == 8usize);
assert!(size_of::<BindingRestElement<'static>>() == 40usize);
assert!(align_of::<BindingRestElement<'static>>() == 8usize);
assert!(size_of::<Function<'static>>() == 144usize);
assert!(size_of::<Function<'static>>() == 136usize);
assert!(align_of::<Function<'static>>() == 8usize);
assert!(size_of::<FunctionType>() == 4usize);
assert!(align_of::<FunctionType>() == 4usize);
Expand Down Expand Up @@ -374,11 +374,11 @@ const _: () = {
assert!(align_of::<TSSignature<'static>>() == 8usize);
assert!(size_of::<TSIndexSignature<'static>>() == 56usize);
assert!(align_of::<TSIndexSignature<'static>>() == 8usize);
assert!(size_of::<TSCallSignatureDeclaration<'static>>() == 80usize);
assert!(size_of::<TSCallSignatureDeclaration<'static>>() == 72usize);
assert!(align_of::<TSCallSignatureDeclaration<'static>>() == 8usize);
assert!(size_of::<TSMethodSignatureKind>() == 4usize);
assert!(align_of::<TSMethodSignatureKind>() == 4usize);
assert!(size_of::<TSMethodSignature<'static>>() == 112usize);
assert!(size_of::<TSMethodSignature<'static>>() == 104usize);
assert!(align_of::<TSMethodSignature<'static>>() == 8usize);
assert!(size_of::<TSConstructSignatureDeclaration<'static>>() == 40usize);
assert!(align_of::<TSConstructSignatureDeclaration<'static>>() == 8usize);
Expand Down Expand Up @@ -416,7 +416,7 @@ const _: () = {
assert!(align_of::<TSImportAttribute<'static>>() == 8usize);
assert!(size_of::<TSImportAttributeName<'static>>() == 32usize);
assert!(align_of::<TSImportAttributeName<'static>>() == 8usize);
assert!(size_of::<TSFunctionType<'static>>() == 80usize);
assert!(size_of::<TSFunctionType<'static>>() == 72usize);
assert!(align_of::<TSFunctionType<'static>>() == 8usize);
assert!(size_of::<TSConstructorType<'static>>() == 40usize);
assert!(align_of::<TSConstructorType<'static>>() == 8usize);
Expand Down Expand Up @@ -699,7 +699,7 @@ const _: () = {
assert!(align_of::<ArrayPattern<'static>>() == 4usize);
assert!(size_of::<BindingRestElement<'static>>() == 24usize);
assert!(align_of::<BindingRestElement<'static>>() == 4usize);
assert!(size_of::<Function<'static>>() == 92usize);
assert!(size_of::<Function<'static>>() == 88usize);
assert!(align_of::<Function<'static>>() == 4usize);
assert!(size_of::<FunctionType>() == 4usize);
assert!(align_of::<FunctionType>() == 4usize);
Expand Down Expand Up @@ -871,11 +871,11 @@ const _: () = {
assert!(align_of::<TSSignature<'static>>() == 4usize);
assert!(size_of::<TSIndexSignature<'static>>() == 32usize);
assert!(align_of::<TSIndexSignature<'static>>() == 4usize);
assert!(size_of::<TSCallSignatureDeclaration<'static>>() == 52usize);
assert!(size_of::<TSCallSignatureDeclaration<'static>>() == 48usize);
assert!(align_of::<TSCallSignatureDeclaration<'static>>() == 4usize);
assert!(size_of::<TSMethodSignatureKind>() == 4usize);
assert!(align_of::<TSMethodSignatureKind>() == 4usize);
assert!(size_of::<TSMethodSignature<'static>>() == 76usize);
assert!(size_of::<TSMethodSignature<'static>>() == 72usize);
assert!(align_of::<TSMethodSignature<'static>>() == 4usize);
assert!(size_of::<TSConstructSignatureDeclaration<'static>>() == 28usize);
assert!(align_of::<TSConstructSignatureDeclaration<'static>>() == 4usize);
Expand Down Expand Up @@ -913,7 +913,7 @@ const _: () = {
assert!(align_of::<TSImportAttribute<'static>>() == 4usize);
assert!(size_of::<TSImportAttributeName<'static>>() == 20usize);
assert!(align_of::<TSImportAttributeName<'static>>() == 4usize);
assert!(size_of::<TSFunctionType<'static>>() == 52usize);
assert!(size_of::<TSFunctionType<'static>>() == 48usize);
assert!(align_of::<TSFunctionType<'static>>() == 4usize);
assert!(size_of::<TSConstructorType<'static>>() == 24usize);
assert!(align_of::<TSConstructorType<'static>>() == 4usize);
Expand Down
50 changes: 25 additions & 25 deletions tasks/ast_codegen/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub struct StructDef {
pub has_lifetime: bool,
pub size_64: usize,
pub align_64: usize,
pub headroom_64: u128,
pub headroom_64: usize,
pub size_32: usize,
pub align_32: usize,
pub headroom_32: u128,
pub headroom_32: usize,
}

#[derive(Debug, Serialize)]
Expand All @@ -40,10 +40,10 @@ pub struct EnumDef {
pub has_lifetime: bool,
pub size_64: usize,
pub align_64: usize,
pub headroom_64: u128,
pub headroom_64: usize,
pub size_32: usize,
pub align_32: usize,
pub headroom_32: u128,
pub headroom_32: usize,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -76,26 +76,18 @@ impl From<&RType> for Option<TypeDef> {
}
}

macro_rules! unpack_layouts {
($it:ident) => {{
let KnownLayout { align: align_32, size: size_32, headroom: headroom_32 } = $it
.meta
.layout_32
.layout()
.expect(format!("Uncalculated layout on {}!", $it.item.ident.to_string()).as_str());
let KnownLayout { align: align_64, size: size_64, headroom: headroom_64 } = $it
.meta
.layout_64
.layout()
.expect(format!("Uncalculated layout on {}!", $it.item.ident.to_string()).as_str());
((size_64, align_64, headroom_64), (size_32, align_32, headroom_32))
}};
}

impl From<&REnum> for EnumDef {
fn from(it @ REnum { item, meta }: &REnum) -> Self {
let ((size_64, align_64, headroom_64), (size_32, align_32, headroom_32)) =
unpack_layouts!(it);
let (size_64, align_64, headroom_64) = meta
.layout_64
.layout()
.map(|it| it.unpack())
.expect(format!("Uncalculated layout on {}!", item.ident.to_string()).as_str());
let (size_32, align_32, headroom_32) = meta
.layout_32
.layout()
.map(|it| it.unpack())
.expect(format!("Uncalculated layout on {}!", item.ident.to_string()).as_str());
Self {
name: it.ident().to_string(),
variants: item.variants.iter().map(Into::into).collect(),
Expand All @@ -113,9 +105,17 @@ impl From<&REnum> for EnumDef {
}

impl From<&RStruct> for StructDef {
fn from(it @ RStruct { item, .. }: &RStruct) -> Self {
let ((size_64, align_64, headroom_64), (size_32, align_32, headroom_32)) =
unpack_layouts!(it);
fn from(it @ RStruct { item, meta }: &RStruct) -> Self {
let (size_64, align_64, headroom_64) = meta
.layout_64
.layout()
.map(|it| it.unpack())
.expect(format!("Uncalculated layout on {}!", item.ident.to_string()).as_str());
let (size_32, align_32, headroom_32) = meta
.layout_32
.layout()
.map(|it| it.unpack())
.expect(format!("Uncalculated layout on {}!", item.ident.to_string()).as_str());
Self {
name: it.ident().to_string(),
fields: item.fields.iter().map(Into::into).collect(),
Expand Down
Loading

0 comments on commit 671d536

Please sign in to comment.