Skip to content

Commit 8d89149

Browse files
committed
feat: complete type checker and multi-paradigm type system
- Phase 0: Convert debug eprintln! to log::trace! across ssa.rs, lowering.rs, cranelift_backend.rs (209 lines noise → 4 lines) - Phase 1: Implement 15 unimplemented expression type checks (Array, Tuple, Struct, Lambda, Match, If, Cast, Try, Reference, Dereference, Range, Block, ListComprehension, Slice, Await) - Phase 2: Replace pattern checking stub with comprehensive validation for all pattern variants (Wildcard, Identifier, Literal, Tuple, Struct, Enum, Array, Or, Guard, Rest, Reference, Box) - Phase 3: Add generic type parameter substitution in TypeRegistry and wire into field access and method return types - Phase 4: Implement trait method resolution with 3-stage lookup (inherent → trait defs → impl methods), trait bound verification, and optional parameter arity with varargs support - Phase 5: Wire multi-paradigm checkers into main TypeChecker with paradigm fields, lazy-loaded sub-checkers, structural compatibility, linear type pass; fix todo!() panics in multi_paradigm_checker; complete nominal subtype checking with variance and widening - Phase 6: Eliminate all 17 todo!() panics in constraint_solver for Type::Interface, Type::Struct, Type::Trait handling in substitution, formatting, associated type resolution, and self-type substitution; add TypeKind member resolution for Atomic, Class, Function, Array
1 parent 6460ce8 commit 8d89149

9 files changed

Lines changed: 1619 additions & 334 deletions

File tree

