Skip to content

Commit 29ef85d

Browse files
authored
Refactor (#709)
1 parent 92585d0 commit 29ef85d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

melior/src/ir/operation/operation_like.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::Display;
1+
use std::{ffi::c_void, fmt::Display};
22

33
use mlir_sys::{
44
mlirOperationDump, mlirOperationGetAttribute, mlirOperationGetAttributeByName,
@@ -274,21 +274,23 @@ pub trait OperationLike<'c: 'a, 'a>: Display + 'a {
274274
F: for<'x, 'y> FnMut(OperationRef<'x, 'y>) -> WalkResult,
275275
{
276276
// trampoline from C to Rust
277-
unsafe extern "C" fn tramp<F>(
278-
raw: MlirOperation,
279-
user_data: *mut std::os::raw::c_void,
280-
) -> MlirWalkResult
281-
where
282-
F: for<'x, 'y> FnMut(OperationRef<'x, 'y>) -> WalkResult,
283-
{
284-
let cb: &mut F = &mut *(user_data as *mut F);
285-
let op = OperationRef::from_raw(raw);
286-
(cb)(op) as MlirWalkResult
277+
unsafe extern "C" fn tramp<'c: 'a, 'a, F: FnMut(OperationRef<'c, 'a>) -> WalkResult>(
278+
operation: MlirOperation,
279+
data: *mut c_void,
280+
) -> MlirWalkResult {
281+
let callback: &mut F = &mut *(data as *mut F);
282+
let operation = OperationRef::from_raw(operation);
283+
284+
(callback)(operation) as _
287285
}
288286

289-
let data = &mut callback as *mut _ as *mut std::os::raw::c_void;
290287
unsafe {
291-
mlirOperationWalk(self.to_raw(), Some(tramp::<F>), data, order as _);
288+
mlirOperationWalk(
289+
self.to_raw(),
290+
Some(tramp::<'c, 'a, F>),
291+
&mut callback as *mut _ as *mut _,
292+
order as _,
293+
);
292294
}
293295
}
294296
}

0 commit comments

Comments
 (0)