@@ -55,14 +55,39 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
55
55
}
56
56
57
57
let mir = tcx. optimized_mir ( def_id) ;
58
- let mut checker =
59
- CostChecker { tcx, callee_body : mir, calls : 0 , statements : 0 , landing_pads : 0 , resumes : 0 } ;
58
+ let mut checker = CostChecker {
59
+ tcx,
60
+ callee_body : mir,
61
+ calls : 0 ,
62
+ statements : 0 ,
63
+ landing_pads : 0 ,
64
+ resumes : 0 ,
65
+ branches : 0 ,
66
+ asserts : 0 ,
67
+ } ;
60
68
checker. visit_body ( mir) ;
61
- checker. calls == 0
69
+ let is_leaf = checker. calls == 0
62
70
&& checker. resumes == 0
63
71
&& checker. landing_pads == 0
64
72
&& checker. statements
65
- <= tcx. sess . opts . unstable_opts . cross_crate_inline_threshold . unwrap_or ( 100 )
73
+ <= tcx. sess . opts . unstable_opts . cross_crate_inline_threshold . unwrap_or ( 100 ) ;
74
+
75
+ let is_trivial_wrapper = checker. calls == 1
76
+ && checker. resumes == 0
77
+ && checker. landing_pads == 0
78
+ && mir. basic_blocks . len ( ) == 2 ;
79
+
80
+ if is_trivial_wrapper {
81
+ let span = tcx. def_span ( def_id) ;
82
+ if !span. from_expansion ( ) {
83
+ tcx. sess . emit_warning ( crate :: errors:: SuggestAddingInline {
84
+ place : span,
85
+ suggest_inline : span. with_hi ( span. lo ( ) ) ,
86
+ statements : checker. statements ,
87
+ } ) ;
88
+ }
89
+ }
90
+ is_leaf
66
91
}
67
92
68
93
struct CostChecker < ' b , ' tcx > {
@@ -72,6 +97,8 @@ struct CostChecker<'b, 'tcx> {
72
97
statements : usize ,
73
98
landing_pads : usize ,
74
99
resumes : usize ,
100
+ branches : usize ,
101
+ asserts : usize ,
75
102
}
76
103
77
104
impl < ' tcx > Visitor < ' tcx > for CostChecker < ' _ , ' tcx > {
@@ -105,7 +132,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
105
132
}
106
133
}
107
134
TerminatorKind :: Assert { unwind, .. } => {
108
- self . calls += 1 ;
135
+ self . asserts += 1 ;
109
136
if let UnwindAction :: Cleanup ( _) = unwind {
110
137
self . landing_pads += 1 ;
111
138
}
@@ -117,6 +144,10 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
117
144
self . landing_pads += 1 ;
118
145
}
119
146
}
147
+ TerminatorKind :: SwitchInt { .. } => {
148
+ self . statements += 1 ;
149
+ self . branches += 1 ;
150
+ }
120
151
TerminatorKind :: Return => { }
121
152
_ => self . statements += 1 ,
122
153
}
0 commit comments