Skip to content

Commit d9cbd36

Browse files
committed
Revert "Bind Symbol to the engine using lifetime not Rc"
This reverts commit 05f768e.
1 parent 949634d commit d9cbd36

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

examples/jit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use std::error::Error;
1414
/// do `unsafe` operations internally.
1515
type SumFunc = unsafe extern "C" fn(u64, u64, u64) -> u64;
1616

17-
fn jit_compile_sum<'engine>(
17+
fn jit_compile_sum(
1818
context: &Context,
1919
module: &Module,
2020
builder: &Builder,
21-
execution_engine: &'engine ExecutionEngine,
22-
) -> Option<JitFunction<'engine, SumFunc>> {
21+
execution_engine: &ExecutionEngine,
22+
) -> Option<JitFunction<SumFunc>> {
2323
let i64_type = context.i64_type();
2424
let fn_type = i64_type.fn_type(&[i64_type.into(), i64_type.into(), i64_type.into()], false);
2525

src/execution_engine.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::rc::Rc;
1111
use std::ops::Deref;
1212
use std::ffi::CString;
1313
use std::fmt::{self, Debug, Display, Formatter};
14-
use std::marker::PhantomData;
1514
use std::mem::{forget, zeroed, transmute_copy, size_of};
1615

1716
#[derive(Debug, PartialEq, Eq)]
@@ -286,7 +285,7 @@ impl ExecutionEngine {
286285
/// method *may* invalidate the function pointer.
287286
///
288287
/// [`UnsafeFunctionPointer`]: trait.UnsafeFunctionPointer.html
289-
pub unsafe fn get_function<'engine, F>(&'engine self, fn_name: &str) -> Result<JitFunction<'engine, F>, FunctionLookupError>
288+
pub unsafe fn get_function<F>(&self, fn_name: &str) -> Result<JitFunction<F>, FunctionLookupError>
290289
where
291290
F: UnsafeFunctionPointer,
292291
{
@@ -315,7 +314,7 @@ impl ExecutionEngine {
315314
"The type `F` must have the same size as a function pointer");
316315

317316
Ok(JitFunction {
318-
_execution_engine: PhantomData,
317+
_execution_engine: self.execution_engine.clone(),
319318
inner: transmute_copy(&address),
320319
})
321320
}
@@ -436,12 +435,12 @@ impl Deref for ExecEngineInner {
436435
/// A wrapper around a function pointer which ensures the function being pointed
437436
/// to doesn't accidentally outlive its execution engine.
438437
#[derive(Clone)]
439-
pub struct JitFunction<'engine, F> {
440-
_execution_engine: PhantomData<&'engine ExecutionEngine>,
438+
pub struct JitFunction<F> {
439+
_execution_engine: ExecEngineInner,
441440
inner: F,
442441
}
443442

444-
impl<'engine, F> Debug for JitFunction<'engine, F> {
443+
impl<F> Debug for JitFunction<F> {
445444
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
446445
f.debug_tuple("JitFunction")
447446
.field(&"<unnamed>")
@@ -470,9 +469,9 @@ macro_rules! impl_unsafe_fn {
470469
(@recurse) => {};
471470

472471
($( $param:ident ),*) => {
473-
impl<'engine, Output, $( $param ),*> private::SealedUnsafeFunctionPointer for unsafe extern "C" fn($( $param ),*) -> Output {}
472+
impl<Output, $( $param ),*> private::SealedUnsafeFunctionPointer for unsafe extern "C" fn($( $param ),*) -> Output {}
474473

475-
impl<'engine, Output, $( $param ),*> JitFunction<'engine, unsafe extern "C" fn($( $param ),*) -> Output> {
474+
impl<Output, $( $param ),*> JitFunction<unsafe extern "C" fn($( $param ),*) -> Output> {
476475
/// This method allows you to call the underlying function while making
477476
/// sure that the backing storage is not dropped too early and
478477
/// preserves the `unsafe` marker for any calls.

0 commit comments

Comments
 (0)