|
1 | 1 | use crate::ty::context::TyCtxt;
|
| 2 | +use crate::ty::WithOptConstParam; |
2 | 3 | use measureme::{StringComponent, StringId};
|
3 | 4 | use rustc_data_structures::fx::FxHashMap;
|
4 | 5 | use rustc_data_structures::profiling::SelfProfiler;
|
5 |
| -use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; |
| 6 | +use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; |
6 | 7 | use rustc_hir::definitions::DefPathData;
|
7 | 8 | use rustc_query_system::query::QueryCache;
|
8 | 9 | use rustc_query_system::query::QueryState;
|
@@ -154,6 +155,49 @@ impl SpecIntoSelfProfilingString for DefIndex {
|
154 | 155 | }
|
155 | 156 | }
|
156 | 157 |
|
| 158 | +impl SpecIntoSelfProfilingString for LocalDefId { |
| 159 | + fn spec_to_self_profile_string( |
| 160 | + &self, |
| 161 | + builder: &mut QueryKeyStringBuilder<'_, '_, '_>, |
| 162 | + ) -> StringId { |
| 163 | + builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: self.local_def_index }) |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +impl<T: SpecIntoSelfProfilingString> SpecIntoSelfProfilingString for WithOptConstParam<T> { |
| 168 | + fn spec_to_self_profile_string( |
| 169 | + &self, |
| 170 | + builder: &mut QueryKeyStringBuilder<'_, '_, '_>, |
| 171 | + ) -> StringId { |
| 172 | + // We print `WithOptConstParam` values as tuples to make them shorter |
| 173 | + // and more readable, without losing information: |
| 174 | + // |
| 175 | + // "WithOptConstParam { did: foo::bar, const_param_did: Some(foo::baz) }" |
| 176 | + // becomes "(foo::bar, foo::baz)" and |
| 177 | + // "WithOptConstParam { did: foo::bar, const_param_did: None }" |
| 178 | + // becomes "(foo::bar, _)". |
| 179 | + |
| 180 | + let did = StringComponent::Ref(self.did.to_self_profile_string(builder)); |
| 181 | + |
| 182 | + let const_param_did = if let Some(const_param_did) = self.const_param_did { |
| 183 | + let const_param_did = builder.def_id_to_string_id(const_param_did); |
| 184 | + StringComponent::Ref(const_param_did) |
| 185 | + } else { |
| 186 | + StringComponent::Value("_") |
| 187 | + }; |
| 188 | + |
| 189 | + let components = [ |
| 190 | + StringComponent::Value("("), |
| 191 | + did, |
| 192 | + StringComponent::Value(", "), |
| 193 | + const_param_did, |
| 194 | + StringComponent::Value(")"), |
| 195 | + ]; |
| 196 | + |
| 197 | + builder.profiler.alloc_string(&components[..]) |
| 198 | + } |
| 199 | +} |
| 200 | + |
157 | 201 | impl<T0, T1> SpecIntoSelfProfilingString for (T0, T1)
|
158 | 202 | where
|
159 | 203 | T0: SpecIntoSelfProfilingString,
|
|
0 commit comments