crates/compiler/src/cranelift_backend.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl CraneliftBackend {
371371
// Dump HIR if ZYNTAX_DUMP_HIR is set
372372
if std::env::var("ZYNTAX_DUMP_HIR").is_ok() {
373373
let dump = crate::hir_dump::dump_module(module);
374-
eprintln!("{}", dump);
374+
log::trace!("{}", dump);
375375
}
376376

377377
// Process globals first (including vtables)
@@ -396,10 +396,7 @@ impl CraneliftBackend {
396396
// Skip functions that fail to compile (e.g., signature mismatches with ZRTL)
397397
if let Err(e) = self.compile_function_body(*id, function, module) {
398398
CRANELIFT_SKIPPED_FUNCTIONS.fetch_add(1, Ordering::Relaxed);
399-
eprintln!(
400-
"[CRANELIFT WARN] Skipping function '{}': {:?}",
401-
function.name, e
402-
);
399+
log::debug!("[CRANELIFT] Skipping function '{}': {:?}", function.name, e);
403400
// Remove from function_map to prevent later lookup failures
404401
self.function_map.remove(id);
405402
}
@@ -732,19 +729,23 @@ impl CraneliftBackend {
732729
/// Note: This legacy path does not support algebraic effects. Use compile_module() for
733730
/// full effect support.
734731
pub fn compile_function(&mut self, id: HirId, function: &HirFunction) -> CompilerResult<()> {
735-
eprintln!("[Backend] compile_function called for {:?}", id);
732+
log::trace!("[Backend] compile_function called for {:?}", id);
736733
let empty_module_for_decl =
737734
HirModule::new(zyntax_typed_ast::InternedString::new_global("__legacy__"));
738735
self.declare_function(id, function, &empty_module_for_decl)?;
739-
eprintln!("[Backend] After declare_function, IR:");
740-
eprintln!("{}", self.codegen_context.func);
736+
log::trace!(
737+
"[Backend] After declare_function, IR:\n{}",
738+
self.codegen_context.func
739+
);
741740
if !function.is_external {
742741
// Create empty module for legacy path (effects won't work)
743742
let empty_module =
744743
HirModule::new(zyntax_typed_ast::InternedString::new_global("__legacy__"));
745744
self.compile_function_body(id, function, &empty_module)?;
746-
eprintln!("[Backend] After compile_function_body, IR:");
747-
eprintln!("{}", self.codegen_context.func);
745+
log::trace!(
746+
"[Backend] After compile_function_body, IR:\n{}",
747+
self.codegen_context.func
748+
);
748749
}
749750
Ok(())
750751
}
@@ -1149,9 +1150,10 @@ impl CraneliftBackend {
11491150
);
11501151
let ptr = builder.ins().stack_addr(pointer_type, slot, 0);
11511152
self.value_map.insert(value.id, ptr);
1152-
eprintln!(
1153+
log::trace!(
11531154
"[CRANELIFT UNDEF] Allocated {} bytes stack for aggregate undef {:?}",
1154-
alloc_size, value.id
1155+
alloc_size,
1156+
value.id
11551157
);
11561158
} else {
11571159
// For scalar types, use zero constant
@@ -2361,7 +2363,7 @@ impl CraneliftBackend {
23612363
let func_ptr_val = match self.value_map.get(func_ptr).copied() {
23622364
Some(v) => v,
23632365
None => {
2364-
eprintln!("[WARN] IndirectCall: func_ptr {:?} not found in value_map! Using 0.", func_ptr);
2366+
log::trace!("[WARN] IndirectCall: func_ptr {:?} not found in value_map! Using 0.", func_ptr);
23652367
builder.ins().iconst(types::I64, 0)
23662368
}
23672369
};
@@ -3782,7 +3784,7 @@ impl CraneliftBackend {
37823784
};
37833785
cranelift_vals.push(coerced);
37843786
} else {
3785-
eprintln!(
3787+
log::trace!(
37863788
"[Cranelift ERROR] Return value {:?} not in value_map",
37873789
v
37883790
);
@@ -4093,12 +4095,10 @@ impl CraneliftBackend {
40934095

40944096
// Verify the generated IR (catches errors before they become cryptic panics)
40954097
if let Err(errors) = verify_function(&self.codegen_context.func, self.module.isa()) {
4096-
error!(
4097-
"[Cranelift] IR verification failed for function '{}':",
4098-
function.name
4098+
debug!(
4099+
"[Cranelift] IR verification failed for function '{}': {}",
4100+
function.name, errors
40994101
);
4100-
error!(" {}", errors);
4101-
debug!("Function IR dump:\n{}", self.codegen_context.func.display());
41024102
return Err(CompilerError::Backend(format!(
41034103
"Cranelift IR verification failed for function '{}': {}",
41044104
function.name, errors
@@ -5950,33 +5950,27 @@ impl CraneliftBackend {
59505950
op,
59515951
operand,
59525952
} => {
5953-
eprintln!(
5953+
log::trace!(
59545954
"[Cranelift Cast] operand={:?}, op={:?}, target_ty={:?}",
5955-
operand, op, ty
5955+
operand,
5956+
op,
5957+
ty
59565958
);
59575959
let val = self
59585960
.value_map
59595961
.get(operand)
59605962
.copied()
59615963
.unwrap_or_else(|| panic!("Cast operand {:?} not in value_map", operand));
59625964
let target_ty = self.translate_type(ty)?;
5963-
eprintln!("[Cranelift Cast] val={:?}, target_ty={:?}", val, target_ty);
5965+
log::trace!("[Cranelift Cast] val={:?}, target_ty={:?}", val, target_ty);
59645966

59655967
let cast_val = match op {
59665968
crate::hir::CastOp::Bitcast => {
59675969
// Bitcast - just return the value for now
59685970
val
59695971
}
59705972
crate::hir::CastOp::ZExt => builder.ins().uextend(target_ty, val),
5971-
crate::hir::CastOp::SExt => {
5972-
eprintln!(
5973-
"[Cranelift Cast] Doing sextend from val={:?} to target_ty={:?}",
5974-
val, target_ty
5975-
);
5976-
let result = builder.ins().sextend(target_ty, val);
5977-
eprintln!("[Cranelift Cast] sextend result={:?}", result);
5978-
result
5979-
}
5973+
crate::hir::CastOp::SExt => builder.ins().sextend(target_ty, val),
59805974
crate::hir::CastOp::Trunc => builder.ins().ireduce(target_ty, val),
59815975
crate::hir::CastOp::FpToUi => builder.ins().fcvt_to_uint(target_ty, val),
59825976
crate::hir::CastOp::FpToSi => builder.ins().fcvt_to_sint(target_ty, val),

0 commit comments

Comments
 (0)