Skip to content

AST 工具

🌐 AST Tools

AST 工具 任务是我们管理所有生成文件的秘密武器。这些工具包括 AST 构建器、访问器、像 ContentEqContentHash 这样的特性,以及 TypeScript 类型——所有这些都是机器生成的。

🌐 The AST Tools task serves as our secret weapon for managing all generated files. These tools include the AST builder, visitors, traits like ContentEq and ContentHash, and TypeScript types - all of which are machine-generated.

例如,以下文件会自动生成:

🌐 For instance, the following files are automatically generated:

  • crates/oxc_ast/src/generated/ast_builder.rs
  • crates/oxc_ast/src/generated/visit.rs
  • crates/oxc_ast/src/generated/visit_mut.rs
  • crates/oxc_ast/src/generated/derive_content_eq.rs
  • crates/oxc_ast/src/generated/derive_content_hash.rs
  • npm/oxc-types/src/generated/types.d.ts

背景

🌐 Background

Rust 的编译时间众所周知非常慢,而使用过程宏生成这么多代码只会让问题更严重。

🌐 Rust's compile time is notoriously slow, and using procedural macros to generate this much code worsens the issue.

要求用户在构建时等待代码生成完成,会显著阻碍下游项目的开发体验。

🌐 Requiring users to wait for code generation to complete at build time would significantly hinder the development experience for downstream projects.

无论是冷构建还是增量构建时间都可能大幅回退。

🌐 Both cold and incremental build times can regress drastically.

RFC

🌐 The RFC

团队在 RFC: codegen AST 相关代码 中讨论了该主题,并就以下需求和用户故事达成了一致:

🌐 The team discussed the topic in RFC: codegen AST related codes and agreed on the following requirements and user story:

要求

🌐 Requirements

  • 没有向用户发布 build.rs。
  • 所有生成的代码都已提交到 Git。
  • 没有晚间活动。
  • Rust 代码是事实来源,需要解析标记为 #[ast] 的类型。
  • 尽量避免在编译时使用过程宏。

工作流程

🌐 Workflow

  • 用户在仓库中更改代码。
  • 换表能注意到它。
  • 解析所有标记为 #[ast] 的类型。
  • 记录模式中所有 AST 类型的详细信息。
  • 根据模式生成代码并保存到文件。

基础设施

🌐 Infrastructure

更多详情稍后公布。

🌐 More details to follow.