From dde095c7e174c3611df22cac35ad6537d6b8599a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:37:25 +0000 Subject: [PATCH] refactor(ast_tools): combine derives into generators (#6944) `Generator`s and `Derive`s now work the same. Combine them into a single `Vec`. --- tasks/ast_tools/src/codegen.rs | 15 +-------------- tasks/ast_tools/src/main.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/tasks/ast_tools/src/codegen.rs b/tasks/ast_tools/src/codegen.rs index a56fd308703d7..1d86da5dd7da8 100644 --- a/tasks/ast_tools/src/codegen.rs +++ b/tasks/ast_tools/src/codegen.rs @@ -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, @@ -19,7 +17,6 @@ pub struct AstCodegen { files: Vec, passes: Vec>>, generators: Vec>>, - derives: Vec>>, } pub struct AstCodegenResult { @@ -124,21 +121,12 @@ impl AstCodegen { #[must_use] pub fn generate(mut self, generator: G) -> Self where - G: Generator + Runner + 'static, + G: Runner + 'static, { self.generators.push(Box::new(generator)); self } - #[must_use] - pub fn derive(mut self, derive: D) -> Self - where - D: Derive + Runner + 'static, - { - self.derives.push(Box::new(derive)); - self - } - pub fn run(mut self) -> Result { let modules = self .files @@ -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 }) diff --git a/tasks/ast_tools/src/main.rs b/tasks/ast_tools/src/main.rs index be61954bc8b20..c6b8798ac6d38 100644 --- a/tasks/ast_tools/src/main.rs +++ b/tasks/ast_tools/src/main.rs @@ -72,12 +72,12 @@ fn main() -> std::result::Result<(), Box> { .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)