@@ -65,7 +65,7 @@ impl BorrowCache {
6565
6666 pub fn add_or_get_mut < ' a , T , D , S > (
6767 & mut self ,
68- device : & D ,
68+ device : & ' a D ,
6969 id : Id ,
7070 new_buf : & mut bool ,
7171 ) -> & mut Buffer < ' a , T , D , S >
@@ -75,7 +75,7 @@ impl BorrowCache {
7575 S : Shape ,
7676 {
7777 self . add_buf_once :: < T , D , S > ( device, id, new_buf) ;
78- self . get_buf_mut ( id) . unwrap ( )
78+ unsafe { self . get_buf_mut ( id) . unwrap ( ) }
7979 }
8080
8181 pub fn add_buf_once < T , D , S > ( & mut self , device : & D , id : Id , new_buf : & mut bool )
@@ -91,7 +91,7 @@ impl BorrowCache {
9191 self . add_buf :: < T , D , S > ( device, id)
9292 }
9393
94- pub fn add_buf < T , D , S > ( & mut self , device : & D , id : Id )
94+ pub fn add_buf < ' a , T , D , S > ( & ' a mut self , device : & ' a D , id : Id )
9595 where
9696 T : Unit + ' static ,
9797 D : Alloc < T > + ' static ,
@@ -123,7 +123,7 @@ impl BorrowCache {
123123 }
124124
125125 #[ inline]
126- pub fn get_buf < ' a , T , D , S > ( & self , id : Id ) -> Result < & Buffer < ' a , T , D , S > , CachingError >
126+ pub unsafe fn get_buf < ' a , T , D , S > ( & self , id : Id ) -> Result < & Buffer < ' a , T , D , S > , CachingError >
127127 where
128128 T : Unit + ' static ,
129129 D : Device + ' static ,
@@ -137,7 +137,7 @@ impl BorrowCache {
137137 }
138138
139139 #[ inline]
140- pub fn get_buf_mut < ' a , T , D , S > (
140+ pub unsafe fn get_buf_mut < ' a , T , D , S > (
141141 & mut self ,
142142 id : Id ,
143143 ) -> Result < & mut Buffer < ' a , T , D , S > , CachingError >
@@ -161,16 +161,21 @@ impl BorrowCache {
161161#[ cfg( test) ]
162162mod tests {
163163
164- /*#[test]
165- fn test_comp_error() {
166- let device = CPU::<Base>::new();
164+ // #[test]
165+ // #[cfg(feature = "cpu")]
166+ // fn test_comp_error() {
167+ // use crate::{Base, BorrowCache, Id, CPU};
167168
169+ // let mut cache = BorrowCache::default();
168170
169- let a = {
170- let mut cache = BorrowingCache::default();
171- cache.add_or_get::<f32, CPU, ()>(&device, Id::new(10))
172- };
173- }*/
171+
172+ // let a = {
173+ // let device = CPU::<Base>::new();
174+ // // drop(device);
175+ // let mut new_buf = false;
176+ // // cache.add_or_get::<f32, CPU, ()>(&device, Id { id: 0, len: 10}, &mut new_buf)
177+ // };
178+ // }
174179
175180 #[ cfg( feature = "cpu" ) ]
176181 #[ test]
@@ -190,8 +195,8 @@ mod tests {
190195 cache. add_buf_once :: < f32 , _ , ( ) > ( & device, sid, & mut false ) ;
191196 cache. add_buf_once :: < f32 , _ , ( ) > ( & device, tid, & mut false ) ;
192197
193- let a: & Buffer = cache. get_buf :: < f32 , _ , ( ) > ( fid) . unwrap ( ) ;
194- let b: & Buffer = cache. get_buf :: < f32 , _ , ( ) > ( fid) . unwrap ( ) ;
198+ let a: & Buffer = unsafe { cache. get_buf :: < f32 , _ , ( ) > ( fid) . unwrap ( ) } ;
199+ let b: & Buffer = unsafe { cache. get_buf :: < f32 , _ , ( ) > ( fid) . unwrap ( ) } ;
195200
196201 assert_eq ! ( a. ptr, b. ptr) ;
197202 }
0 commit comments