@@ -15,6 +15,7 @@ use cranelift_jit::{JITBuilder, JITModule};
1515use cranelift_module:: { DataDescription , FuncId , Linkage , Module } ;
1616use log:: { debug, error, info, warn} ;
1717use std:: collections:: HashMap ;
18+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
1819use std:: sync:: { Arc , RwLock } ;
1920
2021use crate :: effect_codegen:: {
@@ -28,6 +29,18 @@ use crate::hir::{
2829} ;
2930use crate :: { CompilerError , CompilerResult } ;
3031
32+ static CRANELIFT_SKIPPED_FUNCTIONS : AtomicUsize = AtomicUsize :: new ( 0 ) ;
33+
34+ /// Number of function bodies skipped by Cranelift due to recoverable codegen errors.
35+ pub fn cranelift_skipped_function_count ( ) -> usize {
36+ CRANELIFT_SKIPPED_FUNCTIONS . load ( Ordering :: Relaxed )
37+ }
38+
39+ /// Reset Cranelift skip diagnostics counter.
40+ pub fn reset_cranelift_skipped_function_count ( ) {
41+ CRANELIFT_SKIPPED_FUNCTIONS . store ( 0 , Ordering :: Relaxed ) ;
42+ }
43+
3144/// Convert ZRTL TypeTag to Cranelift type
3245fn type_tag_to_cranelift_type ( tag : & crate :: zrtl:: TypeTag ) -> types:: Type {
3346 use crate :: zrtl:: { PrimitiveSize , TypeCategory } ;
@@ -372,6 +385,7 @@ impl CraneliftBackend {
372385 if !function. is_external {
373386 // Skip functions that fail to compile (e.g., signature mismatches with ZRTL)
374387 if let Err ( e) = self . compile_function_body ( * id, function, module) {
388+ CRANELIFT_SKIPPED_FUNCTIONS . fetch_add ( 1 , Ordering :: Relaxed ) ;
375389 eprintln ! (
376390 "[CRANELIFT WARN] Skipping function '{}': {:?}" ,
377391 function. name, e
@@ -4061,10 +4075,16 @@ impl CraneliftBackend {
40614075 // Function pointers
40624076 Ok ( self . module . target_config ( ) . pointer_type ( ) )
40634077 }
4064- HirType :: Vector ( elem_ty, _count) => {
4065- // Vector types for SIMD - use the element type for now
4066- self . translate_type ( elem_ty)
4067- }
4078+ HirType :: Vector ( elem_ty, count) => match ( & * * elem_ty, * count) {
4079+ ( HirType :: F32 , 4 ) => Ok ( types:: F32X4 ) ,
4080+ ( HirType :: F64 , 2 ) => Ok ( types:: F64X2 ) ,
4081+ ( HirType :: I32 , 4 ) | ( HirType :: U32 , 4 ) => Ok ( types:: I32X4 ) ,
4082+ ( HirType :: I64 , 2 ) | ( HirType :: U64 , 2 ) => Ok ( types:: I64X2 ) ,
4083+ _ => Err ( CompilerError :: CodeGen ( format ! (
4084+ "unsupported SIMD vector lane shape in Cranelift backend: Vector({:?}, {})" ,
4085+ elem_ty, count
4086+ ) ) ) ,
4087+ } ,
40684088 HirType :: Union ( _) => {
40694089 // Unions are treated as pointers to stack-allocated memory
40704090 Ok ( self . module . target_config ( ) . pointer_type ( ) )
0 commit comments