rib/type_inference/
inferred_expr.rs1use crate::call_type::CallType;
16use crate::rib_type_error::RibTypeErrorInternal;
17use crate::{
18 ComponentDependencies, DynamicParsedFunctionName, Expr, ExprVisitor, FunctionName,
19 GlobalVariableTypeSpec,
20};
21use std::collections::HashSet;
22
23#[derive(Debug, Clone)]
24pub struct InferredExpr(Expr);
25
26impl InferredExpr {
27 pub fn get_expr(&self) -> &Expr {
28 &self.0
29 }
30
31 pub fn from_expr(
32 expr: Expr,
33 component_dependency: &ComponentDependencies,
34 type_spec: &Vec<GlobalVariableTypeSpec>,
35 ) -> Result<InferredExpr, RibTypeErrorInternal> {
36 let mut mutable_expr = expr;
37
38 mutable_expr.infer_types(component_dependency, type_spec)?;
39
40 Ok(InferredExpr(mutable_expr))
41 }
42
43 pub fn worker_invoke_calls(&self) -> Vec<DynamicParsedFunctionName> {
46 let mut expr = self.0.clone();
47 let mut worker_calls = vec![];
48 let mut visitor = ExprVisitor::bottom_up(&mut expr);
49
50 while let Some(expr) = visitor.pop_back() {
51 if let Expr::Call {
52 call_type: CallType::Function { function_name, .. },
53 ..
54 } = expr
55 {
56 worker_calls.push(function_name.clone());
57 }
58 }
59
60 worker_calls
61 }
62
63 pub fn worker_invoke_registry_keys(&self) -> HashSet<FunctionName> {
64 let worker_calls = self.worker_invoke_calls();
65
66 let mut registry_keys = HashSet::new();
67
68 for call in worker_calls {
69 let keys = FunctionName::from_dynamic_parsed_function_name(&call);
70 registry_keys.insert(keys);
71 }
72
73 registry_keys
74 }
75}