@@ -11,8 +11,7 @@ use crate::{
1111 capture,
1212 cir:: { Cost , LogicalProperties , PartialLogicalPlan , PartialPhysicalPlan , PhysicalProperties } ,
1313} ;
14- use eval:: Evaluate ;
15- use generator:: Generator ;
14+
1615use optd_dsl:: analyzer:: {
1716 context:: Context ,
1817 hir:: { CoreData , Expr , Literal , Value } ,
@@ -22,25 +21,22 @@ use utils::UnitFuture;
2221use Expr :: * ;
2322
2423mod eval;
25- pub ( crate ) mod generator;
26- #[ cfg( test) ]
27- pub ( super ) mod test_utils;
28- pub ( crate ) mod utils;
24+ use eval:: Evaluate ;
2925
30- /// Type alias for a continuation that receives a PartialLogicalPlan
31- pub ( crate ) type LogicalPlanContinuation =
32- Arc < dyn Fn ( PartialLogicalPlan ) -> UnitFuture + Send + Sync + ' static > ;
26+ mod generator;
27+ pub use generator:: Generator ;
3328
34- /// Type alias for a continuation that receives a PartialPhysicalPlan
35- pub ( crate ) type PhysicalPlanContinuation =
36- Arc < dyn Fn ( PartialPhysicalPlan ) -> UnitFuture + Send + Sync + ' static > ;
29+ pub ( crate ) mod utils;
3730
38- /// Type alias for a continuation that receives a cost value
39- pub ( crate ) type CostContinuation = Arc < dyn Fn ( Cost ) -> UnitFuture + Send + Sync + ' static > ;
31+ # [ cfg ( test ) ]
32+ pub ( super ) mod test_utils ;
4033
41- /// Type alias for a continuation that receives LogicalProperties
42- pub ( crate ) type PropertiesContinuation =
43- Arc < dyn Fn ( LogicalProperties ) -> UnitFuture + Send + Sync + ' static > ;
34+ /// A type alias for continuations used in the rule engine.
35+ ///
36+ /// The engine uses continuation-passing-style (CPS) since it requires advanced control flow to
37+ /// expand and iterate over expressions within groups (where each expression requires
38+ /// plan-dependent state).
39+ pub type Continuation < Input > = Arc < dyn Fn ( Input ) -> UnitFuture + Send + Sync + ' static > ;
4440
4541/// The engine for evaluating HIR expressions and applying rules.
4642#[ derive( Debug , Clone ) ]
@@ -87,7 +83,7 @@ impl<G: Generator> Engine<G> {
8783 self ,
8884 rule_name : String ,
8985 plan : & PartialLogicalPlan ,
90- k : LogicalPlanContinuation ,
86+ k : Continuation < PartialLogicalPlan > ,
9187 ) -> UnitFuture {
9288 let rule_call = self . create_rule_call ( & rule_name, vec ! [ partial_logical_to_value( plan) ] ) ;
9389
@@ -126,7 +122,7 @@ impl<G: Generator> Engine<G> {
126122 rule_name : String ,
127123 plan : & PartialLogicalPlan ,
128124 props : & PhysicalProperties ,
129- k : PhysicalPlanContinuation ,
125+ k : Continuation < PartialPhysicalPlan > ,
130126 ) -> UnitFuture {
131127 let plan_value = partial_logical_to_value ( plan) ;
132128 let props_value = physical_properties_to_value ( props) ;
@@ -164,7 +160,7 @@ impl<G: Generator> Engine<G> {
164160 pub ( crate ) fn launch_cost_plan (
165161 self ,
166162 plan : & PartialPhysicalPlan ,
167- k : CostContinuation ,
163+ k : Continuation < Cost > ,
168164 ) -> UnitFuture {
169165 // Create a call to the reserved "cost" function
170166 let rule_call = self . create_rule_call ( "cost" , vec ! [ partial_physical_to_value( plan) ] ) ;
@@ -194,7 +190,7 @@ impl<G: Generator> Engine<G> {
194190 pub ( crate ) fn launch_derive_properties (
195191 self ,
196192 plan : & PartialLogicalPlan ,
197- k : PropertiesContinuation ,
193+ k : Continuation < LogicalProperties > ,
198194 ) -> UnitFuture {
199195 // Create a call to the reserved "derive" function
200196 let rule_call = self . create_rule_call ( "derive" , vec ! [ partial_logical_to_value( plan) ] ) ;
0 commit comments