feat(jit): fix segfault

This commit is contained in:
2025-05-18 17:07:49 +08:00
parent f98d623c13
commit af5a312e1e
10 changed files with 115 additions and 111 deletions

View File

@@ -1,5 +1,6 @@
use std::cell::{Cell, OnceCell};
use inkwell::execution_engine::JitFunction;
use itertools::Itertools;
use derive_more::Constructor;
@@ -41,21 +42,21 @@ impl From<ir::Param> for Param {
}
#[derive(Debug, Clone, Constructor)]
pub struct Func<'vm> {
pub struct Func<'jit: 'vm, 'vm> {
pub func: &'vm BFunc,
pub env: Env<'vm>,
pub compiled: OnceCell<&'vm JITFunc<'vm>>,
pub env: Env<'jit, 'vm>,
pub compiled: OnceCell<JitFunction<'jit, JITFunc<'jit, 'vm>>>,
pub count: Cell<usize>
}
impl<'vm, 'jit: 'vm> Func<'vm> {
pub fn call(&self, vm: &'vm VM<'jit>, arg: Value<'vm>) -> Result<Value<'vm>> {
impl<'vm, 'jit: 'vm> Func<'jit, 'vm> {
pub fn call(&self, vm: &'vm VM<'jit>, arg: Value<'jit, 'vm>) -> Result<Value<'jit, 'vm>> {
use Param::*;
let count = self.count.get();
if count >= 1 {
let compiled = self.compiled.get_or_init(|| vm.compile_func(self.func));
let ret = compiled(vm as _, &self.env as _, arg.into());
let ret = unsafe { compiled.call(vm as _, &self.env as _, arg.into()) };
return Ok(ret.into())
}
self.count.replace(count + 1);
@@ -101,7 +102,7 @@ impl<'vm, 'jit: 'vm> Func<'vm> {
}
}
impl PartialEq for Func<'_> {
impl PartialEq for Func<'_, '_> {
fn eq(&self, _: &Self) -> bool {
false
}