BlogDocs

feat(ast)!: generate `ast_builder.rs`.(#3890)

Merged
Merging
06-25-feat_ast_codegen_generate_ast_builder.rs_
(
d347aed
) into
main
(
91c792a
)
0%
IMPROVEMENTS
0
REGRESSIONS
0
UNTOUCHED
29
NEW
0
DROPPED
0
IGNORED
0

Benchmarks

codegen_sourcemap[cal.com.tsx]
tasks/benchmark/benches/codegen_sourcemap.rs::codegen_sourcemap::bench_codegen_sourcemap::codegen_sourcemap[cal.com.tsx]
0%
35.5 ms
35.6 ms
isolated-declarations[vue-id.ts]
tasks/benchmark/benches/isolated_declarations.rs::transformer::bench_isolated_declarations::isolated-declarations[vue-id.ts]
0%
376.9 ms
376.6 ms
lexer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer::lexer[RadixUIAdoptionSection.jsx]
0%
22.7 µs
22.7 µs
lexer[antd.js]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer::lexer[antd.js]
0%
20.1 ms
20.1 ms
lexer[cal.com.tsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer::lexer[cal.com.tsx]
0%
5 ms
5 ms
lexer[checker.ts]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer::lexer[checker.ts]
0%
12 ms
12 ms
lexer[pdf.mjs]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer::lexer[pdf.mjs]
0%
3.2 ms
3.2 ms
linter[cal.com.tsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter::linter[cal.com.tsx]
-1%
747 ms
751.9 ms
linter[checker.ts]
tasks/benchmark/benches/linter.rs::linter::bench_linter::linter[checker.ts]
+1%
1.4 s
1.4 s
minifier[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier::minifier[react.development.js]
0%
1.7 ms
1.7 ms
minifier[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier::minifier[typescript.js]
0%
249.1 ms
249 ms
prepass[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_passes::prepass[react.development.js]
0%
205.3 µs
206.2 µs
prepass[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_passes::prepass[typescript.js]
0%
27.3 ms
27.3 ms
parser[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser::parser[RadixUIAdoptionSection.jsx]
-2%
75.8 µs
77.1 µs
parser[antd.js]
tasks/benchmark/benches/parser.rs::parser::bench_parser::parser[antd.js]
0%
104.2 ms
104.1 ms
parser[cal.com.tsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser::parser[cal.com.tsx]
-1%
23.8 ms
24 ms
parser[checker.ts]
tasks/benchmark/benches/parser.rs::parser::bench_parser::parser[checker.ts]
0%
52.5 ms
52.5 ms
parser[pdf.mjs]
tasks/benchmark/benches/parser.rs::parser::bench_parser::parser[pdf.mjs]
0%
17.2 ms
17.1 ms
semantic[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic::semantic[RadixUIAdoptionSection.jsx]
+1%
128.8 µs
128 µs
semantic[antd.js]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic::semantic[antd.js]
0%
12.4 s
12.4 s
semantic[cal.com.tsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic::semantic[cal.com.tsx]
0%
135.8 ms
135.9 ms
semantic[checker.ts]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic::semantic[checker.ts]
0%
2.6 s
2.6 s
semantic[pdf.mjs]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic::semantic[pdf.mjs]
0%
88.9 ms
89 ms
sourcemap[cal.com.tsx]
tasks/benchmark/benches/sourcemap.rs::sourcemap::bench_sourcemap::sourcemap[cal.com.tsx]
0%
57.8 ms
57.7 ms
transformer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer::transformer[RadixUIAdoptionSection.jsx]
-1%
250.1 µs
252.6 µs
transformer[antd.js]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer::transformer[antd.js]
0%
333.6 ms
333.3 ms
transformer[cal.com.tsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer::transformer[cal.com.tsx]
-1%
83.6 ms
84.4 ms
transformer[checker.ts]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer::transformer[checker.ts]
0%
201.4 ms
201.7 ms
transformer[pdf.mjs]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer::transformer[pdf.mjs]
-1%
52.1 ms
52.7 ms

Commits

Click on a commit to change the comparison range
base
main
91c792a
0%
feat(ast)!: generate `ast_builder.rs`. (#3890) ### Every structure has 2 builder methods: 1. `xxx` e.g. `block_statement` ```rust #[inline] pub fn block_statement(self, span: Span, body: Vec<'a, Statement<'a>>) -> BlockStatement<'a> { BlockStatement { span, body, scope_id: Default::default() } } ``` 2. `alloc_xxx` e.g. `alloc_block_statement` ```rust #[inline] pub fn alloc_block_statement( self, span: Span, body: Vec<'a, Statement<'a>>, ) -> Box<'a, BlockStatement<'a>> { self.block_statement(span, body).into_in(self.allocator) } ``` ### We generate 3 types of methods for enums: 1. `yyy_xxx` e.g. `statement_block` ```rust #[inline] pub fn statement_block(self, span: Span, body: Vec<'a, Statement<'a>>) -> Statement<'a> { Statement::BlockStatement(self.alloc(self.block_statement(span, body))) } ``` 2. `yyy_from_xxx` e.g. `statement_from_block` ```rust #[inline] pub fn statement_from_block<T>(self, inner: T) -> Statement<'a> where T: IntoIn<'a, Box<'a, BlockStatement<'a>>>, { Statement::BlockStatement(inner.into_in(self.allocator)) } ``` 3. `yyy_xxx` where `xxx` is inherited e.g. `statement_declaration` ```rust #[inline] pub fn statement_declaration(self, inner: Declaration<'a>) -> Statement<'a> { Statement::from(inner) } ``` ------------ ### Generic parameters: We no longer accept `Box<'a, ADT>`, `Atom` or `&'a str`, Instead we use `IntoIn<'a, Box<'a, ADT>>`, `IntoIn<'a, Atom<'a>>` and `IntoIn<'a, &'a str>` respectively. It allows us to rewrite things like this: ```rust let ident = IdentifierReference::new(SPAN, Atom::from("require")); let number_literal_expr = self.ast.expression_numeric_literal( right_expr.span(), num, raw, self.ast.new_str(num.to_string().as_str()), NumberBase::Decimal, ); ``` As this: ```rust let ident = IdentifierReference::new(SPAN, "require"); let number_literal_expr = self.ast.expression_numeric_literal( right_expr.span(), num, raw, num.to_string(), NumberBase::Decimal, ); ```
d347aed
2 months ago
by rzvxa
ResourcesHomePricingDocsBlogGitHub
Copyright © 2024 CodSpeed Technology SAS. All rights reserved.