Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/ast): Fix memory layout #7062

Merged
merged 14 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ pub enum Expr {
Invalid(Invalid),
}

#[cfg(target_pointer_width = "64")]
assert_eq_size!(Expr, [u8; 80]);
// Memory layout depedns on the version of rustc.
// #[cfg(target_pointer_width = "64")]
// assert_eq_size!(Expr, [u8; 80]);

impl Expr {
/// Normalize parenthesized expressions.
Expand Down
9 changes: 0 additions & 9 deletions crates/swc_ecma_ast/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,3 @@ macro_rules! bridge_decl_from {
bridge_from!(crate::ModuleItem, crate::Stmt, $src);
};
}

/// Copied from static_assertions
macro_rules! assert_eq_size {
($x:ty, $($xs:ty),+ $(,)?) => {
const _: fn() = || {
$(let _ = std::mem::transmute::<$x, $xs>;)+
};
};
}
9 changes: 5 additions & 4 deletions crates/swc_ecma_ast/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ pub enum Stmt {
Expr(ExprStmt),
}

#[cfg(target_pointer_width = "64")]
assert_eq_size!(Stmt, [u8; 64]);
// Memory layout depedns on the version of rustc.
// #[cfg(target_pointer_width = "64")]
// assert_eq_size!(Stmt, [u8; 56]);

// Implement Clone without inline to avoid multiple copies of the
// implementation.
Expand Down Expand Up @@ -318,7 +319,7 @@ pub struct ForOfStmt {
///
/// for-await-of statements, e.g., `for await (const x of xs) {`
#[serde(default, rename = "await")]
pub await_token: Option<Span>,
pub is_await: bool,
pub left: VarDeclOrPat,
pub right: Box<Expr>,
pub body: Box<Stmt>,
Expand All @@ -328,7 +329,7 @@ impl Take for ForOfStmt {
fn dummy() -> Self {
ForOfStmt {
span: DUMMY_SP,
await_token: Default::default(),
is_await: Default::default(),
left: Take::dummy(),
right: Take::dummy(),
body: Take::dummy(),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3186,7 +3186,7 @@ where

keyword!("for");

if n.await_token.is_some() {
if n.is_await {
space!();
keyword!("await");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_lints/src/rules/no_await_in_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Visit for NoAwaitInLoop {
for_of_stmt.left.visit_children_with(self);
for_of_stmt.right.visit_children_with(self);

self.await_restricted = for_of_stmt.await_token.is_none();
self.await_restricted = !for_of_stmt.is_await;

for_of_stmt.body.visit_children_with(self);

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ impl<'a, I: Tokens> Parser<I> {
}
ForHead::ForOf { left, right } => Stmt::ForOf(ForOfStmt {
span,
await_token,
is_await: await_token.is_some(),
left,
right,
body,
Expand Down Expand Up @@ -1419,7 +1419,7 @@ mod tests {
stmt("for await (const a of b) ;"),
Stmt::ForOf(ForOfStmt {
span,
await_token: Some(span),
is_await: true,
left: VarDeclOrPat::VarDecl(Box::new(VarDecl {
span,
kind: VarDeclKind::Const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 37,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 41,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"end": 72,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"end": 72,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of1.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 74,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of10.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"end": 113,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "MemberExpression",
"span": {
Expand Down Expand Up @@ -152,7 +152,7 @@
"end": 111,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "MemberExpression",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of11.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"end": 25,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "Identifier",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of12.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 25,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "ArrayPattern",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of13.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 69,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of14.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 39,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of15.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 80,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"end": 78,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of16.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 91,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"end": 89,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of17.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 92,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"end": 90,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of18.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 29,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -92,7 +92,7 @@
"end": 58,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of19.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 111,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -117,7 +117,7 @@
"end": 103,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 37,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/tests/tsc/ES5For-of21.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 49,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down Expand Up @@ -71,7 +71,7 @@
"end": 47,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of22.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 65,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of23.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 65,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of24.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"end": 55,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of25.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"end": 73,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of26.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 72,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of27.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 59,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of28.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 53,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of29.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 61,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of3.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"end": 65,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "VariableDeclaration",
"span": {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/tests/tsc/ES5For-of30.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"end": 115,
"ctxt": 0
},
"await": null,
"await": false,
"left": {
"type": "ArrayPattern",
"span": {
Expand Down
Loading