@@ -3,9 +3,9 @@ use std::iter;
33use rustc_index:: IndexVec ;
44use rustc_index:: bit_set:: DenseBitSet ;
55use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
6- use rustc_middle:: mir:: { Body , Local , UnwindTerminateReason , traversal} ;
6+ use rustc_middle:: mir:: { Local , UnwindTerminateReason , traversal} ;
77use rustc_middle:: mono:: { InstantiationMode , MonoItem } ;
8- use rustc_middle:: ty:: layout:: { FnAbiOf , HasTyCtxt , HasTypingEnv , TyAndLayout } ;
8+ use rustc_middle:: ty:: layout:: { FnAbiOf , HasTyCtxt , TyAndLayout } ;
99use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt , TypeVisitableExt } ;
1010use rustc_middle:: { bug, mir, span_bug} ;
1111use rustc_span:: ErrorGuaranteed ;
@@ -194,7 +194,7 @@ pub fn lower_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
194194 let tcx = cx. tcx ( ) ;
195195 let llfn = cx. get_fn ( instance) ;
196196
197- let mut mir = match MonoItem :: Fn ( instance) . instantiation_mode ( tcx) {
197+ let mir = match MonoItem :: Fn ( instance) . instantiation_mode ( tcx) {
198198 InstantiationMode :: LocalCopy => tcx. build_codegen_mir ( instance) ,
199199 InstantiationMode :: GloballyShared { .. } => {
200200 rustc_mir_transform:: build_codegen_mir ( tcx, instance)
@@ -207,10 +207,6 @@ pub fn lower_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
207207 let fn_abi = cx. fn_abi_of_instance ( instance, ty:: List :: empty ( ) ) ;
208208 debug ! ( "fn_abi: {:?}" , fn_abi) ;
209209
210- if tcx. features ( ) . ergonomic_clones ( ) {
211- mir = tcx. arena . alloc ( optimize_use_clone :: < Bx > ( cx, mir. clone ( ) ) ) ;
212- }
213-
214210 let debug_context = cx. create_function_debug_context ( instance, fn_abi, llfn, & mir) ;
215211
216212 let start_llbb = Bx :: append_block ( cx, llfn, "start" ) ;
@@ -325,65 +321,6 @@ pub fn lower_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
325321 }
326322}
327323
328- /// Replace `clone` calls that come from `use` statements with direct copies if possible.
329- // FIXME: Move this function to mir::transform when post-mono MIR passes land.
330- fn optimize_use_clone < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
331- cx : & ' a Bx :: CodegenCx ,
332- mut mir : Body < ' tcx > ,
333- ) -> Body < ' tcx > {
334- let tcx = cx. tcx ( ) ;
335-
336- if tcx. features ( ) . ergonomic_clones ( ) {
337- for bb in mir. basic_blocks . as_mut ( ) {
338- let mir:: TerminatorKind :: Call {
339- args,
340- destination,
341- target,
342- call_source : mir:: CallSource :: Use ,
343- ..
344- } = & bb. terminator ( ) . kind
345- else {
346- continue ;
347- } ;
348-
349- // CallSource::Use calls always use 1 argument.
350- assert_eq ! ( args. len( ) , 1 ) ;
351- let arg = & args[ 0 ] ;
352-
353- // These types are easily available from locals, so check that before
354- // doing DefId lookups to figure out what we're actually calling.
355- let arg_ty = arg. node . ty ( & mir. local_decls , tcx) ;
356-
357- let ty:: Ref ( _region, inner_ty, mir:: Mutability :: Not ) = * arg_ty. kind ( ) else { continue } ;
358-
359- if !tcx. type_is_copy_modulo_regions ( cx. typing_env ( ) , inner_ty) {
360- continue ;
361- }
362-
363- let Some ( arg_place) = arg. node . place ( ) else { continue } ;
364-
365- let destination_block = target. unwrap ( ) ;
366-
367- bb. statements . push ( mir:: Statement :: new (
368- bb. terminator ( ) . source_info ,
369- mir:: StatementKind :: Assign ( Box :: new ( (
370- * destination,
371- mir:: Rvalue :: Use (
372- mir:: Operand :: Copy (
373- arg_place. project_deeper ( & [ mir:: ProjectionElem :: Deref ] , tcx) ,
374- ) ,
375- mir:: WithRetag :: Yes ,
376- ) ,
377- ) ) ) ,
378- ) ) ;
379-
380- bb. terminator_mut ( ) . kind = mir:: TerminatorKind :: Goto { target : destination_block } ;
381- }
382- }
383-
384- mir
385- }
386-
387324/// Produces, for each argument, a `Value` pointing at the
388325/// argument's value. As arguments are places, these are always
389326/// indirect.
0 commit comments