iter 22b.1.1: ClassDef/InstanceDef AST + downstream match arms

Adds Def::Class(ClassDef) and Def::Instance(InstanceDef) variants per
Decision 11 §"Form-A schema". All optional fields (superclass, doc,
default body) carry skip_serializing_if so canonical-JSON bytes of
pre-22b fixtures stay bit-identical.

Downstream match-on-Def sites are extended with explicit Class/Instance
arms. Behaviour for 22b.1 is placeholder (skip in typecheck/codegen,
one-line summary in pretty/manifest, placeholder marker in prose/print)
with TODO comments naming the deferred sub-iters (22b.2 typecheck,
22b.3 codegen, 22b.4 prose-projection arms).
This commit is contained in:
2026-05-09 12:31:23 +02:00
parent 522500a6f6
commit f25d7b6cd6
12 changed files with 264 additions and 4 deletions
+24
View File
@@ -751,6 +751,18 @@ pub fn check(m: &Module) -> Result<CheckedModule> {
name: def.name().to_string(),
args: vec![],
},
// Iter 22b.1: class/instance defs are not yet checked.
// The symbols map is keyed by definition name; class/
// instance contribute their class name, but with no
// concrete pre-monomorphisation type we represent them
// as a placeholder Con. Tools that consume this map
// (`ail diff`, `ail manifest`) read kind separately
// via `def_kind`, so the placeholder type does not
// mislead them.
Def::Class(_) | Def::Instance(_) => Type::Con {
name: def.name().to_string(),
args: vec![],
},
};
symbols.insert(def.name().to_string(), (ty, h));
}
@@ -840,6 +852,10 @@ fn build_module_globals(
name: def_name.to_string(),
args: vec![],
},
// Iter 22b.1: class/instance defs do not contribute
// monomorphic globals to the workspace symbol table
// before 22b.3 monomorphisation runs. Skip them here.
Def::Class(_) | Def::Instance(_) => continue,
};
globals.insert(def_name.to_string(), ty);
}
@@ -944,6 +960,14 @@ fn check_def(def: &Def, env: &Env) -> Result<()> {
Def::Fn(f) => check_fn(f, env),
Def::Const(c) => check_const(c, env),
Def::Type(td) => check_type_def(td, env),
// Iter 22b.1: schema-only landing for class/instance defs.
// Class-schema validation (KindMismatch, InvalidSuperclassParam,
// ConstraintReferencesUnboundTypeVar) and instance-body
// typechecking (with class-method substitution) land in 22b.2.
// Workspace-load coherence checks (Orphan / Duplicate /
// MissingMethod) already fire from `workspace::build_registry`,
// so a malformed instance never reaches this point.
Def::Class(_) | Def::Instance(_) => Ok(()),
}
}
+9
View File
@@ -99,6 +99,11 @@ pub fn lift_letrecs(m: &Module) -> Result<Module> {
name: def.name().to_string(),
args: vec![],
},
// Iter 22b.1: skip class/instance defs in the global-type
// collection. Class methods become globally typed names
// only after 22b.3 monomorphisation; until then there is
// no concrete `Type` to register here.
Def::Class(_) | Def::Instance(_) => continue,
};
env.globals.insert(def.name().to_string(), ty);
}
@@ -186,6 +191,10 @@ pub fn lift_letrecs(m: &Module) -> Result<Module> {
c.value = lifter.lift_in_term(&c.value, &mut locals, &c.name)?;
}
Def::Type(_) => {}
// Iter 22b.1: class/instance defs do not enter the lift
// pass yet. 22b.2 will lift method-body lambdas in instance
// methods; for 22b.1 this is a passthrough.
Def::Class(_) | Def::Instance(_) => {}
}
}
+5
View File
@@ -205,6 +205,11 @@ pub(crate) fn check_module(m: &Module) -> Vec<Diagnostic> {
ctors.insert(name.clone(), fields.clone());
}
}
// Iter 22b.1: class/instance defs are skipped here. Once
// 22b.3 monomorphisation materialises class methods as
// ordinary `FnDef`s, the lift's globals map will pick
// them up automatically.
Def::Class(_) | Def::Instance(_) => {}
}
}
+6
View File
@@ -118,6 +118,12 @@ pub fn infer_module(m: &Module) -> UniquenessTable {
globals.insert(c.name.clone(), strip_forall(&c.ty).clone());
}
Def::Type(_) => {}
// Iter 22b.1: class/instance defs are skipped here. Class
// method signatures contribute global names once
// monomorphisation (22b.3) materialises them; the
// pre-monomorphisation form has no concrete `Type` to
// hand to the uniqueness pass.
Def::Class(_) | Def::Instance(_) => {}
}
}