@@ -62,13 +62,36 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
62
62
} ;
63
63
64
64
let mir = tcx. optimized_mir ( def_id) ;
65
- let mut checker =
66
- CostChecker { tcx, callee_body : mir, calls : 0 , statements : 0 , landing_pads : 0 , resumes : 0 } ;
65
+ let mut checker = CostChecker {
66
+ tcx,
67
+ callee_body : mir,
68
+ calls : 0 ,
69
+ statements : 0 ,
70
+ landing_pads : 0 ,
71
+ resumes : 0 ,
72
+ branches : 0 ,
73
+ asserts : 0 ,
74
+ } ;
67
75
checker. visit_body ( mir) ;
68
- checker. calls == 0
76
+ let is_leaf = checker. calls == 0
69
77
&& checker. resumes == 0
70
78
&& checker. landing_pads == 0
71
- && checker. statements <= threshold
79
+ && checker. statements <= threshold;
80
+
81
+ let is_trivial_wrapper = checker. calls == 1
82
+ && checker. resumes == 0
83
+ && checker. landing_pads == 0
84
+ && mir. basic_blocks . len ( ) == 2 ;
85
+
86
+ if is_trivial_wrapper {
87
+ let span = tcx. def_span ( def_id) ;
88
+ tcx. sess . emit_warning ( crate :: errors:: SuggestAddingInline {
89
+ place : span,
90
+ suggest_inline : span. with_hi ( span. lo ( ) ) ,
91
+ statements : checker. statements ,
92
+ } ) ;
93
+ }
94
+ is_leaf
72
95
}
73
96
74
97
struct CostChecker < ' b , ' tcx > {
@@ -78,6 +101,8 @@ struct CostChecker<'b, 'tcx> {
78
101
statements : usize ,
79
102
landing_pads : usize ,
80
103
resumes : usize ,
104
+ branches : usize ,
105
+ asserts : usize ,
81
106
}
82
107
83
108
impl < ' tcx > Visitor < ' tcx > for CostChecker < ' _ , ' tcx > {
@@ -111,7 +136,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
111
136
}
112
137
}
113
138
TerminatorKind :: Assert { unwind, .. } => {
114
- self . calls += 1 ;
139
+ self . asserts += 1 ;
115
140
if let UnwindAction :: Cleanup ( _) = unwind {
116
141
self . landing_pads += 1 ;
117
142
}
@@ -123,6 +148,10 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
123
148
self . landing_pads += 1 ;
124
149
}
125
150
}
151
+ TerminatorKind :: SwitchInt { .. } => {
152
+ self . statements += 1 ;
153
+ self . branches += 1 ;
154
+ }
126
155
TerminatorKind :: Return => { }
127
156
_ => self . statements += 1 ,
128
157
}
0 commit comments