Skip to main content

harn_modules/
typecheck.rs

1//! Canonical type-checker projection of a resolved module graph.
2
3use std::path::Path;
4
5use harn_parser::analysis::TypeCheckConfig;
6use harn_parser::NamespaceImportBinding;
7
8use crate::ModuleGraph;
9
10impl ModuleGraph {
11    /// Project every import visible to `file` into one type-checker config.
12    ///
13    /// Callers layer execution-specific strictness and authority on top. The
14    /// graph remains the sole owner of named, typed, callable, and namespace
15    /// import resolution.
16    pub fn typecheck_import_config_for_file(&self, file: &Path) -> TypeCheckConfig {
17        let namespace_imports = self
18            .namespace_imports_for_file(file)
19            .unwrap_or_default()
20            .into_iter()
21            .map(|info| {
22                (
23                    info.alias,
24                    NamespaceImportBinding::from_member_signatures(
25                        info.raw_path,
26                        info.member_names.into_iter().collect(),
27                        info.member_signatures,
28                    ),
29                )
30            })
31            .collect();
32
33        TypeCheckConfig::new()
34            .with_imported_names(self.imported_names_for_file(file))
35            .with_imported_type_decls(
36                self.imported_type_declarations_for_file(file)
37                    .unwrap_or_default(),
38            )
39            .with_imported_callable_decls(
40                self.imported_callable_declarations_for_file(file)
41                    .unwrap_or_default(),
42            )
43            .with_namespace_imports(namespace_imports)
44    }
45}