diff --git a/libs/@local/hashql/compiletest/src/pipeline.rs b/libs/@local/hashql/compiletest/src/pipeline.rs index 8b18e299072..e347acb4e28 100644 --- a/libs/@local/hashql/compiletest/src/pipeline.rs +++ b/libs/@local/hashql/compiletest/src/pipeline.rs @@ -31,12 +31,7 @@ use hashql_mir::{ body::Body, context::MirContext, def::{DefId, DefIdSlice, DefIdVec}, - pass::{ - Changed, GlobalAnalysisPass as _, GlobalTransformPass as _, GlobalTransformState, - analysis::SizeEstimationAnalysis, - execution::{ExecutionAnalysis, ExecutionAnalysisResidual}, - transform::{Inline, InlineConfig, PostInline, PreInline}, - }, + pass::{self, LowerConfig, execution::ExecutionAnalysisResidual}, reify::ReifyContext, }; use hashql_syntax_jexpr::span::Span; @@ -189,9 +184,11 @@ impl<'heap> Pipeline<'heap> { bodies: &mut bodies, mir: &mut mir_context, hir: &hir_context, + scratch: &self.scratch, }; let entry = tri!(hashql_mir::reify::from_hir(node, &mut reify_context)); + self.scratch.reset(); // drain the context, because we're going to re-create it self.diagnostics.extend( @@ -218,24 +215,14 @@ impl<'heap> Pipeline<'heap> { bodies: &mut DefIdSlice
>, ) -> Result<(), BoxedDiagnostic<'static, SpanId>> { let mut context = MirContext::new(&self.env, interner); - let mut state = GlobalTransformState::new_in(&*bodies, self.heap); - - self.scratch.reset(); - - let mut pass = PreInline::new_in(&mut self.scratch); - let _: Changed = pass.run(&mut context, &mut state, bodies); - self.scratch.reset(); - - let mut pass = Inline::new_in(InlineConfig::default(), &mut self.scratch); - let _: Changed = pass.run(&mut context, &mut state, bodies); - self.scratch.reset(); - let mut pass = PostInline::new_in(&mut self.scratch); - let _: Changed = pass.run(&mut context, &mut state, bodies); - self.scratch.reset(); - - let status = context.diagnostics.generalize().boxed().into_status(()); - process_status(&mut self.diagnostics, status)?; + let result = pass::lower( + &mut context, + &mut self.scratch, + bodies, + &LowerConfig::default(), + ); + process_status(&mut self.diagnostics, result)?; Ok(()) } @@ -262,20 +249,8 @@ impl<'heap> Pipeline<'heap> { > { let mut context = MirContext::new(&self.env, interner); - let mut pass = SizeEstimationAnalysis::new_in(&self.scratch); - pass.run(&mut context, bodies); - let footprints = pass.finish(); - self.scratch.reset(); - - let pass = ExecutionAnalysis { - footprints: &footprints, - scratch: &mut self.scratch, - }; - let analysis = pass.run_all_in(&mut context, bodies, self.heap); - self.scratch.reset(); - - let status = context.diagnostics.generalize().boxed().into_status(()); - process_status(&mut self.diagnostics, status)?; + let status = pass::place(&mut context, &mut self.scratch, bodies); + let analysis = process_status(&mut self.diagnostics, status)?; Ok(analysis) } diff --git a/libs/@local/hashql/compiletest/src/suite/eval_postgres.rs b/libs/@local/hashql/compiletest/src/suite/eval_postgres.rs index 721796be1e9..7cd0bd37246 100644 --- a/libs/@local/hashql/compiletest/src/suite/eval_postgres.rs +++ b/libs/@local/hashql/compiletest/src/suite/eval_postgres.rs @@ -122,7 +122,7 @@ impl Suite for EvalPostgres { &interner, &bodies, &analysis, - context.heap, + heap, &mut scratch, ); scratch.reset(); diff --git a/libs/@local/hashql/compiletest/src/suite/mir_interpret.rs b/libs/@local/hashql/compiletest/src/suite/mir_interpret.rs new file mode 100644 index 00000000000..6d7bb4aed7b --- /dev/null +++ b/libs/@local/hashql/compiletest/src/suite/mir_interpret.rs @@ -0,0 +1,66 @@ +use hashql_core::r#type::environment::Environment; +use hashql_diagnostics::Diagnostic; +use hashql_mir::{ + intern::Interner, + interpret::{CallStack, Inputs, Runtime, RuntimeConfig}, +}; + +use super::{ + RunContext, Suite, SuiteDiagnostic, + mir_pass_transform_post_inline::mir_pass_transform_post_inline, + mir_pass_transform_pre_inline::TextRenderer, +}; + +pub(crate) struct MirInterpret; + +impl Suite for MirInterpret { + fn name(&self) -> &'static str { + "mir/interpret" + } + + fn description(&self) -> &'static str { + "Run the interpreter on the MIR" + } + + fn secondary_file_extensions(&self) -> &[&str] { + &["mir"] + } + + fn run<'heap>( + &self, + RunContext { + heap, + diagnostics, + secondary_outputs, + .. + }: RunContext<'_, 'heap>, + expr: hashql_ast::node::expr::Expr<'heap>, + ) -> Result