@@ -387,7 +387,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
387
387
current,
388
388
place,
389
389
ty,
390
- vec ! [ ] ,
390
+ Box :: new ( [ ] ) ,
391
391
expr_id. into ( ) ,
392
392
) ?;
393
393
}
@@ -561,7 +561,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
561
561
} ;
562
562
self . push_assignment ( current, ref_mut_iterator_place. clone ( ) , Rvalue :: Ref ( BorrowKind :: Mut { allow_two_phase_borrow : false } , iterator_place) , expr_id. into ( ) ) ;
563
563
self . lower_loop ( current, place, label, expr_id. into ( ) , |this, begin| {
564
- let Some ( current) = this. lower_call ( iter_next_fn_op, vec ! [ Operand :: Copy ( ref_mut_iterator_place) ] , option_item_place. clone ( ) , begin, false , expr_id. into ( ) ) ?
564
+ let Some ( current) = this. lower_call ( iter_next_fn_op, Box :: new ( [ Operand :: Copy ( ref_mut_iterator_place) ] ) , option_item_place. clone ( ) , begin, false , expr_id. into ( ) ) ?
565
565
else {
566
566
return Ok ( ( ) ) ;
567
567
} ;
@@ -758,8 +758,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
758
758
match x {
759
759
Some ( x) => x,
760
760
None => {
761
- let mut p = sp. clone ( ) ;
762
- p. projection . push ( ProjectionElem :: Field ( FieldId {
761
+ let p = sp. project ( ProjectionElem :: Field ( FieldId {
763
762
parent : variant_id,
764
763
local_id : LocalFieldId :: from_raw ( RawIdx :: from ( i as u32 ) ) ,
765
764
} ) ) ;
@@ -782,10 +781,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
782
781
} ;
783
782
let local_id =
784
783
variant_data. field ( name) . ok_or ( MirLowerError :: UnresolvedField ) ?;
785
- let mut place = place;
786
- place
787
- . projection
788
- . push ( PlaceElem :: Field ( FieldId { parent : union_id. into ( ) , local_id } ) ) ;
784
+ let place = place. project ( PlaceElem :: Field ( FieldId { parent : union_id. into ( ) , local_id } ) ) ;
789
785
self . lower_expr_to_place ( * expr, place, current)
790
786
}
791
787
}
@@ -826,8 +822,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
826
822
let Some ( ( operand, current) ) = self . lower_expr_to_some_operand ( * expr, current) ? else {
827
823
return Ok ( None ) ;
828
824
} ;
829
- let mut p = place;
830
- p. projection . push ( ProjectionElem :: Deref ) ;
825
+ let p = place. project ( ProjectionElem :: Deref ) ;
831
826
self . push_assignment ( current, p, operand. into ( ) , expr_id. into ( ) ) ;
832
827
Ok ( Some ( current) )
833
828
} ,
@@ -1031,7 +1026,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
1031
1026
self . push_assignment (
1032
1027
current,
1033
1028
place,
1034
- Rvalue :: Aggregate ( AggregateKind :: Closure ( ty) , operands) ,
1029
+ Rvalue :: Aggregate ( AggregateKind :: Closure ( ty) , operands. into ( ) ) ,
1035
1030
expr_id. into ( ) ,
1036
1031
) ;
1037
1032
Ok ( Some ( current) )
@@ -1128,11 +1123,11 @@ impl<'ctx> MirLowerCtx<'ctx> {
1128
1123
let index = name
1129
1124
. as_tuple_index ( )
1130
1125
. ok_or ( MirLowerError :: TypeError ( "named field on tuple" ) ) ?;
1131
- place. projection . push ( ProjectionElem :: TupleOrClosureField ( index) )
1126
+ * place = place . project ( ProjectionElem :: TupleOrClosureField ( index) )
1132
1127
} else {
1133
1128
let field =
1134
1129
self . infer . field_resolution ( expr_id) . ok_or ( MirLowerError :: UnresolvedField ) ?;
1135
- place. projection . push ( ProjectionElem :: Field ( field) ) ;
1130
+ * place = place . project ( ProjectionElem :: Field ( field) ) ;
1136
1131
}
1137
1132
} else {
1138
1133
not_supported ! ( "" )
@@ -1242,7 +1237,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
1242
1237
prev_block : BasicBlockId ,
1243
1238
place : Place ,
1244
1239
ty : Ty ,
1245
- fields : Vec < Operand > ,
1240
+ fields : Box < [ Operand ] > ,
1246
1241
span : MirSpan ,
1247
1242
) -> Result < BasicBlockId > {
1248
1243
let subst = match ty. kind ( Interner ) {
@@ -1280,13 +1275,13 @@ impl<'ctx> MirLowerCtx<'ctx> {
1280
1275
else {
1281
1276
return Ok ( None ) ;
1282
1277
} ;
1283
- self . lower_call ( func, args, place, current, is_uninhabited, span)
1278
+ self . lower_call ( func, args. into ( ) , place, current, is_uninhabited, span)
1284
1279
}
1285
1280
1286
1281
fn lower_call (
1287
1282
& mut self ,
1288
1283
func : Operand ,
1289
- args : Vec < Operand > ,
1284
+ args : Box < [ Operand ] > ,
1290
1285
place : Place ,
1291
1286
current : BasicBlockId ,
1292
1287
is_uninhabited : bool ,
@@ -1744,12 +1739,13 @@ pub fn mir_body_for_closure_query(
1744
1739
match r {
1745
1740
Some ( x) => {
1746
1741
p. local = closure_local;
1747
- let prev_projs =
1748
- mem:: replace ( & mut p. projection , vec ! [ PlaceElem :: TupleOrClosureField ( x . 1 ) ] ) ;
1742
+ let mut next_projs = vec ! [ PlaceElem :: TupleOrClosureField ( x . 1 ) ] ;
1743
+ let prev_projs = mem:: take ( & mut p. projection ) ;
1749
1744
if x. 0 . kind != CaptureKind :: ByValue {
1750
- p . projection . push ( ProjectionElem :: Deref ) ;
1745
+ next_projs . push ( ProjectionElem :: Deref ) ;
1751
1746
}
1752
- p. projection . extend ( prev_projs. into_iter ( ) . skip ( x. 0 . place . projections . len ( ) ) ) ;
1747
+ next_projs. extend ( prev_projs. iter ( ) . cloned ( ) . skip ( x. 0 . place . projections . len ( ) ) ) ;
1748
+ p. projection = next_projs. into ( ) ;
1753
1749
}
1754
1750
None => err = Some ( p. clone ( ) ) ,
1755
1751
}
@@ -1764,6 +1760,7 @@ pub fn mir_body_for_closure_query(
1764
1760
if let Some ( err) = err {
1765
1761
return Err ( MirLowerError :: UnresolvedUpvar ( err) ) ;
1766
1762
}
1763
+ ctx. result . shrink_to_fit ( ) ;
1767
1764
Ok ( Arc :: new ( ctx. result ) )
1768
1765
}
1769
1766
@@ -1780,7 +1777,8 @@ pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<Mi
1780
1777
} ) ;
1781
1778
let body = db. body ( def) ;
1782
1779
let infer = db. infer ( def) ;
1783
- let result = lower_to_mir ( db, def, & body, & infer, body. body_expr ) ?;
1780
+ let mut result = lower_to_mir ( db, def, & body, & infer, body. body_expr ) ?;
1781
+ result. shrink_to_fit ( ) ;
1784
1782
Ok ( Arc :: new ( result) )
1785
1783
}
1786
1784
0 commit comments