use std::ptr::null;
use melior::{StringRef, ir::TypeLike};
use mlir_sys::MlirStringRef;
pub fn types_unify_with_prefix<'c>(
lhs: impl TypeLike<'c>,
rhs: impl TypeLike<'c>,
rhs_reverse_prefix: &[StringRef<'_>],
) -> bool {
let rhs_reverse_prefix: Vec<MlirStringRef> = rhs_reverse_prefix
.iter()
.map(|name| name.to_raw())
.collect();
let rhs_reverse_prefix_ptr = if rhs_reverse_prefix.is_empty() {
null()
} else {
rhs_reverse_prefix.as_ptr()
};
unsafe {
llzk_sys::llzkTypesUnify(
lhs.to_raw(),
rhs.to_raw(),
isize::try_from(rhs_reverse_prefix.len()).expect("reverse prefix count too large"),
rhs_reverse_prefix_ptr,
)
}
}
#[inline]
pub fn types_unify<'c>(lhs: impl TypeLike<'c>, rhs: impl TypeLike<'c>) -> bool {
types_unify_with_prefix(lhs, rhs, &[])
}