Skip to main content

rib/type_inference/
initial_phase.rs

1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Golem Source License v1.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://license.golem.cloud/LICENSE
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Runs the former “initial phase” passes on an [`crate::expr_arena::ExprArena`] after [`crate::expr_arena::lower`],
16//! in the same order as the historical `Expr` pipeline.
17
18use crate::expr_arena::{ExprArena, ExprId, TypeTable};
19use crate::rib_type_error::RibTypeErrorInternal;
20use crate::type_inference as ti;
21use crate::{ComponentDependency, CustomInstanceSpec, GlobalVariableTypeSpec};
22use std::sync::Arc;
23
24pub fn run_initial_binding_and_instance_phases(
25    root: ExprId,
26    arena: &mut ExprArena,
27    types: &mut TypeTable,
28    component: Arc<ComponentDependency>,
29    global_variable_type_spec: &[GlobalVariableTypeSpec],
30    custom_instance_spec: &[CustomInstanceSpec],
31) -> Result<(), RibTypeErrorInternal> {
32    ti::global_variable_type_binding::bind_global_variable_types_lowered(
33        root,
34        arena,
35        types,
36        global_variable_type_spec,
37    );
38    ti::type_annotation_binding::bind_type_annotations(root, arena, types);
39    ti::variable_binding::bind_variables_of_list_comprehension(root, arena, types);
40    ti::variable_binding::bind_variables_of_list_reduce(root, arena, types);
41    ti::variable_binding::bind_variables_of_pattern_match(root, arena, types);
42    ti::variable_binding::bind_variables_of_let_assignment(root, arena, types);
43    ti::identify_instance_creation::identify_instance_creation(
44        root,
45        arena,
46        types,
47        component,
48        custom_instance_spec,
49    )?;
50    ti::stateful_instance::ensure_stateful_instance(root, arena, types);
51    ti::type_annotation_binding::set_origin(root, arena, types);
52    Ok(())
53}