rib/type_inference/
inferred_expr.rs1use crate::call_type::CallType;
16use crate::rib_type_error::RibTypeErrorInternal;
17use crate::{
18 visit_post_order_rev_mut, ComponentDependency, CustomInstanceSpec, DynamicParsedFunctionName,
19 Expr, FunctionName, 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: &ComponentDependency,
34 global_variable_type_spec: &Vec<GlobalVariableTypeSpec>,
35 custom_instance_spec: &[CustomInstanceSpec],
36 ) -> Result<InferredExpr, RibTypeErrorInternal> {
37 let mut mutable_expr = expr;
38
39 mutable_expr.infer_types(
40 component_dependency,
41 global_variable_type_spec,
42 custom_instance_spec,
43 )?;
44
45 Ok(InferredExpr(mutable_expr))
46 }
47
48 pub fn worker_invoke_calls(&self) -> Vec<DynamicParsedFunctionName> {
51 let mut expr = self.0.clone();
52 let mut worker_calls = vec![];
53 visit_post_order_rev_mut(&mut expr, &mut |expr| {
54 if let Expr::Call {
55 call_type: CallType::Function { function_name, .. },
56 ..
57 } = expr
58 {
59 worker_calls.push(function_name.clone());
60 }
61 });
62
63 worker_calls
64 }
65
66 pub fn worker_invoke_registry_keys(&self) -> HashSet<FunctionName> {
67 let worker_calls = self.worker_invoke_calls();
68
69 let mut registry_keys = HashSet::new();
70
71 for call in worker_calls {
72 let keys = FunctionName::from_dynamic_parsed_function_name(&call);
73 registry_keys.insert(keys);
74 }
75
76 registry_keys
77 }
78}