Skip to content

Commit

Permalink
refactor(ast_tools): combine derives into generators (oxc-project#6944)
Browse files Browse the repository at this point in the history
`Generator`s and `Derive`s now work the same. Combine them into a single `Vec`.
  • Loading branch information
overlookmotel committed Oct 27, 2024
1 parent 80a163e commit dde095c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
15 changes: 1 addition & 14 deletions tasks/ast_tools/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use itertools::Itertools;
use rustc_hash::{FxBuildHasher, FxHashMap};

use crate::{
derives::Derive,
generators::Generator,
log, logln,
output::{Output, RawOutput},
passes::Pass,
Expand All @@ -19,7 +17,6 @@ pub struct AstCodegen {
files: Vec<PathBuf>,
passes: Vec<Box<dyn Runner<Context = EarlyCtx>>>,
generators: Vec<Box<dyn Runner<Context = LateCtx>>>,
derives: Vec<Box<dyn Runner<Context = LateCtx>>>,
}

pub struct AstCodegenResult {
Expand Down Expand Up @@ -124,21 +121,12 @@ impl AstCodegen {
#[must_use]
pub fn generate<G>(mut self, generator: G) -> Self
where
G: Generator + Runner<Context = LateCtx> + 'static,
G: Runner<Context = LateCtx> + 'static,
{
self.generators.push(Box::new(generator));
self
}

#[must_use]
pub fn derive<D>(mut self, derive: D) -> Self
where
D: Derive + Runner<Context = LateCtx> + 'static,
{
self.derives.push(Box::new(derive));
self
}

pub fn run(mut self) -> Result<AstCodegenResult> {
let modules = self
.files
Expand All @@ -155,7 +143,6 @@ impl AstCodegen {

// Late passes
let late_ctx = early_ctx.into_late_ctx();
outputs.extend(run_passes(&mut self.derives, &late_ctx)?);
outputs.extend(run_passes(&mut self.generators, &late_ctx)?);

Ok(AstCodegenResult { outputs, schema: late_ctx.schema })
Expand Down
12 changes: 6 additions & 6 deletions tasks/ast_tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
.fold(AstCodegen::default(), AstCodegen::add_file)
.pass(Linker)
.pass(CalcLayout)
.derive(DeriveCloneIn)
.derive(DeriveGetSpan)
.derive(DeriveGetSpanMut)
.derive(DeriveContentEq)
.derive(DeriveContentHash)
.derive(DeriveESTree)
.generate(DeriveCloneIn)
.generate(DeriveGetSpan)
.generate(DeriveGetSpanMut)
.generate(DeriveContentEq)
.generate(DeriveContentHash)
.generate(DeriveESTree)
.generate(AssertLayouts)
.generate(AstKindGenerator)
.generate(AstBuilderGenerator)
Expand Down

0 comments on commit dde095c

Please sign in to comment.