@@ -146,6 +146,11 @@ impl<'tcx> TyCtxt<'tcx> {
146146 self_ty : Ty < ' tcx > ,
147147 mut f : F ,
148148 ) -> Option < T > {
149+ // FIXME: This depends on the set of all impls for the trait. That is
150+ // unfortunate wrt. incremental compilation.
151+ //
152+ // If we want to be faster, we could have separate queries for
153+ // blanket and non-blanket impls, and compare them separately.
149154 let impls = self . trait_impls_of ( def_id) ;
150155
151156 for & impl_def_id in impls. blanket_impls . iter ( ) {
@@ -154,31 +159,13 @@ impl<'tcx> TyCtxt<'tcx> {
154159 }
155160 }
156161
157- // simplify_type(.., false) basically replaces type parameters and
158- // projections with infer-variables. This is, of course, done on
159- // the impl trait-ref when it is instantiated, but not on the
160- // predicate trait-ref which is passed here.
161- //
162- // for example, if we match `S: Copy` against an impl like
163- // `impl<T:Copy> Copy for Option<T>`, we replace the type variable
164- // in `Option<T>` with an infer variable, to `Option<_>` (this
165- // doesn't actually change fast_reject output), but we don't
166- // replace `S` with anything - this impl of course can't be
167- // selected, and as there are hundreds of similar impls,
168- // considering them would significantly harm performance.
169-
170- // This depends on the set of all impls for the trait. That is
171- // unfortunate. When we get red-green recompilation, we would like
172- // to have a way of knowing whether the set of relevant impls
173- // changed. The most naive
174- // way would be to compute the Vec of relevant impls and see whether
175- // it differs between compilations. That shouldn't be too slow by
176- // itself - we do quite a bit of work for each relevant impl anyway.
177- //
178- // If we want to be faster, we could have separate queries for
179- // blanket and non-blanket impls, and compare them separately.
162+ // Note that we're using `SimplifyParams::Yes` to query `non_blanket_impls` while using
163+ // `SimplifyParams::No` while actually adding them.
180164 //
181- // I think we'll cross that bridge when we get to it.
165+ // This way, when searching for some impl for `T: Trait`, we do not look at any impls
166+ // whose outer level is not a parameter or projection. Especially for things like
167+ // `T: Clone` this is incredibly useful as we would otherwise look at all the impls
168+ // of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
182169 if let Some ( simp) =
183170 fast_reject:: simplify_type ( self , self_ty, SimplifyParams :: Yes , StripReferences :: No )
184171 {
0 commit comments