Skip to content

Commit

Permalink
feat(es/ast): Expose Archived types (#7811)
Browse files Browse the repository at this point in the history
**Description:**

For crates using both `rkyv` and `swc`, where ast nodes from
`swc_ecma_ast` are included in data that's serialized with `rkyv`, it's
difficult to access the archived data from the archived ast nodes since
the types are private.

More context in the issue.

**Related issue:**

 - Closes #7810.
  • Loading branch information
JQuezada0 authored Aug 16, 2023
1 parent 023042d commit 478fa47
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/swc_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ pub mod util;

#[cfg(all(not(debug_assertions), feature = "plugin-rt", feature = "plugin-mode"))]
compile_error!("You can't enable `plugin-rt` and `plugin-mode` at the same time");

/// Warning: The particular implementation of serialization and deserialization
/// of the ast nodes may change in the future, and so these types would be
/// removed. It's safe to say they will be serializable in some form or another,
/// but not necessarily with these specific types underlying the implementation.
/// As such, *use these types at your own risk*.
#[cfg(feature = "rkyv-impl")]
#[doc(hidden)]
pub use self::syntax_pos::{
ArchivedBytePos, ArchivedCharPos, ArchivedFileName, ArchivedMultiSpan, ArchivedSourceFile,
ArchivedSourceFileAndBytePos, ArchivedSpan, ArchivedSpanLinesError, ArchivedSpanSnippetError,
};
97 changes: 97 additions & 0 deletions crates/swc_ecma_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,100 @@ impl Default for EsVersion {
EsVersion::Es5
}
}

