Skip to main content

rib/type_inference/
initial_phase.rs

1//! Runs the former “initial phase” passes on an [`crate::expr_arena::ExprArena`] after [`crate::expr_arena::lower`],
2//! in the same order as the historical `Expr` pipeline.
3
4use crate::expr_arena::{ExprArena, ExprId, TypeTable};
5use crate::rib_type_error::RibTypeErrorInternal;
6use crate::type_inference as ti;
7use crate::{ComponentDependency, CustomInstanceSpec, GlobalVariableTypeSpec};
8use std::sync::Arc;
9
10pub fn run_initial_binding_and_instance_phases(
11    root: ExprId,
12    arena: &mut ExprArena,
13    types: &mut TypeTable,
14    component: Arc<ComponentDependency>,
15    global_variable_type_spec: &[GlobalVariableTypeSpec],
16    custom_instance_spec: &[CustomInstanceSpec],
17) -> Result<(), RibTypeErrorInternal> {
18    ti::global_variable_type_binding::bind_global_variable_types_lowered(
19        root,
20        arena,
21        types,
22        global_variable_type_spec,
23    );
24    ti::type_annotation_binding::bind_type_annotations(root, arena, types);
25    ti::variable_binding::bind_variables_of_list_comprehension(root, arena, types);
26    ti::variable_binding::bind_variables_of_list_reduce(root, arena, types);
27    ti::variable_binding::bind_variables_of_pattern_match(root, arena, types);
28    ti::variable_binding::bind_variables_of_let_assignment(root, arena, types);
29    ti::identify_instance_creation::identify_instance_creation(
30        root,
31        arena,
32        types,
33        component,
34        custom_instance_spec,
35    )?;
36    ti::stateful_instance::ensure_stateful_instance(root, arena, types);
37    ti::type_annotation_binding::set_origin(root, arena, types);
38    Ok(())
39}