@@ -1199,10 +1199,7 @@ impl RowGroupsPrunedParquetOpen {
11991199 predicate_cache_records,
12001200 baseline_metrics : prepared. baseline_metrics ,
12011201 } ,
1202- |mut state| async move {
1203- let result = state. transition ( ) . await ;
1204- result. map ( |r| ( r, state) )
1205- } ,
1202+ |state| async move { state. transition ( ) . await } ,
12061203 )
12071204 . fuse ( ) ;
12081205
@@ -1248,15 +1245,15 @@ impl PushDecoderStreamState {
12481245 /// fetched from the [`AsyncFileReader`] and fed back into the decoder.
12491246 /// - [`Data`](DecodeResult::Data) – a decoded batch is projected and returned.
12501247 /// - [`Finished`](DecodeResult::Finished) – signals end-of-stream (`None`).
1251- async fn transition ( & mut self ) -> Option < Result < RecordBatch > > {
1248+ ///
1249+ /// Takes `self` by value (rather than `&mut self`) so the generated future
1250+ /// owns the state directly. This avoids a Stacked Borrows violation under
1251+ /// miri where `&mut self` creates a single opaque borrow that conflicts
1252+ /// with `unfold`'s ownership across yield points.
1253+ async fn transition ( mut self ) -> Option < ( Result < RecordBatch > , Self ) > {
12521254 loop {
12531255 match self . decoder . try_decode ( ) {
12541256 Ok ( DecodeResult :: NeedsData ( ranges) ) => {
1255- // IO (get_byte_ranges) and CPU (push_ranges) are still
1256- // decoupled — they just can't live in a nested async block
1257- // because that captures `&mut self` as one opaque borrow,
1258- // which violates Stacked Borrows across the yield point.
1259- // Inlining lets the compiler split the disjoint field borrows.
12601257 let data = self
12611258 . reader
12621259 . get_byte_ranges ( ranges. clone ( ) )
@@ -1265,24 +1262,26 @@ impl PushDecoderStreamState {
12651262 match data {
12661263 Ok ( data) => {
12671264 if let Err ( e) = self . decoder . push_ranges ( ranges, data) {
1268- return Some ( Err ( DataFusionError :: from ( e) ) ) ;
1265+ return Some ( ( Err ( DataFusionError :: from ( e) ) , self ) ) ;
12691266 }
12701267 }
1271- Err ( e) => return Some ( Err ( e) ) ,
1268+ Err ( e) => return Some ( ( Err ( e) , self ) ) ,
12721269 }
12731270 }
12741271 Ok ( DecodeResult :: Data ( batch) ) => {
12751272 let mut timer = self . baseline_metrics . elapsed_compute ( ) . timer ( ) ;
12761273 self . copy_arrow_reader_metrics ( ) ;
12771274 let result = self . project_batch ( & batch) ;
12781275 timer. stop ( ) ;
1279- return Some ( result) ;
1276+ // Release the borrow on baseline_metrics before moving self
1277+ drop ( timer) ;
1278+ return Some ( ( result, self ) ) ;
12801279 }
12811280 Ok ( DecodeResult :: Finished ) => {
12821281 return None ;
12831282 }
12841283 Err ( e) => {
1285- return Some ( Err ( DataFusionError :: from ( e) ) ) ;
1284+ return Some ( ( Err ( DataFusionError :: from ( e) ) , self ) ) ;
12861285 }
12871286 }
12881287 }
0 commit comments