@@ -11,8 +11,7 @@ use crate::{
11
11
capture,
12
12
cir:: { Cost , LogicalProperties , PartialLogicalPlan , PartialPhysicalPlan , PhysicalProperties } ,
13
13
} ;
14
- use eval:: Evaluate ;
15
- use generator:: Generator ;
14
+
16
15
use optd_dsl:: analyzer:: {
17
16
context:: Context ,
18
17
hir:: { CoreData , Expr , Literal , Value } ,
@@ -22,25 +21,22 @@ use utils::UnitFuture;
22
21
use Expr :: * ;
23
22
24
23
mod eval;
25
- pub ( crate ) mod generator;
26
- #[ cfg( test) ]
27
- pub ( super ) mod test_utils;
28
- pub ( crate ) mod utils;
24
+ use eval:: Evaluate ;
29
25
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 ;
33
28
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;
37
30
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 ;
40
33
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 > ;
44
40
45
41
/// The engine for evaluating HIR expressions and applying rules.
46
42
#[ derive( Debug , Clone ) ]
@@ -87,7 +83,7 @@ impl<G: Generator> Engine<G> {
87
83
self ,
88
84
rule_name : String ,
89
85
plan : & PartialLogicalPlan ,
90
- k : LogicalPlanContinuation ,
86
+ k : Continuation < PartialLogicalPlan > ,
91
87
) -> UnitFuture {
92
88
let rule_call = self . create_rule_call ( & rule_name, vec ! [ partial_logical_to_value( plan) ] ) ;
93
89
@@ -126,7 +122,7 @@ impl<G: Generator> Engine<G> {
126
122
rule_name : String ,
127
123
plan : & PartialLogicalPlan ,
128
124
props : & PhysicalProperties ,
129
- k : PhysicalPlanContinuation ,
125
+ k : Continuation < PartialPhysicalPlan > ,
130
126
) -> UnitFuture {
131
127
let plan_value = partial_logical_to_value ( plan) ;
132
128
let props_value = physical_properties_to_value ( props) ;
@@ -164,7 +160,7 @@ impl<G: Generator> Engine<G> {
164
160
pub ( crate ) fn launch_cost_plan (
165
161
self ,
166
162
plan : & PartialPhysicalPlan ,
167
- k : CostContinuation ,
163
+ k : Continuation < Cost > ,
168
164
) -> UnitFuture {
169
165
// Create a call to the reserved "cost" function
170
166
let rule_call = self . create_rule_call ( "cost" , vec ! [ partial_physical_to_value( plan) ] ) ;
@@ -194,7 +190,7 @@ impl<G: Generator> Engine<G> {
194
190
pub ( crate ) fn launch_derive_properties (
195
191
self ,
196
192
plan : & PartialLogicalPlan ,
197
- k : PropertiesContinuation ,
193
+ k : Continuation < LogicalProperties > ,
198
194
) -> UnitFuture {
199
195
// Create a call to the reserved "derive" function
200
196
let rule_call = self . create_rule_call ( "derive" , vec ! [ partial_logical_to_value( plan) ] ) ;
0 commit comments