/// Warning: The particular implementation of serialization and deserialization
/// of the ast nodes may change in the future, and so these types would be
/// removed. It's safe to say they will be serializable in some form or another,
/// but not necessarily with these specific types underlying the implementation.
/// As such, *use these types at your own risk*.
#[cfg(feature = "rkyv-impl")]
#[doc(hidden)]
pub use self::{
class::{
ArchivedAutoAccessor, ArchivedClass, ArchivedClassMember, ArchivedClassMethod,
ArchivedClassProp, ArchivedConstructor, ArchivedDecorator, ArchivedKey, ArchivedMethodKind,
ArchivedPrivateMethod, ArchivedPrivateProp, ArchivedStaticBlock,
},
decl::{
ArchivedClassDecl, ArchivedDecl, ArchivedFnDecl, ArchivedUsingDecl, ArchivedVarDecl,
ArchivedVarDeclKind, ArchivedVarDeclarator,
},
expr::{
ArchivedArrayLit, ArchivedArrowExpr, ArchivedAssignExpr, ArchivedAwaitExpr,
ArchivedBinExpr, ArchivedBlockStmtOrExpr, ArchivedCallExpr, ArchivedCallee,
ArchivedClassExpr, ArchivedCondExpr, ArchivedExpr, ArchivedExprOrSpread, ArchivedFnExpr,
ArchivedImport, ArchivedMemberExpr, ArchivedMemberProp, ArchivedMetaPropExpr,
ArchivedMetaPropKind, ArchivedNewExpr, ArchivedObjectLit, ArchivedOptCall,
ArchivedOptChainBase, ArchivedOptChainExpr, ArchivedParenExpr, ArchivedPatOrExpr,
ArchivedPropOrSpread, ArchivedSeqExpr, ArchivedSpreadElement, ArchivedSuper,
ArchivedSuperProp, ArchivedSuperPropExpr, ArchivedTaggedTpl, ArchivedThisExpr, ArchivedTpl,
ArchivedTplElement, ArchivedUnaryExpr, ArchivedUpdateExpr, ArchivedYieldExpr,
},
function::{ArchivedFunction, ArchivedParam, ArchivedParamOrTsParamProp},
ident::{ArchivedBindingIdent, ArchivedIdent, ArchivedPrivateName},
jsx::{
ArchivedJSXAttr, ArchivedJSXAttrName, ArchivedJSXAttrOrSpread, ArchivedJSXAttrValue,
ArchivedJSXClosingElement, ArchivedJSXClosingFragment, ArchivedJSXElement,
ArchivedJSXElementChild, ArchivedJSXElementName, ArchivedJSXEmptyExpr, ArchivedJSXExpr,
ArchivedJSXExprContainer, ArchivedJSXFragment, ArchivedJSXMemberExpr,
ArchivedJSXNamespacedName, ArchivedJSXObject, ArchivedJSXOpeningElement,
ArchivedJSXOpeningFragment, ArchivedJSXSpreadChild, ArchivedJSXText,
},
lit::{
ArchivedBigInt, ArchivedBool, ArchivedLit, ArchivedNull, ArchivedNumber, ArchivedRegex,
ArchivedStr,
},
module::{
ArchivedModule, ArchivedModuleItem, ArchivedProgram, ArchivedReservedUnused, ArchivedScript,
},
module_decl::{
ArchivedDefaultDecl, ArchivedExportAll, ArchivedExportDecl, ArchivedExportDefaultDecl,
ArchivedExportDefaultExpr, ArchivedExportDefaultSpecifier, ArchivedExportNamedSpecifier,
ArchivedExportNamespaceSpecifier, ArchivedExportSpecifier, ArchivedImportDecl,
ArchivedImportDefaultSpecifier, ArchivedImportNamedSpecifier, ArchivedImportSpecifier,
ArchivedImportStarAsSpecifier, ArchivedModuleDecl, ArchivedModuleExportName,
ArchivedNamedExport,
},
operators::{ArchivedAssignOp, ArchivedBinaryOp, ArchivedUnaryOp, ArchivedUpdateOp},
pat::{
ArchivedArrayPat, ArchivedAssignPat, ArchivedAssignPatProp, ArchivedKeyValuePatProp,
ArchivedObjectPat, ArchivedObjectPatProp, ArchivedPat, ArchivedRestPat,
},
prop::{
ArchivedAssignProp, ArchivedComputedPropName, ArchivedGetterProp, ArchivedKeyValueProp,
ArchivedMethodProp, ArchivedProp, ArchivedPropName, ArchivedSetterProp,
},
stmt::{
ArchivedBlockStmt, ArchivedBreakStmt, ArchivedCatchClause, ArchivedContinueStmt,
ArchivedDebuggerStmt, ArchivedDoWhileStmt, ArchivedEmptyStmt, ArchivedExprStmt,
ArchivedForHead, ArchivedForInStmt, ArchivedForOfStmt, ArchivedForStmt, ArchivedIfStmt,
ArchivedLabeledStmt, ArchivedReturnStmt, ArchivedStmt, ArchivedSwitchCase,
ArchivedSwitchStmt, ArchivedThrowStmt, ArchivedTryStmt, ArchivedVarDeclOrExpr,
ArchivedWhileStmt, ArchivedWithStmt,
},
typescript::{
ArchivedAccessibility, ArchivedTruePlusMinus, ArchivedTsArrayType, ArchivedTsAsExpr,
ArchivedTsCallSignatureDecl, ArchivedTsConditionalType, ArchivedTsConstAssertion,
ArchivedTsConstructSignatureDecl, ArchivedTsConstructorType, ArchivedTsEntityName,
ArchivedTsEnumDecl, ArchivedTsEnumMember, ArchivedTsEnumMemberId,
ArchivedTsExportAssignment, ArchivedTsExprWithTypeArgs, ArchivedTsExternalModuleRef,
ArchivedTsFnOrConstructorType, ArchivedTsFnParam, ArchivedTsFnType,
ArchivedTsGetterSignature, ArchivedTsImportEqualsDecl, ArchivedTsImportType,
ArchivedTsIndexSignature, ArchivedTsIndexedAccessType, ArchivedTsInferType,
ArchivedTsInstantiation, ArchivedTsInterfaceBody, ArchivedTsInterfaceDecl,
ArchivedTsIntersectionType, ArchivedTsKeywordType, ArchivedTsKeywordTypeKind,
ArchivedTsLit, ArchivedTsLitType, ArchivedTsMappedType, ArchivedTsMethodSignature,
ArchivedTsModuleBlock, ArchivedTsModuleDecl, ArchivedTsModuleName, ArchivedTsModuleRef,
ArchivedTsNamespaceBody, ArchivedTsNamespaceDecl, ArchivedTsNamespaceExportDecl,
ArchivedTsNonNullExpr, ArchivedTsOptionalType, ArchivedTsParamProp,
ArchivedTsParamPropParam, ArchivedTsParenthesizedType, ArchivedTsPropertySignature,
ArchivedTsQualifiedName, ArchivedTsRestType, ArchivedTsSatisfiesExpr,
ArchivedTsSetterSignature, ArchivedTsThisType, ArchivedTsThisTypeOrIdent,
ArchivedTsTplLitType, ArchivedTsTupleElement, ArchivedTsTupleType, ArchivedTsType,
ArchivedTsTypeAliasDecl, ArchivedTsTypeAnn, ArchivedTsTypeAssertion, ArchivedTsTypeElement,
ArchivedTsTypeLit, ArchivedTsTypeOperator, ArchivedTsTypeOperatorOp, ArchivedTsTypeParam,
ArchivedTsTypeParamDecl, ArchivedTsTypeParamInstantiation, ArchivedTsTypePredicate,
ArchivedTsTypeQuery, ArchivedTsTypeQueryExpr, ArchivedTsTypeRef,
ArchivedTsUnionOrIntersectionType, ArchivedTsUnionType,
},
};

