Skip to content

Commit 9c041fb

Browse files
Fix lint "elided_named_lifetimes"
And some dogfood.
1 parent 3bf7b49 commit 9c041fb

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

src/eager/op.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use libc::c_void;
77
use libc::size_t;
88
use std::ffi::{CStr, CString};
99
use std::marker::PhantomData;
10-
use std::mem::{self, ManuallyDrop};
10+
use std::mem::ManuallyDrop;
1111
use std::os::raw::c_void as std_c_void;
1212
use std::ptr;
1313

@@ -365,7 +365,7 @@ impl<'a> Op<'a> {
365365
/// For sync execution, if any of the inputs to `op` are not ready, this call
366366
/// will block till they become ready and then return when the kernel execution
367367
/// is done.
368-
fn execute<const N: usize>(self, ctx: &'a Context) -> Result<[TensorHandle; N]> {
368+
fn execute<const N: usize>(self, ctx: &'a Context) -> Result<[TensorHandle<'a>; N]> {
369369
let status = Status::new();
370370

371371
let mut num_retvals = N as i32;
@@ -399,23 +399,8 @@ impl<'a> Op<'a> {
399399
return Err(status);
400400
}
401401

402-
let mut handles_uninit: [mem::MaybeUninit<TensorHandle>; N] =
403-
unsafe { mem::MaybeUninit::uninit().assume_init() };
404-
405-
for i in 0..N {
406-
let t = unsafe { TensorHandle::from_tensor_handle(ctx, retvals[i]) };
407-
handles_uninit[i].write(t);
408-
}
409-
410-
// Transmute uninitialized handles to initialized handles. Ideally, we would use
411-
// `mem::transmute` here, but it is not stable yet for generic sized arrays.
412-
// ref : https://github.com/rust-lang/rust/issues/61956
413-
//
414-
// Following is a workaround for this issue:
415-
// Using &mut as an assertion of unique "ownership"
416-
let ptr = &mut handles_uninit as *mut _ as *mut [TensorHandle; N];
417-
let handles: [TensorHandle; N] = unsafe { ptr.read() };
418-
mem::forget(handles_uninit);
402+
let handles: [TensorHandle; N] =
403+
std::array::from_fn(|i| unsafe { TensorHandle::from_tensor_handle(ctx, retvals[i]) });
419404

420405
Ok(handles)
421406
}

src/eager/readonly_tensor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use crate::tf;
12
use crate::{
23
write_tensor_recursive, AnyTensor, DataType, Result, Shape, Tensor, TensorInner, TensorType,
34
};
45
use core::fmt;
56
use fmt::{Debug, Formatter};
67
use libc::c_int;
78
use std::{fmt::Display, ops::Deref};
8-
use tensorflow_sys as tf;
99

1010
/// A read-only tensor.
1111
///

src/eager/tensor_handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::{AnyTensor, DataType, Result, Status, TensorType};
6464
#[derive(Debug)]
6565
pub struct TensorHandle<'a> {
6666
pub(super) inner: *mut tf::TFE_TensorHandle,
67-
// TensorHandle should not live longer than a given context.
67+
// TensorHandle canjot outlive its associated context
6868
ctx: PhantomData<&'a Context>,
6969
}
7070

0 commit comments

Comments
 (0)