1
- //! This pass lowers calls to core::slice::len to just Len op.
1
+ //! This pass lowers calls to core::slice::len to just PtrMetadata op.
2
2
//! It should run before inlining!
3
3
4
4
use rustc_hir:: def_id:: DefId ;
5
- use rustc_index:: IndexSlice ;
6
5
use rustc_middle:: mir:: * ;
7
- use rustc_middle:: ty:: { self , TyCtxt } ;
6
+ use rustc_middle:: ty:: TyCtxt ;
8
7
9
8
pub struct LowerSliceLenCalls ;
10
9
@@ -29,16 +28,11 @@ pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
29
28
let basic_blocks = body. basic_blocks . as_mut_preserves_cfg ( ) ;
30
29
for block in basic_blocks {
31
30
// lower `<[_]>::len` calls
32
- lower_slice_len_call ( tcx , block, & body . local_decls , slice_len_fn_item_def_id) ;
31
+ lower_slice_len_call ( block, slice_len_fn_item_def_id) ;
33
32
}
34
33
}
35
34
36
- fn lower_slice_len_call < ' tcx > (
37
- tcx : TyCtxt < ' tcx > ,
38
- block : & mut BasicBlockData < ' tcx > ,
39
- local_decls : & IndexSlice < Local , LocalDecl < ' tcx > > ,
40
- slice_len_fn_item_def_id : DefId ,
41
- ) {
35
+ fn lower_slice_len_call < ' tcx > ( block : & mut BasicBlockData < ' tcx > , slice_len_fn_item_def_id : DefId ) {
42
36
let terminator = block. terminator ( ) ;
43
37
if let TerminatorKind :: Call {
44
38
func,
@@ -50,19 +44,17 @@ fn lower_slice_len_call<'tcx>(
50
44
} = & terminator. kind
51
45
// some heuristics for fast rejection
52
46
&& let [ arg] = & args[ ..]
53
- && let Some ( arg) = arg. node . place ( )
54
- && let ty:: FnDef ( fn_def_id, _) = func. ty ( local_decls, tcx) . kind ( )
55
- && * fn_def_id == slice_len_fn_item_def_id
47
+ && let Some ( ( fn_def_id, _) ) = func. const_fn_def ( )
48
+ && fn_def_id == slice_len_fn_item_def_id
56
49
{
57
50
// perform modifications from something like:
58
51
// _5 = core::slice::<impl [u8]>::len(move _6) -> bb1
59
52
// into:
60
- // _5 = Len(* _6)
53
+ // _5 = PtrMetadata(move _6)
61
54
// goto bb1
62
55
63
56
// make new RValue for Len
64
- let deref_arg = tcx. mk_place_deref ( arg) ;
65
- let r_value = Rvalue :: Len ( deref_arg) ;
57
+ let r_value = Rvalue :: UnaryOp ( UnOp :: PtrMetadata , arg. node . clone ( ) ) ;
66
58
let len_statement_kind = StatementKind :: Assign ( Box :: new ( ( * destination, r_value) ) ) ;
67
59
let add_statement =
68
60
Statement { kind : len_statement_kind, source_info : terminator. source_info } ;
0 commit comments