1 comment on commit 478fa47

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 478fa47 Previous: 42dec55 Ratio
es/full/bugs-1 284055 ns/iter (± 5375) 291098 ns/iter (± 8640) 0.98
es/full/minify/libraries/antd 1321495201 ns/iter (± 13665152) 1317080452 ns/iter (± 6582890) 1.00
es/full/minify/libraries/d3 277267110 ns/iter (± 1462154) 277478556 ns/iter (± 2045777) 1.00
es/full/minify/libraries/echarts 1052466619 ns/iter (± 11413827) 1049827358 ns/iter (± 3810725) 1.00
es/full/minify/libraries/jquery 84832326 ns/iter (± 86368) 85265346 ns/iter (± 88939) 0.99
es/full/minify/libraries/lodash 98206031 ns/iter (± 167926) 98821508 ns/iter (± 265580) 0.99
es/full/minify/libraries/moment 49962411 ns/iter (± 95581) 50253553 ns/iter (± 42439) 0.99
es/full/minify/libraries/react 17983205 ns/iter (± 46817) 18036961 ns/iter (± 44637) 1.00
es/full/minify/libraries/terser 218879392 ns/iter (± 1369152) 219629102 ns/iter (± 646599) 1.00
es/full/minify/libraries/three 383350893 ns/iter (± 1777864) 386301394 ns/iter (± 1247042) 0.99
es/full/minify/libraries/typescript 2672034877 ns/iter (± 12155552) 2666427161 ns/iter (± 10174405) 1.00
es/full/minify/libraries/victory 580560639 ns/iter (± 5305655) 570105429 ns/iter (± 2845977) 1.02
es/full/minify/libraries/vue 120416280 ns/iter (± 364068) 121160647 ns/iter (± 252826) 0.99
es/full/codegen/es3 35234 ns/iter (± 79) 34020 ns/iter (± 54) 1.04
es/full/codegen/es5 35215 ns/iter (± 78) 33935 ns/iter (± 204) 1.04
es/full/codegen/es2015 35286 ns/iter (± 86) 33994 ns/iter (± 86) 1.04
es/full/codegen/es2016 35221 ns/iter (± 95) 33917 ns/iter (± 105) 1.04
es/full/codegen/es2017 35288 ns/iter (± 72) 34027 ns/iter (± 61) 1.04
es/full/codegen/es2018 35212 ns/iter (± 95) 33994 ns/iter (± 219) 1.04
es/full/codegen/es2019 35194 ns/iter (± 116) 33942 ns/iter (± 80) 1.04
es/full/codegen/es2020 35240 ns/iter (± 111) 34043 ns/iter (± 106) 1.04
es/full/all/es3 169021014 ns/iter (± 1373862) 170270327 ns/iter (± 1248413) 0.99
es/full/all/es5 160805929 ns/iter (± 1539014) 161913930 ns/iter (± 889603) 0.99
es/full/all/es2015 120338300 ns/iter (± 564282) 120715607 ns/iter (± 589220) 1.00
es/full/all/es2016 118747705 ns/iter (± 658059) 120495128 ns/iter (± 416679) 0.99
es/full/all/es2017 118504855 ns/iter (± 783939) 119735148 ns/iter (± 935923) 0.99
es/full/all/es2018 116549496 ns/iter (± 501797) 117936879 ns/iter (± 708872) 0.99
es/full/all/es2019 115431518 ns/iter (± 1663059) 117238449 ns/iter (± 490473) 0.98
es/full/all/es2020 111004264 ns/iter (± 2593980) 112803465 ns/iter (± 830486) 0.98
es/full/parser 494674 ns/iter (± 4690) 504137 ns/iter (± 5869) 0.98
es/full/base/fixer 19435 ns/iter (± 98) 18208 ns/iter (± 482) 1.07
es/full/base/resolver_and_hygiene 82347 ns/iter (± 353) 79600 ns/iter (± 103) 1.03
serialization of serde 293 ns/iter (± 0) 292 ns/iter (± 3) 1.00
css/minify/libraries/bootstrap 28747417 ns/iter (± 43888) 28357138 ns/iter (± 93907) 1.01
css/visitor/compare/clone 1648837 ns/iter (± 8333) 1645213 ns/iter (± 6986) 1.00
css/visitor/compare/visit_mut_span 1769997 ns/iter (± 4789) 1779771 ns/iter (± 701) 0.99
css/visitor/compare/visit_mut_span_panic 1837692 ns/iter (± 2551) 1859124 ns/iter (± 4192) 0.99
css/visitor/compare/fold_span 2599453 ns/iter (± 6436) 2585403 ns/iter (± 14148) 1.01
css/visitor/compare/fold_span_panic 2769366 ns/iter (± 16134) 2761336 ns/iter (± 13227) 1.00
css/lexer/bootstrap_5_1_3 4530288 ns/iter (± 23969) 4440535 ns/iter (± 10890) 1.02
css/lexer/foundation_6_7_4 3800071 ns/iter (± 3034) 3789116 ns/iter (± 4785) 1.00
css/lexer/tailwind_3_1_1 723326 ns/iter (± 374) 722012 ns/iter (± 1348) 1.00
css/parser/bootstrap_5_1_3 19066785 ns/iter (± 90366) 19312756 ns/iter (± 167108) 0.99
css/parser/foundation_6_7_4 15394323 ns/iter (± 101223) 15533918 ns/iter (± 275756) 0.99
css/parser/tailwind_3_1_1 2942565 ns/iter (± 3754) 2960584 ns/iter (± 4898) 0.99
es/codegen/colors 737381 ns/iter (± 403066) 737275 ns/iter (± 403513) 1.00
es/codegen/large 3162105 ns/iter (± 1664579) 3147417 ns/iter (± 1668065) 1.00
es/codegen/with-parser/colors 44933 ns/iter (± 581) 45070 ns/iter (± 106) 1.00
es/codegen/with-parser/large 484679 ns/iter (± 690) 488850 ns/iter (± 1475) 0.99
es/minify/libraries/antd 1136508598 ns/iter (± 9192760) 1160223294 ns/iter (± 11396374) 0.98
es/minify/libraries/d3 240068034 ns/iter (± 1222725) 242518717 ns/iter (± 485513) 0.99
es/minify/libraries/echarts 911568947 ns/iter (± 6029929) 915986929 ns/iter (± 7124209) 1.00
es/minify/libraries/jquery 73549662 ns/iter (± 130703) 74763872 ns/iter (± 239514) 0.98
es/minify/libraries/lodash 87621884 ns/iter (± 222458) 89234693 ns/iter (± 146393) 0.98
es/minify/libraries/moment 43341436 ns/iter (± 83278) 44002506 ns/iter (± 24917) 0.98
es/minify/libraries/react 15974064 ns/iter (± 41657) 16166879 ns/iter (± 39770) 0.99
es/minify/libraries/terser 186714002 ns/iter (± 458378) 188573574 ns/iter (± 453850) 0.99
es/minify/libraries/three 319652491 ns/iter (± 1519407) 322183340 ns/iter (± 1114619) 0.99
es/minify/libraries/typescript 2263992960 ns/iter (± 9307777) 2282012886 ns/iter (± 12917213) 0.99
es/minify/libraries/victory 479624719 ns/iter (± 2140663) 487214670 ns/iter (± 1858815) 0.98
es/minify/libraries/vue 106374833 ns/iter (± 223652) 108483342 ns/iter (± 234183) 0.98
es/visitor/compare/clone 1929442 ns/iter (± 5936) 1936514 ns/iter (± 5842) 1.00
es/visitor/compare/visit_mut_span 2233365 ns/iter (± 2708) 2240588 ns/iter (± 3517) 1.00
es/visitor/compare/visit_mut_span_panic 2301447 ns/iter (± 1835) 2306231 ns/iter (± 18912) 1.00
es/visitor/compare/fold_span 3343465 ns/iter (± 4395) 3349981 ns/iter (± 4860) 1.00
es/visitor/compare/fold_span_panic 3468371 ns/iter (± 13827) 3500135 ns/iter (± 9874) 0.99
es/lexer/colors 13486 ns/iter (± 40) 13177 ns/iter (± 86) 1.02
es/lexer/angular 6205237 ns/iter (± 8215) 6160573 ns/iter (± 3270) 1.01
es/lexer/backbone 813859 ns/iter (± 2835) 805147 ns/iter (± 1543) 1.01
es/lexer/jquery 4621616 ns/iter (± 6277) 4559217 ns/iter (± 2521) 1.01
es/lexer/jquery mobile 7014112 ns/iter (± 6860) 6937817 ns/iter (± 10309) 1.01
es/lexer/mootools 3626080 ns/iter (± 1648) 3584977 ns/iter (± 16826) 1.01
es/lexer/underscore 684340 ns/iter (± 387) 670913 ns/iter (± 1051) 1.02
es/lexer/three 21833769 ns/iter (± 16552) 21432020 ns/iter (± 347308) 1.02
es/lexer/yui 3901601 ns/iter (± 4499) 3863024 ns/iter (± 2313) 1.01
es/parser/colors 27974 ns/iter (± 98) 27398 ns/iter (± 95) 1.02
es/parser/angular 13403316 ns/iter (± 62616) 13399337 ns/iter (± 54911) 1.00
es/parser/backbone 1980636 ns/iter (± 7308) 1983140 ns/iter (± 12297) 1.00
es/parser/jquery 10810636 ns/iter (± 45271) 10864832 ns/iter (± 41107) 1.00
es/parser/jquery mobile 16565840 ns/iter (± 36493) 16515068 ns/iter (± 62868) 1.00
es/parser/mootools 8352854 ns/iter (± 15936) 8351794 ns/iter (± 18668) 1.00
es/parser/underscore 1711357 ns/iter (± 10651) 1713876 ns/iter (± 9647) 1.00
es/parser/three 46516499 ns/iter (± 229236) 46540781 ns/iter (± 250407) 1.00
es/parser/yui 8271685 ns/iter (± 29979) 8262560 ns/iter (± 33078) 1.00
es/preset-env/usage/builtin_type 137053 ns/iter (± 32748) 139015 ns/iter (± 32111) 0.99
es/preset-env/usage/property 16872 ns/iter (± 104) 17007 ns/iter (± 80) 0.99
es/resolver/typescript 87970764 ns/iter (± 855785) 87397191 ns/iter (± 1392369) 1.01
es/fixer/typescript 63033981 ns/iter (± 614829) 62884136 ns/iter (± 400164) 1.00
es/hygiene/typescript 130767927 ns/iter (± 1035122) 130009428 ns/iter (± 718762) 1.01
es/resolver_with_hygiene/typescript 243856475 ns/iter (± 1427041) 243759393 ns/iter (± 658841) 1.00
es/visitor/base-perf/module_clone 59182 ns/iter (± 204) 59693 ns/iter (± 296) 0.99
es/visitor/base-perf/fold_empty 63669 ns/iter (± 224) 64021 ns/iter (± 214) 0.99
es/visitor/base-perf/fold_noop_impl_all 64040 ns/iter (± 313) 64081 ns/iter (± 221) 1.00
es/visitor/base-perf/fold_noop_impl_vec 64300 ns/iter (± 291) 64647 ns/iter (± 325) 0.99
es/visitor/base-perf/boxing_boxed_clone 57 ns/iter (± 0) 57 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 38 ns/iter (± 0) 40 ns/iter (± 0) 0.95
es/visitor/base-perf/boxing_boxed 108 ns/iter (± 1) 106 ns/iter (± 0) 1.02
es/visitor/base-perf/boxing_unboxed 78 ns/iter (± 0) 74 ns/iter (± 0) 1.05
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2591 ns/iter (± 20) 2655 ns/iter (± 20) 0.98
es/base/parallel/resolver/typescript 4457335696 ns/iter (± 228911829) 3674469532 ns/iter (± 231768319) 1.21
es/base/parallel/hygiene/typescript 1451798630 ns/iter (± 12304265) 1459359993 ns/iter (± 28685604) 0.99
misc/visitors/time-complexity/time 5 137 ns/iter (± 0) 120 ns/iter (± 0) 1.14
misc/visitors/time-complexity/time 10 383 ns/iter (± 7) 371 ns/iter (± 0) 1.03
misc/visitors/time-complexity/time 15 526 ns/iter (± 5) 678 ns/iter (± 2) 0.78
misc/visitors/time-complexity/time 20 1047 ns/iter (± 2) 1053 ns/iter (± 4) 0.99
misc/visitors/time-complexity/time 40 3548 ns/iter (± 9) 3558 ns/iter (± 61) 1.00
misc/visitors/time-complexity/time 60 7357 ns/iter (± 28) 7360 ns/iter (± 59) 1.00
es/full-target/es2016 231628 ns/iter (± 1377) 236478 ns/iter (± 469) 0.98
es/full-target/es2017 218781 ns/iter (± 772) 222505 ns/iter (± 489) 0.98
es/full-target/es2018 207047 ns/iter (± 788) 211863 ns/iter (± 591) 0.98
es2020_nullish_coalescing 70748 ns/iter (± 395) 71374 ns/iter (± 221) 0.99
es2020_optional_chaining 81699 ns/iter (± 232) 80150 ns/iter (± 433) 1.02
es2022_class_properties 115210 ns/iter (± 751) 115698 ns/iter (± 356) 1.00
es2018_object_rest_spread 76464 ns/iter (± 880) 75159 ns/iter (± 106) 1.02
es2019_optional_catch_binding 63850 ns/iter (± 277) 66131 ns/iter (± 252) 0.97
es2017_async_to_generator 63865 ns/iter (± 178) 65532 ns/iter (± 246) 0.97
es2016_exponentiation 68494 ns/iter (± 176) 69977 ns/iter (± 227) 0.98
es2015_arrow 71985 ns/iter (± 254) 71763 ns/iter (± 225) 1.00
es2015_block_scoped_fn 68406 ns/iter (± 283) 69875 ns/iter (± 206) 0.98
es2015_block_scoping 120707 ns/iter (± 403) 124822 ns/iter (± 445) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.