@@ -22,7 +22,6 @@ use rustc_middle::ty::{
22
22
} ;
23
23
use rustc_span:: Span ;
24
24
use rustc_target:: abi:: { HasDataLayout , Size , TargetDataLayout } ;
25
- use rustc_trait_selection:: traits;
26
25
27
26
use crate :: const_prop:: CanConstProp ;
28
27
use crate :: const_prop:: ConstPropMachine ;
@@ -35,9 +34,9 @@ use crate::MirLint;
35
34
/// Severely regress performance.
36
35
const MAX_ALLOC_LIMIT : u64 = 1024 ;
37
36
38
- pub struct ConstProp ;
37
+ pub struct ConstPropLint ;
39
38
40
- impl < ' tcx > MirLint < ' tcx > for ConstProp {
39
+ impl < ' tcx > MirLint < ' tcx > for ConstPropLint {
41
40
fn run_lint ( & self , tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) {
42
41
if body. tainted_by_errors . is_some ( ) {
43
42
return ;
@@ -49,61 +48,25 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
49
48
}
50
49
51
50
let def_id = body. source . def_id ( ) . expect_local ( ) ;
52
- let is_fn_like = tcx. def_kind ( def_id) . is_fn_like ( ) ;
53
- let is_assoc_const = tcx. def_kind ( def_id) == DefKind :: AssocConst ;
51
+ let def_kind = tcx. def_kind ( def_id) ;
52
+ let is_fn_like = def_kind. is_fn_like ( ) ;
53
+ let is_assoc_const = def_kind == DefKind :: AssocConst ;
54
54
55
55
// Only run const prop on functions, methods, closures and associated constants
56
56
if !is_fn_like && !is_assoc_const {
57
57
// skip anon_const/statics/consts because they'll be evaluated by miri anyway
58
- trace ! ( "ConstProp skipped for {:?}" , def_id) ;
58
+ trace ! ( "ConstPropLint skipped for {:?}" , def_id) ;
59
59
return ;
60
60
}
61
61
62
- let is_generator = tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) . is_generator ( ) ;
63
62
// FIXME(welseywiser) const prop doesn't work on generators because of query cycles
64
63
// computing their layout.
65
- if is_generator {
66
- trace ! ( "ConstProp skipped for generator {:?}" , def_id) ;
64
+ if let DefKind :: Generator = def_kind {
65
+ trace ! ( "ConstPropLint skipped for generator {:?}" , def_id) ;
67
66
return ;
68
67
}
69
68
70
- // Check if it's even possible to satisfy the 'where' clauses
71
- // for this item.
72
- // This branch will never be taken for any normal function.
73
- // However, it's possible to `#!feature(trivial_bounds)]` to write
74
- // a function with impossible to satisfy clauses, e.g.:
75
- // `fn foo() where String: Copy {}`
76
- //
77
- // We don't usually need to worry about this kind of case,
78
- // since we would get a compilation error if the user tried
79
- // to call it. However, since we can do const propagation
80
- // even without any calls to the function, we need to make
81
- // sure that it even makes sense to try to evaluate the body.
82
- // If there are unsatisfiable where clauses, then all bets are
83
- // off, and we just give up.
84
- //
85
- // We manually filter the predicates, skipping anything that's not
86
- // "global". We are in a potentially generic context
87
- // (e.g. we are evaluating a function without substituting generic
88
- // parameters, so this filtering serves two purposes:
89
- //
90
- // 1. We skip evaluating any predicates that we would
91
- // never be able prove are unsatisfiable (e.g. `<T as Foo>`
92
- // 2. We avoid trying to normalize predicates involving generic
93
- // parameters (e.g. `<T as Foo>::MyItem`). This can confuse
94
- // the normalization code (leading to cycle errors), since
95
- // it's usually never invoked in this way.
96
- let predicates = tcx
97
- . predicates_of ( def_id. to_def_id ( ) )
98
- . predicates
99
- . iter ( )
100
- . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
101
- if traits:: impossible_predicates ( tcx, traits:: elaborate ( tcx, predicates) . collect ( ) ) {
102
- trace ! ( "ConstProp skipped for {:?}: found unsatisfiable predicates" , def_id) ;
103
- return ;
104
- }
105
-
106
- trace ! ( "ConstProp starting for {:?}" , def_id) ;
69
+ trace ! ( "ConstPropLint starting for {:?}" , def_id) ;
107
70
108
71
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
109
72
// constants, instead of just checking for const-folding succeeding.
@@ -112,7 +75,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
112
75
let mut linter = ConstPropagator :: new ( body, tcx) ;
113
76
linter. visit_body ( body) ;
114
77
115
- trace ! ( "ConstProp done for {:?}" , def_id) ;
78
+ trace ! ( "ConstPropLint done for {:?}" , def_id) ;
116
79
}
117
80
}
118
81
0 commit comments