@@ -411,19 +411,22 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
411411 ( Prim :: FormatF32Le , [ ] ) => read_const ( reader, span, read_f32le, Const :: F32 ) ,
412412 ( Prim :: FormatF64Be , [ ] ) => read_const ( reader, span, read_f64be, Const :: F64 ) ,
413413 ( Prim :: FormatF64Le , [ ] ) => read_const ( reader, span, read_f64le, Const :: F64 ) ,
414- ( Prim :: FormatArray8 , [ FunApp ( len) , FunApp ( format) ] ) => self . read_array ( reader , span , len , format ) ,
415- ( Prim :: FormatArray16 , [ FunApp ( len) , FunApp ( format) ] ) => self . read_array ( reader , span , len , format ) ,
416- ( Prim :: FormatArray32 , [ FunApp ( len) , FunApp ( format) ] ) => self . read_array ( reader , span , len , format ) ,
414+ ( Prim :: FormatArray8 , [ FunApp ( len) , FunApp ( format) ] ) |
415+ ( Prim :: FormatArray16 , [ FunApp ( len) , FunApp ( format) ] ) |
416+ ( Prim :: FormatArray32 , [ FunApp ( len) , FunApp ( format) ] ) |
417417 ( Prim :: FormatArray64 , [ FunApp ( len) , FunApp ( format) ] ) => self . read_array ( reader, span, len, format) ,
418- ( Prim :: FormatArray8Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) => self . array_map ( reader , span , map_fn , array ) ,
419- ( Prim :: FormatArray16Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) => self . array_map ( reader , span , map_fn , array ) ,
420- ( Prim :: FormatArray32Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) => self . array_map ( reader , span , map_fn , array ) ,
418+ ( Prim :: FormatArray8Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) |
419+ ( Prim :: FormatArray16Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) |
420+ ( Prim :: FormatArray32Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) |
421421 ( Prim :: FormatArray64Map , [ _, _, FunApp ( map_fn) , FunApp ( array) ] ) => self . array_map ( reader, span, map_fn, array) ,
422422 ( Prim :: FormatRepeatUntilEnd , [ FunApp ( format) ] ) => self . read_repeat_until_end ( reader, format) ,
423- ( Prim :: FormatRepeatUntilFull , [ FunApp ( len) , FunApp ( format) , FunApp ( replicate) ] ) => self . read_repeat_until_full ( reader, len, replicate, format) ,
424- ( Prim :: FormatLimit8 , [ FunApp ( limit) , FunApp ( format) ] ) => self . read_limit ( reader, limit, format) ,
425- ( Prim :: FormatLimit16 , [ FunApp ( limit) , FunApp ( format) ] ) => self . read_limit ( reader, limit, format) ,
426- ( Prim :: FormatLimit32 , [ FunApp ( limit) , FunApp ( format) ] ) => self . read_limit ( reader, limit, format) ,
423+ ( Prim :: FormatRepeatUntilFull8 , [ FunApp ( len) , FunApp ( format) , FunApp ( replicate) ] ) |
424+ ( Prim :: FormatRepeatUntilFull16 , [ FunApp ( len) , FunApp ( format) , FunApp ( replicate) ] ) |
425+ ( Prim :: FormatRepeatUntilFull32 , [ FunApp ( len) , FunApp ( format) , FunApp ( replicate) ] ) |
426+ ( Prim :: FormatRepeatUntilFull64 , [ FunApp ( len) , FunApp ( format) , FunApp ( replicate) ] ) => self . read_repeat_until_full ( reader, len, replicate, format) ,
427+ ( Prim :: FormatLimit8 , [ FunApp ( limit) , FunApp ( format) ] ) |
428+ ( Prim :: FormatLimit16 , [ FunApp ( limit) , FunApp ( format) ] ) |
429+ ( Prim :: FormatLimit32 , [ FunApp ( limit) , FunApp ( format) ] ) |
427430 ( Prim :: FormatLimit64 , [ FunApp ( limit) , FunApp ( format) ] ) => self . read_limit ( reader, limit, format) ,
428431 ( Prim :: FormatLink , [ FunApp ( pos) , FunApp ( format) ] ) => self . read_link ( span, pos, format) ,
429432 ( Prim :: FormatDeref , [ FunApp ( format) , FunApp ( r#ref) ] ) => self . read_deref ( format, r#ref) ,
@@ -529,9 +532,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
529532 _ => return Err ( ReadError :: InvalidValue ( len. span ( ) ) ) ,
530533 }
531534 . ok_or_else ( || ReadError :: InvalidValue ( len. span ( ) ) ) ?;
532-
533- // TODO: Do we need to force replicate as well?
534- // let replicate = self.elim_env().force(replicate);
535+ let replicate = self . elim_env ( ) . force ( replicate) ;
535536
536537 let mut elems = Vec :: with_capacity ( len) ;
537538 while elems. len ( ) < len {
@@ -544,9 +545,11 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
544545 _ => return Err ( ReadError :: InvalidValue ( replicate. span ( ) ) ) ,
545546 } ;
546547
547- // Push it that many times onto the array
548- // TODO: Error/limit if this exceeds len?
549- elems. extend ( std:: iter:: repeat ( elem) . take ( usize:: from ( repeat) ) ) ;
548+ // Push it that many times onto the array, limiting to the length of the
549+ // output array.
550+ elems. extend (
551+ std:: iter:: repeat ( elem) . take ( usize:: from ( repeat) . min ( len - elems. len ( ) ) ) ,
552+ ) ;
550553 }
551554 Err ( err) => return Err ( err) ,
552555 } ;
0 commit comments