diff --git a/crates/ailang-check/src/lib.rs b/crates/ailang-check/src/lib.rs index cd9ac3e..5727081 100644 --- a/crates/ailang-check/src/lib.rs +++ b/crates/ailang-check/src/lib.rs @@ -123,7 +123,7 @@ fn instantiate(forall_vars: &[String], body: &Type, counter: &mut u32) -> (Vec) -> Type { +fn substitute_rigids(t: &Type, mapping: &BTreeMap) -> Type { match t { Type::Var { name } => mapping.get(name).cloned().unwrap_or_else(|| t.clone()), Type::Con { name, args } => Type::Con { @@ -874,7 +874,7 @@ pub fn check_and_lift(m: &Module) -> Result<(CheckedModule, Module)> { /// cross-module `Pattern::Ctor` fallback. Duplicate type / ctor errors /// inside a single module surface during the per-module body-check /// phase, not here. -fn build_module_types( +pub(crate) fn build_module_types( ws: &Workspace, ) -> BTreeMap> { let mut out: BTreeMap> = BTreeMap::new(); diff --git a/crates/ailang-check/src/mono.rs b/crates/ailang-check/src/mono.rs index b3dddf3..66ed426 100644 --- a/crates/ailang-check/src/mono.rs +++ b/crates/ailang-check/src/mono.rs @@ -171,6 +171,9 @@ pub(crate) fn mono_target_key(t: &MonoTarget) -> (String, String, String) { /// declared param types. Module-resident fns are still needed /// for non-class-method calls inside instance bodies. pub fn build_workspace_env(ws: &Workspace) -> crate::Env { + // Drift risk: this fn and `crate::check_in_workspace` both + // populate `crate::Env`. If `synth` starts reading a new `Env` + // field, update both paths. let mut env = crate::Env::default(); crate::builtins::install(&mut env); env.workspace_registry = ws.registry.clone(); @@ -180,30 +183,14 @@ pub fn build_workspace_env(ws: &Workspace) -> crate::Env { // env shape is interchangeable. `build_module_globals` may // surface duplicate-def errors for malformed workspaces; the // mono pass's pre-condition is that typecheck has already - // succeeded, so any error here means a caller violated that - // contract — fall back to an empty per-module table to keep - // this builder infallible. + // succeeded, so a failure here is a caller-contract violation. let module_globals_index = crate::build_module_globals(ws) - .unwrap_or_default(); + .expect("build_module_globals: pre-condition (typecheck succeeded) violated"); env.module_globals = module_globals_index .iter() .map(|(mname, g)| (mname.clone(), g.fns.clone())) .collect(); - env.module_types = ws - .modules - .iter() - .map(|(mname, m)| { - let tys: IndexMap = m - .defs - .iter() - .filter_map(|d| match d { - Def::Type(td) => Some((td.name.clone(), td.clone())), - _ => None, - }) - .collect(); - (mname.clone(), tys) - }) - .collect(); + env.module_types = crate::build_module_types(ws); // Workspace-wide class-method table: merge per module's // ModuleGlobals.class_methods.