Skip to content

Commit bc1bcdd

Browse files
committed
perf(napi/parser, linter/plugins): inline trivial raw transfer field deserializers into node object definitions (#21134)
Utilize the `#[estree(raw_deser_inline)]` attribute introduced in #21134 to mark all custom deserializers which do not depend on `parent` as inline-able. This reduces deserializer code size, as well as being more performant in some cases, by avoiding write boundary checks.
1 parent 7b3d5a9 commit bc1bcdd

14 files changed

Lines changed: 902 additions & 1489 deletions

File tree

apps/oxlint/src-js/generated/deserialize.js

Lines changed: 138 additions & 227 deletions
Large diffs are not rendered by default.

crates/oxc_ast/src/serialize/basic.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use oxc_estree::{ESTree, JsonSafeString, Serializer};
33

44
/// Serialized as `null`.
55
#[ast_meta]
6-
#[estree(ts_type = "null", raw_deser = "null")]
6+
#[estree(ts_type = "null", raw_deser = "null", raw_deser_inline)]
77
pub struct Null<T>(pub T);
88

99
impl<T> ESTree for Null<T> {
@@ -14,7 +14,7 @@ impl<T> ESTree for Null<T> {
1414

1515
/// Serialized as `null`. Field only present in TS-ESTree AST.
1616
#[ast_meta]
17-
#[estree(ts_type = "null", raw_deser = "null")]
17+
#[estree(ts_type = "null", raw_deser = "null", raw_deser_inline)]
1818
#[ts]
1919
pub struct TsNull<T>(pub T);
2020

@@ -26,7 +26,7 @@ impl<T> ESTree for TsNull<T> {
2626

2727
/// Serialized as `true`.
2828
#[ast_meta]
29-
#[estree(ts_type = "true", raw_deser = "true")]
29+
#[estree(ts_type = "true", raw_deser = "true", raw_deser_inline)]
3030
pub struct True<T>(pub T);
3131

3232
impl<T> ESTree for True<T> {
@@ -37,7 +37,7 @@ impl<T> ESTree for True<T> {
3737

3838
/// Serialized as `false`.
3939
#[ast_meta]
40-
#[estree(ts_type = "false", raw_deser = "false")]
40+
#[estree(ts_type = "false", raw_deser = "false", raw_deser_inline)]
4141
pub struct False<T>(pub T);
4242

4343
impl<T> ESTree for False<T> {
@@ -48,7 +48,7 @@ impl<T> ESTree for False<T> {
4848

4949
/// Serialized as `false`. Field only present in JS ESTree AST (not TS-ESTree).
5050
#[ast_meta]
51-
#[estree(ts_type = "false", raw_deser = "false")]
51+
#[estree(ts_type = "false", raw_deser = "false", raw_deser_inline)]
5252
#[js_only]
5353
pub struct JsFalse<T>(pub T);
5454

@@ -60,7 +60,7 @@ impl<T> ESTree for JsFalse<T> {
6060

6161
/// Serialized as `false`. Field only present in TS-ESTree AST.
6262
#[ast_meta]
63-
#[estree(ts_type = "false", raw_deser = "false")]
63+
#[estree(ts_type = "false", raw_deser = "false", raw_deser_inline)]
6464
#[ts]
6565
pub struct TsFalse<T>(pub T);
6666

@@ -72,7 +72,7 @@ impl<T> ESTree for TsFalse<T> {
7272

7373
/// Serialized as `"value"`.
7474
#[ast_meta]
75-
#[estree(ts_type = "'value'", raw_deser = "'value'")]
75+
#[estree(ts_type = "'value'", raw_deser = "'value'", raw_deser_inline)]
7676
#[ts]
7777
pub struct TsValue<T>(pub T);
7878

@@ -84,7 +84,7 @@ impl<T> ESTree for TsValue<T> {
8484

8585
/// Serialized as `"in"`.
8686
#[ast_meta]
87-
#[estree(ts_type = "'in'", raw_deser = "'in'")]
87+
#[estree(ts_type = "'in'", raw_deser = "'in'", raw_deser_inline)]
8888
pub struct In<T>(pub T);
8989

9090
impl<T> ESTree for In<T> {
@@ -95,7 +95,7 @@ impl<T> ESTree for In<T> {
9595

9696
/// Serialized as `"init"`.
9797
#[ast_meta]
98-
#[estree(ts_type = "'init'", raw_deser = "'init'")]
98+
#[estree(ts_type = "'init'", raw_deser = "'init'", raw_deser_inline)]
9999
pub struct Init<T>(pub T);
100100

101101
impl<T> ESTree for Init<T> {
@@ -106,7 +106,7 @@ impl<T> ESTree for Init<T> {
106106

107107
/// Serialized as `"this"`.
108108
#[ast_meta]
109-
#[estree(ts_type = "'this'", raw_deser = "'this'")]
109+
#[estree(ts_type = "'this'", raw_deser = "'this'", raw_deser_inline)]
110110
pub struct This<T>(pub T);
111111

112112
impl<T> ESTree for This<T> {
@@ -117,7 +117,7 @@ impl<T> ESTree for This<T> {
117117

118118
/// Serialized as `"global"`.
119119
#[ast_meta]
120-
#[estree(ts_type = "'global'", raw_deser = "'global'")]
120+
#[estree(ts_type = "'global'", raw_deser = "'global'", raw_deser_inline)]
121121
pub struct Global<T>(pub T);
122122

123123
impl<T> ESTree for Global<T> {
@@ -128,7 +128,7 @@ impl<T> ESTree for Global<T> {
128128

129129
/// Serialized as `[]`.
130130
#[ast_meta]
131-
#[estree(ts_type = "[]", raw_deser = "[]")]
131+
#[estree(ts_type = "[]", raw_deser = "[]", raw_deser_inline)]
132132
pub struct EmptyArray<T>(pub T);
133133

134134
impl<T> ESTree for EmptyArray<T> {
@@ -139,7 +139,7 @@ impl<T> ESTree for EmptyArray<T> {
139139

140140
/// Serialized as `[]`. Field only present in JS ESTree AST (not TS-ESTree).
141141
#[ast_meta]
142-
#[estree(ts_type = "[]", raw_deser = "[]")]
142+
#[estree(ts_type = "[]", raw_deser = "[]", raw_deser_inline)]
143143
#[js_only]
144144
pub struct JsEmptyArray<T>(pub T);
145145

@@ -151,7 +151,7 @@ impl<T> ESTree for JsEmptyArray<T> {
151151

152152
/// Serialized as `[]`. Field only present in TS-ESTree AST.
153153
#[ast_meta]
154-
#[estree(ts_type = "[]", raw_deser = "[]")]
154+
#[estree(ts_type = "[]", raw_deser = "[]", raw_deser_inline)]
155155
#[ts]
156156
pub struct TsEmptyArray<T>(pub T);
157157

crates/oxc_ast/src/serialize/jsx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl ESTree for JSXElementOpeningElement<'_, '_> {
4242
/// This type is only required to add `selfClosing: boolean` to TS type def,
4343
/// and provide default value of `false` for raw transfer deserializer.
4444
#[ast_meta]
45-
#[estree(ts_type = "boolean", raw_deser = "false")]
45+
#[estree(ts_type = "boolean", raw_deser = "false", raw_deser_inline)]
4646
pub struct JSXOpeningElementSelfClosing<'a, 'b>(#[expect(dead_code)] pub &'b JSXOpeningElement<'a>);
4747

4848
impl ESTree for JSXOpeningElementSelfClosing<'_, '_> {

crates/oxc_ast/src/serialize/literal.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl ESTree for BooleanLiteralRaw<'_> {
3636
#[ast_meta]
3737
#[estree(
3838
ts_type = "'null' | null",
39-
raw_deser = "(THIS.start === 0 && THIS.end === 0) ? null : 'null'"
39+
raw_deser = "(THIS.start === 0 && THIS.end === 0) ? null : 'null'",
40+
raw_deser_inline
4041
)]
4142
pub struct NullLiteralRaw<'b>(pub &'b NullLiteral);
4243

@@ -100,7 +101,8 @@ impl StringLiteralValue<'_, '_> {
100101
raw_deser = "
101102
const bigint = DESER[Str](POS_OFFSET.value);
102103
BigInt(bigint)
103-
"
104+
",
105+
raw_deser_inline
104106
)]
105107
pub struct BigIntLiteralValue<'a, 'b>(#[expect(dead_code)] pub &'b BigIntLiteral<'a>);
106108

@@ -118,7 +120,7 @@ impl ESTree for BigIntLiteralValue<'_, '_> {
118120
///
119121
/// `bigint` var in `raw_deser` comes from `BigIntLiteralValue` serializer.
120122
#[ast_meta]
121-
#[estree(ts_type = "string", raw_deser = "bigint")]
123+
#[estree(ts_type = "string", raw_deser = "bigint", raw_deser_inline)]
122124
pub struct BigIntLiteralBigint<'a, 'b>(pub &'b BigIntLiteral<'a>);
123125

124126
impl ESTree for BigIntLiteralBigint<'_, '_> {

crates/oxc_ast/src/serialize/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ fn get_ts_start_span(program: &Program<'_>) -> u32 {
246246
#[ast_meta]
247247
#[estree(
248248
ts_type = "string",
249-
raw_deser = "SOURCE_TEXT.slice(THIS.start + 2, THIS.end - (THIS.type === 'Line' ? 0 : 2))"
249+
raw_deser = "SOURCE_TEXT.slice(THIS.start + 2, THIS.end - (THIS.type === 'Line' ? 0 : 2))",
250+
raw_deser_inline
250251
)]
251252
pub struct CommentValue<'b>(#[expect(dead_code)] pub &'b Comment);
252253

crates/oxc_ast/src/serialize/ts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::Null;
1515
// TODO: Not ideal to have to include the enum discriminant's value here explicitly.
1616
// Need a "macro" e.g. `ENUM_MATCHES(id, ComputedString | ComputedTemplateString)`.
1717
#[ast_meta]
18-
#[estree(ts_type = "boolean", raw_deser = "DESER[u8](POS_OFFSET.id) > 1")]
18+
#[estree(ts_type = "boolean", raw_deser = "DESER[u8](POS_OFFSET.id) > 1", raw_deser_inline)]
1919
pub struct TSEnumMemberComputed<'a, 'b>(pub &'b TSEnumMember<'a>);
2020

2121
impl ESTree for TSEnumMemberComputed<'_, '_> {
@@ -32,7 +32,7 @@ impl ESTree for TSEnumMemberComputed<'_, '_> {
3232
///
3333
/// This field is always `null`, and only appears in the TS-ESTree AST, not JS ESTree.
3434
#[ast_meta]
35-
#[estree(ts_type = "string | null", raw_deser = "null")]
35+
#[estree(ts_type = "string | null", raw_deser = "null", raw_deser_inline)]
3636
#[ts]
3737
pub struct ExpressionStatementDirective<'a, 'b>(
3838
#[expect(dead_code)] pub &'b ExpressionStatement<'a>,

0 commit comments

Comments
 (0)