1use std::borrow::Borrow;
2use std::collections::hash_map::Entry;
3use std::fs::File;
4use std::io::{Read, Seek, Write};
5use std::path::{Path, PathBuf};
6use std::sync::Arc;
7
8use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
9use rustc_data_structures::memmap::{Mmap, MmapMut};
10use rustc_data_structures::sync::{par_for_each_in, par_join};
11use rustc_data_structures::temp_dir::MaybeTempDir;
12use rustc_data_structures::thousands::usize_with_underscores;
13use rustc_hir as hir;
14use rustc_hir::attrs::{AttributeKind, EncodeCrossCrate};
15use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalDefIdSet};
16use rustc_hir::definitions::DefPathData;
17use rustc_hir::find_attr;
18use rustc_hir_pretty::id_to_string;
19use rustc_middle::dep_graph::WorkProductId;
20use rustc_middle::middle::dependency_format::Linkage;
21use rustc_middle::mir::interpret;
22use rustc_middle::query::Providers;
23use rustc_middle::traits::specialization_graph;
24use rustc_middle::ty::AssocContainer;
25use rustc_middle::ty::codec::TyEncoder;
26use rustc_middle::ty::fast_reject::{self, TreatParams};
27use rustc_middle::{bug, span_bug};
28use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
29use rustc_session::config::mitigation_coverage::DeniedPartialMitigation;
30use rustc_session::config::{OptLevel, TargetModifier};
31use rustc_span::def_id::CRATE_MOD_ID;
32use rustc_span::hygiene::HygieneEncodeContext;
33use rustc_span::{
34 ByteSymbol, ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId,
35 Symbol, SyntaxContext, sym,
36};
37use rustc_structures::CrateType;
38use tracing::{debug, instrument, trace};
39
40use crate::diagnostics::{FailCreateFileEncoder, FailWriteFile};
41use crate::eii::EiiMapEncodedKeyValue;
42use crate::rmeta::*;
43
44pub(super) struct EncodeContext<'a, 'tcx> {
45 opaque: opaque::FileEncoder<'a>,
46 tcx: TyCtxt<'tcx>,
47 feat: &'tcx rustc_feature::Features,
48 tables: TableBuilders,
49
50 lazy_state: LazyState,
51 span_shorthands: FxHashMap<Span, usize>,
52 type_shorthands: FxHashMap<Ty<'tcx>, usize>,
53 predicate_shorthands: FxHashMap<ty::PredicateKind<'tcx>, usize>,
54
55 interpret_allocs: FxIndexSet<interpret::AllocId>,
56
57 source_file_cache: (Arc<SourceFile>, usize),
61 required_source_files: Option<FxIndexSet<usize>>,
68 is_proc_macro: bool,
69 hygiene_ctxt: &'a HygieneEncodeContext,
70 symbol_index_table: FxHashMap<u32, usize>,
72}
73
74macro_rules! empty_proc_macro {
78 ($self:ident) => {
79 if $self.is_proc_macro {
80 return LazyArray::default();
81 }
82 };
83}
84
85macro_rules! encoder_methods {
86 ($($name:ident($ty:ty);)*) => {
87 $(fn $name(&mut self, value: $ty) {
88 self.opaque.$name(value)
89 })*
90 }
91}
92
93impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
94 fn emit_raw_bytes(&mut self, value: &[u8]) {
self.opaque.emit_raw_bytes(value)
}encoder_methods! {
95 emit_usize(usize);
96 emit_u128(u128);
97 emit_u64(u64);
98 emit_u32(u32);
99 emit_u16(u16);
100 emit_u8(u8);
101
102 emit_isize(isize);
103 emit_i128(i128);
104 emit_i64(i64);
105 emit_i32(i32);
106 emit_i16(i16);
107
108 emit_raw_bytes(&[u8]);
109 }
110}
111
112impl<'a, 'tcx, T> Encodable<EncodeContext<'a, 'tcx>> for LazyValue<T> {
113 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
114 e.emit_lazy_distance(self.position);
115 }
116}
117
118impl<'a, 'tcx, T> Encodable<EncodeContext<'a, 'tcx>> for LazyArray<T> {
119 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
120 e.emit_usize(self.num_elems);
121 if self.num_elems > 0 {
122 e.emit_lazy_distance(self.position)
123 }
124 }
125}
126
127impl<'a, 'tcx, I, T> Encodable<EncodeContext<'a, 'tcx>> for LazyTable<I, T> {
128 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
129 e.emit_usize(self.width);
130 e.emit_usize(self.len);
131 e.emit_lazy_distance(self.position);
132 }
133}
134
135impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for ExpnIndex {
136 fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
137 s.emit_u32(self.as_u32());
138 }
139}
140
141impl<'a, 'tcx> SpanEncoder for EncodeContext<'a, 'tcx> {
142 fn encode_crate_num(&mut self, crate_num: CrateNum) {
143 if crate_num != LOCAL_CRATE && self.is_proc_macro {
144 {
::core::panicking::panic_fmt(format_args!("Attempted to encode non-local CrateNum {0:?} for proc-macro crate",
crate_num));
};panic!("Attempted to encode non-local CrateNum {crate_num:?} for proc-macro crate");
145 }
146 self.emit_u32(crate_num.as_u32());
147 }
148
149 fn encode_def_index(&mut self, def_index: DefIndex) {
150 self.emit_u32(def_index.as_u32());
151 }
152
153 fn encode_def_id(&mut self, def_id: DefId) {
154 def_id.krate.encode(self);
155 def_id.index.encode(self);
156 }
157
158 fn encode_syntax_context(&mut self, syntax_context: SyntaxContext) {
159 rustc_span::hygiene::raw_encode_syntax_context(syntax_context, self.hygiene_ctxt, self);
160 }
161
162 fn encode_expn_id(&mut self, expn_id: ExpnId) {
163 if expn_id.krate == LOCAL_CRATE {
164 self.hygiene_ctxt.schedule_expn_data_for_encoding(expn_id);
169 }
170 expn_id.krate.encode(self);
171 expn_id.local_id.encode(self);
172 }
173
174 fn encode_span(&mut self, span: Span) {
175 match self.span_shorthands.entry(span) {
176 Entry::Occupied(o) => {
177 let last_location = *o.get();
180 let offset = self.opaque.position() - last_location;
183 if offset < last_location {
184 let needed = bytes_needed(offset);
185 SpanTag::indirect(true, needed as u8).encode(self);
186 self.opaque.write_with(|dest| {
187 *dest = offset.to_le_bytes();
188 needed
189 });
190 } else {
191 let needed = bytes_needed(last_location);
192 SpanTag::indirect(false, needed as u8).encode(self);
193 self.opaque.write_with(|dest| {
194 *dest = last_location.to_le_bytes();
195 needed
196 });
197 }
198 }
199 Entry::Vacant(v) => {
200 let position = self.opaque.position();
201 v.insert(position);
202 span.data().encode(self);
204 }
205 }
206 }
207
208 fn encode_symbol(&mut self, sym: Symbol) {
209 self.encode_symbol_or_byte_symbol(sym.as_u32(), |this| this.emit_str(sym.as_str()));
210 }
211
212 fn encode_byte_symbol(&mut self, byte_sym: ByteSymbol) {
213 self.encode_symbol_or_byte_symbol(byte_sym.as_u32(), |this| {
214 this.emit_byte_str(byte_sym.as_byte_str())
215 });
216 }
217}
218
219fn bytes_needed(n: usize) -> usize {
220 (usize::BITS - n.leading_zeros()).div_ceil(u8::BITS) as usize
221}
222
223impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for SpanData {
224 fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) {
225 let ctxt = if s.is_proc_macro { SyntaxContext::root() } else { self.ctxt };
257
258 if self.is_dummy() {
259 let tag = SpanTag::new(SpanKind::Partial, ctxt, 0);
260 tag.encode(s);
261 if tag.context().is_none() {
262 ctxt.encode(s);
263 }
264 return;
265 }
266
267 if true {
if !(self.lo <= self.hi) {
::core::panicking::panic("assertion failed: self.lo <= self.hi")
};
};debug_assert!(self.lo <= self.hi);
269
270 if !s.source_file_cache.0.contains(self.lo) {
271 let source_map = s.tcx.sess.source_map();
272 let source_file_index = source_map.lookup_source_file_idx(self.lo);
273 s.source_file_cache =
274 (Arc::clone(&source_map.files()[source_file_index]), source_file_index);
275 }
276 let (ref source_file, source_file_index) = s.source_file_cache;
277 if true {
if !source_file.contains(self.lo) {
::core::panicking::panic("assertion failed: source_file.contains(self.lo)")
};
};debug_assert!(source_file.contains(self.lo));
278
279 if !source_file.contains(self.hi) {
280 let tag = SpanTag::new(SpanKind::Partial, ctxt, 0);
283 tag.encode(s);
284 if tag.context().is_none() {
285 ctxt.encode(s);
286 }
287 return;
288 }
289
290 let (kind, metadata_index) = if source_file.is_imported() && !s.is_proc_macro {
307 let metadata_index = {
317 match &*source_file.external_src.read() {
319 ExternalSource::Foreign { metadata_index, .. } => *metadata_index,
320 src => {
::core::panicking::panic_fmt(format_args!("Unexpected external source {0:?}",
src));
}panic!("Unexpected external source {src:?}"),
321 }
322 };
323
324 (SpanKind::Foreign, metadata_index)
325 } else {
326 let source_files =
328 s.required_source_files.as_mut().expect("Already encoded SourceMap!");
329 let (metadata_index, _) = source_files.insert_full(source_file_index);
330 let metadata_index: u32 =
331 metadata_index.try_into().expect("cannot export more than U32_MAX files");
332
333 (SpanKind::Local, metadata_index)
334 };
335
336 let lo = self.lo - source_file.start_pos;
339
340 let len = self.hi - self.lo;
343
344 let tag = SpanTag::new(kind, ctxt, len.0 as usize);
345 tag.encode(s);
346 if tag.context().is_none() {
347 ctxt.encode(s);
348 }
349 lo.encode(s);
350 if tag.length().is_none() {
351 len.encode(s);
352 }
353
354 metadata_index.encode(s);
356
357 if kind == SpanKind::Foreign {
358 let cnum = s.source_file_cache.0.cnum;
361 cnum.encode(s);
362 }
363 }
364}
365
366impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
367 fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) {
368 Encoder::emit_usize(e, self.len());
369 e.emit_raw_bytes(self);
370 }
371}
372
373impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
374 const CLEAR_CROSS_CRATE: bool = true;
375
376 fn position(&self) -> usize {
377 self.opaque.position()
378 }
379
380 fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
381 &mut self.type_shorthands
382 }
383
384 fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize> {
385 &mut self.predicate_shorthands
386 }
387
388 fn encode_alloc_id(&mut self, alloc_id: &rustc_middle::mir::interpret::AllocId) {
389 let (index, _) = self.interpret_allocs.insert_full(*alloc_id);
390
391 index.encode(self);
392 }
393}
394
395macro_rules! record {
398 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
399 {
400 let value = $value;
401 let lazy = $self.lazy(value);
402 $self.$tables.$table.set_some($def_id.index, lazy);
403 }
404 }};
405}
406
407macro_rules! record_array {
410 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
411 {
412 let value = $value;
413 let lazy = $self.lazy_array(value);
414 $self.$tables.$table.set_some($def_id.index, lazy);
415 }
416 }};
417}
418
419macro_rules! record_defaulted_array {
420 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
421 {
422 let value = $value;
423 let lazy = $self.lazy_array(value);
424 $self.$tables.$table.set($def_id.index, lazy);
425 }
426 }};
427}
428
429impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
430 fn emit_lazy_distance(&mut self, position: NonZero<usize>) {
431 let pos = position.get();
432 let distance = match self.lazy_state {
433 LazyState::NoNode => ::rustc_middle::util::bug::bug_fmt(format_args!("emit_lazy_distance: outside of a metadata node"))bug!("emit_lazy_distance: outside of a metadata node"),
434 LazyState::NodeStart(start) => {
435 let start = start.get();
436 if !(pos <= start) {
::core::panicking::panic("assertion failed: pos <= start")
};assert!(pos <= start);
437 start - pos
438 }
439 LazyState::Previous(last_pos) => {
440 if !(last_pos <= position) {
{
::core::panicking::panic_fmt(format_args!("make sure that the calls to `lazy*` are in the same order as the metadata fields"));
}
};assert!(
441 last_pos <= position,
442 "make sure that the calls to `lazy*` \
443 are in the same order as the metadata fields",
444 );
445 position.get() - last_pos.get()
446 }
447 };
448 self.lazy_state = LazyState::Previous(NonZero::new(pos).unwrap());
449 self.emit_usize(distance);
450 }
451
452 fn lazy<T: ParameterizedOverTcx, B: Borrow<T::Value<'tcx>>>(&mut self, value: B) -> LazyValue<T>
453 where
454 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
455 {
456 let pos = NonZero::new(self.position()).unwrap();
457
458 {
match (&self.lazy_state, &LazyState::NoNode) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(self.lazy_state, LazyState::NoNode);
459 self.lazy_state = LazyState::NodeStart(pos);
460 value.borrow().encode(self);
461 self.lazy_state = LazyState::NoNode;
462
463 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
464
465 LazyValue::from_position(pos)
466 }
467
468 fn lazy_array<T: ParameterizedOverTcx, I: IntoIterator<Item = B>, B: Borrow<T::Value<'tcx>>>(
469 &mut self,
470 values: I,
471 ) -> LazyArray<T>
472 where
473 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
474 {
475 let pos = NonZero::new(self.position()).unwrap();
476
477 {
match (&self.lazy_state, &LazyState::NoNode) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(self.lazy_state, LazyState::NoNode);
478 self.lazy_state = LazyState::NodeStart(pos);
479 let len = values.into_iter().map(|value| value.borrow().encode(self)).count();
480 self.lazy_state = LazyState::NoNode;
481
482 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
483
484 LazyArray::from_position_and_num_elems(pos, len)
485 }
486
487 fn encode_symbol_or_byte_symbol(
488 &mut self,
489 index: u32,
490 emit_str_or_byte_str: impl Fn(&mut Self),
491 ) {
492 if Symbol::is_predefined(index) {
494 self.opaque.emit_u8(SYMBOL_PREDEFINED);
495 self.opaque.emit_u32(index);
496 } else {
497 match self.symbol_index_table.entry(index) {
499 Entry::Vacant(o) => {
500 self.opaque.emit_u8(SYMBOL_STR);
501 let pos = self.opaque.position();
502 o.insert(pos);
503 emit_str_or_byte_str(self);
504 }
505 Entry::Occupied(o) => {
506 let x = *o.get();
507 self.emit_u8(SYMBOL_OFFSET);
508 self.emit_usize(x);
509 }
510 }
511 }
512 }
513
514 fn encode_def_path_table(&mut self) {
515 let defs = self.tcx.definitions();
516 if self.is_proc_macro {
517 for def_id in std::iter::once(CRATE_DEF_ID)
518 .chain(self.tcx.resolutions(()).proc_macros.iter().copied())
519 {
520 let def_key = self.lazy(defs.def_key(def_id));
521 let def_path_hash = defs.def_path_hash(def_id);
522 self.tables.def_keys.set_some(def_id.local_def_index, def_key);
523 self.tables
524 .def_path_hashes
525 .set(def_id.local_def_index, def_path_hash.local_hash().as_u64());
526 }
527 } else {
528 for (def_index, def_key, def_path_hash) in defs.enumerated_keys_and_path_hashes() {
529 let def_key = self.lazy(def_key);
530 self.tables.def_keys.set_some(def_index, def_key);
531 self.tables.def_path_hashes.set(def_index, def_path_hash.local_hash().as_u64());
532 }
533 }
534 }
535
536 fn encode_def_path_hash_map(&mut self) -> LazyValue<DefPathHashMapRef<'static>> {
537 self.lazy(DefPathHashMapRef::BorrowedFromTcx(self.tcx.def_path_hash_to_def_index_map()))
538 }
539
540 fn encode_source_map(&mut self) -> LazyTable<u32, Option<LazyValue<rustc_span::SourceFile>>> {
541 let source_map = self.tcx.sess.source_map();
542 let all_source_files = source_map.files();
543
544 let required_source_files = self.required_source_files.take().unwrap();
548
549 let mut adapted = TableBuilder::default();
550
551 let local_crate_stable_id = self.tcx.stable_crate_id(LOCAL_CRATE);
552
553 for (on_disk_index, &source_file_index) in required_source_files.iter().enumerate() {
558 let source_file = &all_source_files[source_file_index];
559 if !(!source_file.is_imported() || self.is_proc_macro) {
::core::panicking::panic("assertion failed: !source_file.is_imported() || self.is_proc_macro")
};assert!(!source_file.is_imported() || self.is_proc_macro);
561
562 let mut adapted_source_file = (**source_file).clone();
570
571 match source_file.name {
572 FileName::Real(ref original_file_name) => {
573 let mut adapted_file_name = original_file_name.clone();
574 adapted_file_name.update_for_crate_metadata();
575 adapted_source_file.name = FileName::Real(adapted_file_name);
576 }
577 _ => {
578 }
580 };
581
582 if self.is_proc_macro {
589 adapted_source_file.cnum = LOCAL_CRATE;
590 }
591
592 adapted_source_file.stable_id = StableSourceFileId::from_filename_for_export(
596 &adapted_source_file.name,
597 local_crate_stable_id,
598 );
599
600 let on_disk_index: u32 =
601 on_disk_index.try_into().expect("cannot export more than U32_MAX files");
602 adapted.set_some(on_disk_index, self.lazy(adapted_source_file));
603 }
604
605 adapted.encode(&mut self.opaque)
606 }
607
608 fn encode_crate_root(&mut self) -> LazyValue<CrateRoot> {
609 let tcx = self.tcx;
610 let mut stats: Vec<(&'static str, usize)> = Vec::with_capacity(32);
611
612 macro_rules! stat {
613 ($label:literal, $f:expr) => {{
614 let orig_pos = self.position();
615 let res = $f();
616 stats.push(($label, self.position() - orig_pos));
617 res
618 }};
619 }
620
621 stats.push(("preamble", self.position()));
623
624 let externally_implementable_items = {
let orig_pos = self.position();
let res = (|| self.encode_externally_implementable_items())();
stats.push(("externally-implementable-items",
self.position() - orig_pos));
res
}stat!("externally-implementable-items", || self
625 .encode_externally_implementable_items());
626
627 let (crate_deps, dylib_dependency_formats) =
628 {
let orig_pos = self.position();
let res =
(||
(self.encode_crate_deps(),
self.encode_dylib_dependency_formats()))();
stats.push(("dep", self.position() - orig_pos));
res
}stat!("dep", || (self.encode_crate_deps(), self.encode_dylib_dependency_formats()));
629
630 let lib_features = {
let orig_pos = self.position();
let res = (|| self.encode_lib_features())();
stats.push(("lib-features", self.position() - orig_pos));
res
}stat!("lib-features", || self.encode_lib_features());
631
632 let stability_implications =
633 {
let orig_pos = self.position();
let res = (|| self.encode_stability_implications())();
stats.push(("stability-implications", self.position() - orig_pos));
res
}stat!("stability-implications", || self.encode_stability_implications());
634
635 let (lang_items, lang_items_missing) = {
let orig_pos = self.position();
let res =
(||
{
(self.encode_lang_items(), self.encode_lang_items_missing())
})();
stats.push(("lang-items", self.position() - orig_pos));
res
}stat!("lang-items", || {
636 (self.encode_lang_items(), self.encode_lang_items_missing())
637 });
638
639 let stripped_cfg_items = {
let orig_pos = self.position();
let res = (|| self.encode_stripped_cfg_items())();
stats.push(("stripped-cfg-items", self.position() - orig_pos));
res
}stat!("stripped-cfg-items", || self.encode_stripped_cfg_items());
640
641 let diagnostic_items = {
let orig_pos = self.position();
let res = (|| self.encode_diagnostic_items())();
stats.push(("diagnostic-items", self.position() - orig_pos));
res
}stat!("diagnostic-items", || self.encode_diagnostic_items());
642
643 let canonical_symbols = {
let orig_pos = self.position();
let res = (|| self.encode_canonical_symbols())();
stats.push(("canonical-symbols", self.position() - orig_pos));
res
}stat!("canonical-symbols", || self.encode_canonical_symbols());
644
645 let native_libraries = {
let orig_pos = self.position();
let res = (|| self.encode_native_libraries())();
stats.push(("native-libs", self.position() - orig_pos));
res
}stat!("native-libs", || self.encode_native_libraries());
646
647 let foreign_modules = {
let orig_pos = self.position();
let res = (|| self.encode_foreign_modules())();
stats.push(("foreign-modules", self.position() - orig_pos));
res
}stat!("foreign-modules", || self.encode_foreign_modules());
648
649 _ = {
let orig_pos = self.position();
let res = (|| self.encode_def_path_table())();
stats.push(("def-path-table", self.position() - orig_pos));
res
}stat!("def-path-table", || self.encode_def_path_table());
650
651 let traits = {
let orig_pos = self.position();
let res = (|| self.encode_traits())();
stats.push(("traits", self.position() - orig_pos));
res
}stat!("traits", || self.encode_traits());
653
654 let impls = {
let orig_pos = self.position();
let res = (|| self.encode_impls())();
stats.push(("impls", self.position() - orig_pos));
res
}stat!("impls", || self.encode_impls());
656
657 let incoherent_impls = {
let orig_pos = self.position();
let res = (|| self.encode_incoherent_impls())();
stats.push(("incoherent-impls", self.position() - orig_pos));
res
}stat!("incoherent-impls", || self.encode_incoherent_impls());
658
659 _ = {
let orig_pos = self.position();
let res = (|| self.encode_mir())();
stats.push(("mir", self.position() - orig_pos));
res
}stat!("mir", || self.encode_mir());
660
661 _ = {
let orig_pos = self.position();
let res = (|| self.encode_def_ids())();
stats.push(("def-ids", self.position() - orig_pos));
res
}stat!("def-ids", || self.encode_def_ids());
662
663 let interpret_alloc_index = {
let orig_pos = self.position();
let res =
(||
{
let mut interpret_alloc_index = Vec::new();
let mut n = 0;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:666",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(666u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("beginning to encode alloc ids")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
loop {
let new_n = self.interpret_allocs.len();
if n == new_n { break; }
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:674",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(674u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("encoding {0} further alloc ids",
new_n - n) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for idx in n..new_n {
let id = self.interpret_allocs[idx];
let pos = self.position() as u64;
interpret_alloc_index.push(pos);
interpret::specialized_encode_alloc_id(self, tcx, id);
}
n = new_n;
}
self.lazy_array(interpret_alloc_index)
})();
stats.push(("interpret-alloc-index", self.position() - orig_pos));
res
}stat!("interpret-alloc-index", || {
664 let mut interpret_alloc_index = Vec::new();
665 let mut n = 0;
666 trace!("beginning to encode alloc ids");
667 loop {
668 let new_n = self.interpret_allocs.len();
669 if n == new_n {
671 break;
673 }
674 trace!("encoding {} further alloc ids", new_n - n);
675 for idx in n..new_n {
676 let id = self.interpret_allocs[idx];
677 let pos = self.position() as u64;
678 interpret_alloc_index.push(pos);
679 interpret::specialized_encode_alloc_id(self, tcx, id);
680 }
681 n = new_n;
682 }
683 self.lazy_array(interpret_alloc_index)
684 });
685
686 let proc_macro_data = {
let orig_pos = self.position();
let res = (|| self.encode_proc_macros())();
stats.push(("proc-macro-data", self.position() - orig_pos));
res
}stat!("proc-macro-data", || self.encode_proc_macros());
690
691 let tables = {
let orig_pos = self.position();
let res = (|| self.tables.encode(&mut self.opaque))();
stats.push(("tables", self.position() - orig_pos));
res
}stat!("tables", || self.tables.encode(&mut self.opaque));
692
693 let debugger_visualizers =
694 {
let orig_pos = self.position();
let res = (|| self.encode_debugger_visualizers())();
stats.push(("debugger-visualizers", self.position() - orig_pos));
res
}stat!("debugger-visualizers", || self.encode_debugger_visualizers());
695
696 let exportable_items = {
let orig_pos = self.position();
let res = (|| self.encode_exportable_items())();
stats.push(("exportable-items", self.position() - orig_pos));
res
}stat!("exportable-items", || self.encode_exportable_items());
697
698 let stable_order_of_exportable_impls =
699 {
let orig_pos = self.position();
let res = (|| self.encode_stable_order_of_exportable_impls())();
stats.push(("exportable-items", self.position() - orig_pos));
res
}stat!("exportable-items", || self.encode_stable_order_of_exportable_impls());
700
701 let (exported_non_generic_symbols, exported_generic_symbols) =
703 {
let orig_pos = self.position();
let res =
(||
{
(self.encode_exported_symbols(tcx.exported_non_generic_symbols(LOCAL_CRATE)),
self.encode_exported_symbols(tcx.exported_generic_symbols(LOCAL_CRATE)))
})();
stats.push(("exported-symbols", self.position() - orig_pos));
res
}stat!("exported-symbols", || {
704 (
705 self.encode_exported_symbols(tcx.exported_non_generic_symbols(LOCAL_CRATE)),
706 self.encode_exported_symbols(tcx.exported_generic_symbols(LOCAL_CRATE)),
707 )
708 });
709
710 let (syntax_contexts, expn_data, expn_hashes) = {
let orig_pos = self.position();
let res = (|| self.encode_hygiene())();
stats.push(("hygiene", self.position() - orig_pos));
res
}stat!("hygiene", || self.encode_hygiene());
717
718 let def_path_hash_map = {
let orig_pos = self.position();
let res = (|| self.encode_def_path_hash_map())();
stats.push(("def-path-hash-map", self.position() - orig_pos));
res
}stat!("def-path-hash-map", || self.encode_def_path_hash_map());
719
720 let source_map = {
let orig_pos = self.position();
let res = (|| self.encode_source_map())();
stats.push(("source-map", self.position() - orig_pos));
res
}stat!("source-map", || self.encode_source_map());
723 let target_modifiers = {
let orig_pos = self.position();
let res = (|| self.encode_target_modifiers())();
stats.push(("target-modifiers", self.position() - orig_pos));
res
}stat!("target-modifiers", || self.encode_target_modifiers());
724 let denied_partial_mitigations = {
let orig_pos = self.position();
let res = (|| self.encode_enabled_denied_partial_mitigations())();
stats.push(("denied-partial-mitigations", self.position() - orig_pos));
res
}stat!("denied-partial-mitigations", || self
725 .encode_enabled_denied_partial_mitigations());
726
727 let root = {
let orig_pos = self.position();
let res =
(||
{
let attrs = tcx.hir_krate_attrs();
self.lazy(CrateRoot {
header: CrateHeader {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
hash: tcx.crate_hash(LOCAL_CRATE),
is_proc_macro_crate: proc_macro_data.is_some(),
is_stub: false,
},
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
edition: tcx.sess.edition(),
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
has_default_lib_allocator: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(DefaultLibAllocator) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
externally_implementable_items,
proc_macro_data,
debugger_visualizers,
compiler_builtins: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(CompilerBuiltins) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
needs_allocator: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(NeedsAllocator) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
needs_panic_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(NeedsPanicRuntime) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
no_builtins: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(NoBuiltins) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
panic_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(PanicRuntime) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
profiler_runtime: {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(ProfilerRuntime) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
},
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
crate_deps,
dylib_dependency_formats,
lib_features,
stability_implications,
lang_items,
diagnostic_items,
canonical_symbols,
lang_items_missing,
stripped_cfg_items,
native_libraries,
foreign_modules,
source_map,
target_modifiers,
denied_partial_mitigations,
traits,
impls,
incoherent_impls,
exportable_items,
stable_order_of_exportable_impls,
exported_non_generic_symbols,
exported_generic_symbols,
interpret_alloc_index,
tables,
syntax_contexts,
expn_data,
expn_hashes,
def_path_hash_map,
specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
})
})();
stats.push(("final", self.position() - orig_pos));
res
}stat!("final", || {
728 let attrs = tcx.hir_krate_attrs();
729 self.lazy(CrateRoot {
730 header: CrateHeader {
731 name: tcx.crate_name(LOCAL_CRATE),
732 triple: tcx.sess.opts.target_triple.clone(),
733 hash: tcx.crate_hash(LOCAL_CRATE),
734 is_proc_macro_crate: proc_macro_data.is_some(),
735 is_stub: false,
736 },
737 extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
738 stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
739 required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
740 panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
741 edition: tcx.sess.edition(),
742 has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
743 has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
744 has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
745 has_default_lib_allocator: find_attr!(attrs, DefaultLibAllocator),
746 externally_implementable_items,
747 proc_macro_data,
748 debugger_visualizers,
749 compiler_builtins: find_attr!(attrs, CompilerBuiltins),
750 needs_allocator: find_attr!(attrs, NeedsAllocator),
751 needs_panic_runtime: find_attr!(attrs, NeedsPanicRuntime),
752 no_builtins: find_attr!(attrs, NoBuiltins),
753 panic_runtime: find_attr!(attrs, PanicRuntime),
754 profiler_runtime: find_attr!(attrs, ProfilerRuntime),
755 symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
756
757 crate_deps,
758 dylib_dependency_formats,
759 lib_features,
760 stability_implications,
761 lang_items,
762 diagnostic_items,
763 canonical_symbols,
764 lang_items_missing,
765 stripped_cfg_items,
766 native_libraries,
767 foreign_modules,
768 source_map,
769 target_modifiers,
770 denied_partial_mitigations,
771 traits,
772 impls,
773 incoherent_impls,
774 exportable_items,
775 stable_order_of_exportable_impls,
776 exported_non_generic_symbols,
777 exported_generic_symbols,
778 interpret_alloc_index,
779 tables,
780 syntax_contexts,
781 expn_data,
782 expn_hashes,
783 def_path_hash_map,
784 specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
785 })
786 });
787
788 let total_bytes = self.position();
789
790 let computed_total_bytes: usize = stats.iter().map(|(_, size)| size).sum();
791 {
match (&total_bytes, &computed_total_bytes) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(total_bytes, computed_total_bytes);
792
793 if tcx.sess.opts.unstable_opts.meta_stats {
794 use std::fmt::Write;
795
796 self.opaque.flush();
797
798 let pos_before_rewind = self.opaque.file().stream_position().unwrap();
800 let mut zero_bytes = 0;
801 self.opaque.file().rewind().unwrap();
802 let file = std::io::BufReader::new(self.opaque.file());
803 for e in file.bytes() {
804 if e.unwrap() == 0 {
805 zero_bytes += 1;
806 }
807 }
808 {
match (&self.opaque.file().stream_position().unwrap(), &pos_before_rewind)
{
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(self.opaque.file().stream_position().unwrap(), pos_before_rewind);
809
810 stats.sort_by_key(|&(_, usize)| usize);
811 stats.reverse(); let prefix = "meta-stats";
814 let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
815
816 let section_w = 23;
817 let size_w = 10;
818 let banner_w = 64;
819
820 let mut s = String::new();
826 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
827 _ = s.write_fmt(format_args!("{1} METADATA STATS: {0}\n",
tcx.crate_name(LOCAL_CRATE), prefix))writeln!(s, "{prefix} METADATA STATS: {}", tcx.crate_name(LOCAL_CRATE));
828 _ = s.write_fmt(format_args!("{2} {0:<3$}{1:>4$}\n", "Section", "Size", prefix,
section_w, size_w))writeln!(s, "{prefix} {:<section_w$}{:>size_w$}", "Section", "Size");
829 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
830 for (label, size) in stats {
831 _ = s.write_fmt(format_args!("{3} {0:<4$}{1:>5$} ({2:4.1}%)\n", label,
usize_with_underscores(size), perc(size), prefix, section_w, size_w))writeln!(
832 s,
833 "{prefix} {:<section_w$}{:>size_w$} ({:4.1}%)",
834 label,
835 usize_with_underscores(size),
836 perc(size)
837 );
838 }
839 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
840 _ = s.write_fmt(format_args!("{3} {0:<4$}{1:>5$} (of which {2:.1}% are zero bytes)\n",
"Total", usize_with_underscores(total_bytes), perc(zero_bytes),
prefix, section_w, size_w))writeln!(
841 s,
842 "{prefix} {:<section_w$}{:>size_w$} (of which {:.1}% are zero bytes)",
843 "Total",
844 usize_with_underscores(total_bytes),
845 perc(zero_bytes)
846 );
847 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
848 { ::std::io::_eprint(format_args!("{0}", s)); };eprint!("{s}");
849 }
850
851 root
852 }
853}
854
855struct AnalyzeAttrState {
856 is_exported: bool,
857 is_doc_hidden: bool,
858}
859
860#[inline]
870fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState) -> bool {
871 let mut should_encode = false;
872 if let hir::Attribute::Parsed(p) = attr
873 && p.encode_cross_crate() == EncodeCrossCrate::No
874 {
875 } else if let Some(name) = attr.name()
877 && [sym::warn, sym::allow, sym::expect, sym::forbid, sym::deny].contains(&name)
878 {
879 } else if let hir::Attribute::Parsed(AttributeKind::DocComment { .. }) = attr {
882 if state.is_exported {
886 should_encode = true;
887 }
888 } else if let hir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
889 should_encode = true;
890 if d.hidden.is_some() {
891 state.is_doc_hidden = true;
892 }
893 } else {
894 should_encode = true;
895 }
896 should_encode
897}
898
899fn should_encode_span(def_kind: DefKind) -> bool {
900 match def_kind {
901 DefKind::Mod
902 | DefKind::Struct
903 | DefKind::Union
904 | DefKind::Enum
905 | DefKind::Variant
906 | DefKind::Trait
907 | DefKind::TyAlias
908 | DefKind::ForeignTy
909 | DefKind::TraitAlias
910 | DefKind::AssocTy
911 | DefKind::TyParam
912 | DefKind::ConstParam
913 | DefKind::LifetimeParam
914 | DefKind::Fn
915 | DefKind::Const { .. }
916 | DefKind::Static { .. }
917 | DefKind::Ctor(..)
918 | DefKind::AssocFn
919 | DefKind::AssocConst { .. }
920 | DefKind::Macro(_)
921 | DefKind::ExternCrate
922 | DefKind::Use
923 | DefKind::AnonConst
924 | DefKind::OpaqueTy
925 | DefKind::Field
926 | DefKind::Impl { .. }
927 | DefKind::Closure
928 | DefKind::SyntheticCoroutineBody => true,
929 DefKind::ForeignMod | DefKind::GlobalAsm => false,
930 }
931}
932
933fn should_encode_attrs(def_kind: DefKind) -> bool {
934 match def_kind {
935 DefKind::Mod
936 | DefKind::Struct
937 | DefKind::Union
938 | DefKind::Enum
939 | DefKind::Variant
940 | DefKind::Trait
941 | DefKind::TyAlias
942 | DefKind::ForeignTy
943 | DefKind::TraitAlias
944 | DefKind::AssocTy
945 | DefKind::Fn
946 | DefKind::Const { .. }
947 | DefKind::Static { nested: false, .. }
948 | DefKind::AssocFn
949 | DefKind::AssocConst { .. }
950 | DefKind::Macro(_)
951 | DefKind::Field
952 | DefKind::ConstParam
953 | DefKind::Impl { .. } => true,
954 DefKind::Use => true,
958 DefKind::Closure => true,
963 DefKind::SyntheticCoroutineBody => false,
964 DefKind::TyParam
965 | DefKind::Ctor(..)
966 | DefKind::ExternCrate
967 | DefKind::ForeignMod
968 | DefKind::AnonConst
969 | DefKind::OpaqueTy
970 | DefKind::LifetimeParam
971 | DefKind::Static { nested: true, .. }
972 | DefKind::GlobalAsm => false,
973 }
974}
975
976fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
977 match def_kind {
978 DefKind::Mod
979 | DefKind::Struct
980 | DefKind::Union
981 | DefKind::Enum
982 | DefKind::Variant
983 | DefKind::Trait
984 | DefKind::Impl { .. } => true,
985 DefKind::TyAlias
986 | DefKind::ForeignTy
987 | DefKind::TraitAlias
988 | DefKind::AssocTy
989 | DefKind::TyParam
990 | DefKind::Fn
991 | DefKind::Const { .. }
992 | DefKind::ConstParam
993 | DefKind::Static { .. }
994 | DefKind::Ctor(..)
995 | DefKind::AssocFn
996 | DefKind::AssocConst { .. }
997 | DefKind::Macro(_)
998 | DefKind::ExternCrate
999 | DefKind::Use
1000 | DefKind::ForeignMod
1001 | DefKind::AnonConst
1002 | DefKind::OpaqueTy
1003 | DefKind::Field
1004 | DefKind::LifetimeParam
1005 | DefKind::GlobalAsm
1006 | DefKind::Closure
1007 | DefKind::SyntheticCoroutineBody => false,
1008 }
1009}
1010
1011fn should_encode_visibility(def_kind: DefKind) -> bool {
1012 match def_kind {
1013 DefKind::Mod
1014 | DefKind::Struct
1015 | DefKind::Union
1016 | DefKind::Enum
1017 | DefKind::Variant
1018 | DefKind::Trait
1019 | DefKind::TyAlias
1020 | DefKind::ForeignTy
1021 | DefKind::TraitAlias
1022 | DefKind::AssocTy
1023 | DefKind::Fn
1024 | DefKind::Const { .. }
1025 | DefKind::Static { nested: false, .. }
1026 | DefKind::Ctor(..)
1027 | DefKind::AssocFn
1028 | DefKind::AssocConst { .. }
1029 | DefKind::Macro(..)
1030 | DefKind::Field => true,
1031 DefKind::Use
1032 | DefKind::ForeignMod
1033 | DefKind::TyParam
1034 | DefKind::ConstParam
1035 | DefKind::LifetimeParam
1036 | DefKind::AnonConst
1037 | DefKind::Static { nested: true, .. }
1038 | DefKind::OpaqueTy
1039 | DefKind::GlobalAsm
1040 | DefKind::Impl { .. }
1041 | DefKind::Closure
1042 | DefKind::ExternCrate
1043 | DefKind::SyntheticCoroutineBody => false,
1044 }
1045}
1046
1047fn should_encode_stability(def_kind: DefKind) -> bool {
1048 match def_kind {
1049 DefKind::Mod
1050 | DefKind::Ctor(..)
1051 | DefKind::Variant
1052 | DefKind::Field
1053 | DefKind::Struct
1054 | DefKind::AssocTy
1055 | DefKind::AssocFn
1056 | DefKind::AssocConst { .. }
1057 | DefKind::TyParam
1058 | DefKind::ConstParam
1059 | DefKind::Static { .. }
1060 | DefKind::Const { .. }
1061 | DefKind::Fn
1062 | DefKind::ForeignMod
1063 | DefKind::TyAlias
1064 | DefKind::OpaqueTy
1065 | DefKind::Enum
1066 | DefKind::Union
1067 | DefKind::Impl { .. }
1068 | DefKind::Trait
1069 | DefKind::TraitAlias
1070 | DefKind::Macro(..)
1071 | DefKind::ForeignTy => true,
1072 DefKind::Use
1073 | DefKind::LifetimeParam
1074 | DefKind::AnonConst
1075 | DefKind::GlobalAsm
1076 | DefKind::Closure
1077 | DefKind::ExternCrate
1078 | DefKind::SyntheticCoroutineBody => false,
1079 }
1080}
1081
1082fn should_encode_mir(
1103 tcx: TyCtxt<'_>,
1104 reachable_set: &LocalDefIdSet,
1105 def_id: LocalDefId,
1106) -> (bool, bool) {
1107 match tcx.def_kind(def_id) {
1108 DefKind::Ctor(_, _) => (true, false),
1110 DefKind::AnonConst | DefKind::AssocConst { .. } | DefKind::Const { .. } => (true, false),
1112 DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
1114 DefKind::SyntheticCoroutineBody => (false, true),
1115 DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
1117 let opt = tcx.sess.opts.unstable_opts.always_encode_mir
1118 || (tcx.sess.opts.output_types.should_codegen()
1119 && reachable_set.contains(&def_id)
1120 && (tcx.generics_of(def_id).requires_monomorphization(tcx)
1121 || tcx.cross_crate_inlinable(def_id)));
1122 let opt =
1124 opt && !#[allow(non_exhaustive_omitted_patterns)] match tcx.constness(def_id) {
hir::Constness::Const { always: true } => true,
_ => false,
}matches!(tcx.constness(def_id), hir::Constness::Const { always: true });
1125 let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
1127 (is_const_fn, opt)
1128 }
1129 _ => (false, false),
1131 }
1132}
1133
1134fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
1135 match def_kind {
1136 DefKind::Struct
1137 | DefKind::Union
1138 | DefKind::Enum
1139 | DefKind::OpaqueTy
1140 | DefKind::Fn
1141 | DefKind::Ctor(..)
1142 | DefKind::AssocFn => true,
1143 DefKind::AssocTy => {
1144 #[allow(non_exhaustive_omitted_patterns)] match tcx.opt_rpitit_info(def_id) {
Some(ty::ImplTraitInTraitData::Trait { .. }) => true,
_ => false,
}matches!(tcx.opt_rpitit_info(def_id), Some(ty::ImplTraitInTraitData::Trait { .. }))
1146 }
1147 DefKind::Mod
1148 | DefKind::Variant
1149 | DefKind::Field
1150 | DefKind::AssocConst { .. }
1151 | DefKind::TyParam
1152 | DefKind::ConstParam
1153 | DefKind::Static { .. }
1154 | DefKind::Const { .. }
1155 | DefKind::ForeignMod
1156 | DefKind::TyAlias
1157 | DefKind::Impl { .. }
1158 | DefKind::Trait
1159 | DefKind::TraitAlias
1160 | DefKind::Macro(..)
1161 | DefKind::ForeignTy
1162 | DefKind::Use
1163 | DefKind::LifetimeParam
1164 | DefKind::AnonConst
1165 | DefKind::GlobalAsm
1166 | DefKind::Closure
1167 | DefKind::ExternCrate
1168 | DefKind::SyntheticCoroutineBody => false,
1169 }
1170}
1171
1172fn should_encode_generics(def_kind: DefKind) -> bool {
1173 match def_kind {
1174 DefKind::Struct
1175 | DefKind::Union
1176 | DefKind::Enum
1177 | DefKind::Variant
1178 | DefKind::Trait
1179 | DefKind::TyAlias
1180 | DefKind::ForeignTy
1181 | DefKind::TraitAlias
1182 | DefKind::AssocTy
1183 | DefKind::Fn
1184 | DefKind::Const { .. }
1185 | DefKind::Static { .. }
1186 | DefKind::Ctor(..)
1187 | DefKind::AssocFn
1188 | DefKind::AssocConst { .. }
1189 | DefKind::AnonConst
1190 | DefKind::OpaqueTy
1191 | DefKind::Impl { .. }
1192 | DefKind::Field
1193 | DefKind::TyParam
1194 | DefKind::Closure
1195 | DefKind::SyntheticCoroutineBody => true,
1196 DefKind::Mod
1197 | DefKind::ForeignMod
1198 | DefKind::ConstParam
1199 | DefKind::Macro(..)
1200 | DefKind::Use
1201 | DefKind::LifetimeParam
1202 | DefKind::GlobalAsm
1203 | DefKind::ExternCrate => false,
1204 }
1205}
1206
1207fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> bool {
1208 match def_kind {
1209 DefKind::Struct
1210 | DefKind::Union
1211 | DefKind::Enum
1212 | DefKind::Variant
1213 | DefKind::Ctor(..)
1214 | DefKind::Field
1215 | DefKind::Fn
1216 | DefKind::Const { .. }
1217 | DefKind::Static { nested: false, .. }
1218 | DefKind::TyAlias
1219 | DefKind::ForeignTy
1220 | DefKind::Impl { .. }
1221 | DefKind::AssocFn
1222 | DefKind::AssocConst { .. }
1223 | DefKind::Closure
1224 | DefKind::ConstParam
1225 | DefKind::AnonConst
1226 | DefKind::SyntheticCoroutineBody => true,
1227
1228 DefKind::OpaqueTy => {
1229 let origin = tcx.local_opaque_ty_origin(def_id);
1230 if let hir::OpaqueTyOrigin::FnReturn { parent, .. }
1231 | hir::OpaqueTyOrigin::AsyncFn { parent, .. } = origin
1232 && let hir::Node::TraitItem(trait_item) = tcx.hir_node_by_def_id(parent)
1233 && let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
1234 {
1235 false
1236 } else {
1237 true
1238 }
1239 }
1240
1241 DefKind::AssocTy => {
1242 let assoc_item = tcx.associated_item(def_id);
1243 match assoc_item.container {
1244 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => true,
1245 ty::AssocContainer::Trait => assoc_item.defaultness(tcx).has_value(),
1246 }
1247 }
1248 DefKind::TyParam => {
1249 let hir::Node::GenericParam(param) = tcx.hir_node_by_def_id(def_id) else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
1250 let hir::GenericParamKind::Type { default, .. } = param.kind else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
1251 default.is_some()
1252 }
1253
1254 DefKind::Trait
1255 | DefKind::TraitAlias
1256 | DefKind::Mod
1257 | DefKind::ForeignMod
1258 | DefKind::Macro(..)
1259 | DefKind::Static { nested: true, .. }
1260 | DefKind::Use
1261 | DefKind::LifetimeParam
1262 | DefKind::GlobalAsm
1263 | DefKind::ExternCrate => false,
1264 }
1265}
1266
1267fn should_encode_fn_sig(def_kind: DefKind) -> bool {
1268 match def_kind {
1269 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) => true,
1270
1271 DefKind::Struct
1272 | DefKind::Union
1273 | DefKind::Enum
1274 | DefKind::Variant
1275 | DefKind::Field
1276 | DefKind::Const { .. }
1277 | DefKind::Static { .. }
1278 | DefKind::Ctor(..)
1279 | DefKind::TyAlias
1280 | DefKind::OpaqueTy
1281 | DefKind::ForeignTy
1282 | DefKind::Impl { .. }
1283 | DefKind::AssocConst { .. }
1284 | DefKind::Closure
1285 | DefKind::ConstParam
1286 | DefKind::AnonConst
1287 | DefKind::AssocTy
1288 | DefKind::TyParam
1289 | DefKind::Trait
1290 | DefKind::TraitAlias
1291 | DefKind::Mod
1292 | DefKind::ForeignMod
1293 | DefKind::Macro(..)
1294 | DefKind::Use
1295 | DefKind::LifetimeParam
1296 | DefKind::GlobalAsm
1297 | DefKind::ExternCrate
1298 | DefKind::SyntheticCoroutineBody => false,
1299 }
1300}
1301
1302fn should_encode_constness(def_kind: DefKind) -> bool {
1303 match def_kind {
1304 DefKind::Fn
1305 | DefKind::AssocFn
1306 | DefKind::Closure
1307 | DefKind::Ctor(_, CtorKind::Fn)
1308 | DefKind::Impl { of_trait: false } => true,
1309
1310 DefKind::Struct
1311 | DefKind::Union
1312 | DefKind::Enum
1313 | DefKind::Field
1314 | DefKind::Const { .. }
1315 | DefKind::AssocConst { .. }
1316 | DefKind::AnonConst
1317 | DefKind::Static { .. }
1318 | DefKind::TyAlias
1319 | DefKind::OpaqueTy
1320 | DefKind::Impl { .. }
1321 | DefKind::ForeignTy
1322 | DefKind::ConstParam
1323 | DefKind::AssocTy
1324 | DefKind::TyParam
1325 | DefKind::Trait
1326 | DefKind::TraitAlias
1327 | DefKind::Mod
1328 | DefKind::ForeignMod
1329 | DefKind::Macro(..)
1330 | DefKind::Use
1331 | DefKind::LifetimeParam
1332 | DefKind::GlobalAsm
1333 | DefKind::ExternCrate
1334 | DefKind::Ctor(_, CtorKind::Const)
1335 | DefKind::Variant
1336 | DefKind::SyntheticCoroutineBody => false,
1337 }
1338}
1339
1340fn should_encode_const(def_kind: DefKind) -> bool {
1341 match def_kind {
1342 DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => true,
1344
1345 DefKind::Struct
1346 | DefKind::Union
1347 | DefKind::Enum
1348 | DefKind::Variant
1349 | DefKind::Ctor(..)
1350 | DefKind::Field
1351 | DefKind::Fn
1352 | DefKind::Static { .. }
1353 | DefKind::TyAlias
1354 | DefKind::OpaqueTy
1355 | DefKind::ForeignTy
1356 | DefKind::Impl { .. }
1357 | DefKind::AssocFn
1358 | DefKind::Closure
1359 | DefKind::ConstParam
1360 | DefKind::AssocTy
1361 | DefKind::TyParam
1362 | DefKind::Trait
1363 | DefKind::TraitAlias
1364 | DefKind::Mod
1365 | DefKind::ForeignMod
1366 | DefKind::Macro(..)
1367 | DefKind::Use
1368 | DefKind::LifetimeParam
1369 | DefKind::GlobalAsm
1370 | DefKind::ExternCrate
1371 | DefKind::SyntheticCoroutineBody => false,
1372 }
1373}
1374
1375fn should_encode_const_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
1376 tcx.is_type_const(def_id)
1378 && (!#[allow(non_exhaustive_omitted_patterns)] match def_kind {
DefKind::AssocConst { .. } => true,
_ => false,
}matches!(def_kind, DefKind::AssocConst { .. }) || assoc_item_has_value(tcx, def_id))
1379}
1380
1381fn assoc_item_has_value<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1382 let assoc_item = tcx.associated_item(def_id);
1383 match assoc_item.container {
1384 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => true,
1385 ty::AssocContainer::Trait => assoc_item.defaultness(tcx).has_value(),
1386 }
1387}
1388
1389impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1390 fn encode_attrs(&mut self, def_id: LocalDefId) {
1391 let tcx = self.tcx;
1392 let mut state = AnalyzeAttrState {
1393 is_exported: tcx.effective_visibilities(()).is_exported(def_id),
1394 is_doc_hidden: false,
1395 };
1396 let attr_iter = tcx
1397 .hir_attrs(tcx.local_def_id_to_hir_id(def_id))
1398 .iter()
1399 .filter(|attr| analyze_attr(*attr, &mut state));
1400
1401 {
{
let value = attr_iter;
let lazy = self.lazy_array(value);
self.tables.attributes.set_some(def_id.to_def_id().index, lazy);
}
};record_array!(self.tables.attributes[def_id.to_def_id()] <- attr_iter);
1402
1403 let mut attr_flags = AttrFlags::empty();
1404 if state.is_doc_hidden {
1405 attr_flags |= AttrFlags::IS_DOC_HIDDEN;
1406 }
1407 self.tables.attr_flags.set(def_id.local_def_index, attr_flags);
1408 }
1409
1410 fn encode_def_ids(&mut self) {
1411 self.encode_info_for_mod(CRATE_DEF_ID);
1412
1413 if self.is_proc_macro {
1416 return;
1417 }
1418
1419 let tcx = self.tcx;
1420
1421 for local_id in tcx.iter_local_def_id() {
1422 let def_id = local_id.to_def_id();
1423 let def_kind = tcx.def_kind(local_id);
1424 self.tables.def_kind.set_some(def_id.index, def_kind);
1425
1426 if def_kind == DefKind::AnonConst
1432 && #[allow(non_exhaustive_omitted_patterns)] match tcx.hir_node_by_def_id(local_id)
{
hir::Node::ConstArg(_) |
hir::Node::Infer(hir::InferArg { kind: hir::InferArgKind::Const, .. })
=> true,
_ => false,
}matches!(
1433 tcx.hir_node_by_def_id(local_id),
1434 hir::Node::ConstArg(_)
1435 | hir::Node::Infer(hir::InferArg { kind: hir::InferArgKind::Const, .. })
1436 )
1437 {
1438 continue;
1439 }
1440
1441 if def_kind == DefKind::Field
1442 && let hir::Node::Field(field) = tcx.hir_node_by_def_id(local_id)
1443 && let Some(anon) = field.default
1444 {
1445 {
{
let value = anon.def_id.to_def_id();
let lazy = self.lazy(value);
self.tables.default_fields.set_some(def_id.index, lazy);
}
};record!(self.tables.default_fields[def_id] <- anon.def_id.to_def_id());
1446 }
1447
1448 if should_encode_span(def_kind) {
1449 let def_span = tcx.def_span(local_id);
1450 {
{
let value = def_span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_span[def_id] <- def_span);
1451 }
1452 if should_encode_attrs(def_kind) {
1453 self.encode_attrs(local_id);
1454 }
1455 if should_encode_expn_that_defined(def_kind) {
1456 {
{
let value = self.tcx.expn_that_defined(def_id);
let lazy = self.lazy(value);
self.tables.expn_that_defined.set_some(def_id.index, lazy);
}
};record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
1457 }
1458 if should_encode_span(def_kind)
1459 && let Some(ident_span) = tcx.def_ident_span(def_id)
1460 {
1461 {
{
let value = ident_span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_ident_span[def_id] <- ident_span);
1462 }
1463 if def_kind.has_codegen_attrs() {
1464 {
{
let value = self.tcx.codegen_fn_attrs(def_id);
let lazy = self.lazy(value);
self.tables.codegen_fn_attrs.set_some(def_id.index, lazy);
}
};record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
1465 }
1466 if should_encode_visibility(def_kind) {
1467 let vis = self
1468 .tcx
1469 .local_visibility(local_id)
1470 .map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
1471 {
{
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
}
};record!(self.tables.visibility[def_id] <- vis);
1472 }
1473 if should_encode_stability(def_kind) {
1474 self.encode_stability(def_id);
1475 self.encode_const_stability(def_id);
1476 self.encode_default_body_stability(def_id);
1477 self.encode_deprecation(def_id);
1478 }
1479 if should_encode_variances(tcx, def_id, def_kind) {
1480 let v = self.tcx.variances_of(def_id);
1481 {
{
let value = v;
let lazy = self.lazy_array(value);
self.tables.variances_of.set_some(def_id.index, lazy);
}
};record_array!(self.tables.variances_of[def_id] <- v);
1482 }
1483 if should_encode_fn_sig(def_kind) {
1484 {
{
let value = tcx.fn_sig(def_id);
let lazy = self.lazy(value);
self.tables.fn_sig.set_some(def_id.index, lazy);
}
};record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
1485 }
1486 if should_encode_generics(def_kind) {
1487 let g = tcx.generics_of(def_id);
1488 {
{
let value = g;
let lazy = self.lazy(value);
self.tables.generics_of.set_some(def_id.index, lazy);
}
};record!(self.tables.generics_of[def_id] <- g);
1489 {
{
let value = self.tcx.explicit_clauses_of(def_id);
let lazy = self.lazy(value);
self.tables.explicit_clauses_of.set_some(def_id.index, lazy);
}
};record!(self.tables.explicit_clauses_of[def_id] <- self.tcx.explicit_clauses_of(def_id));
1490 let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
1491 {
{
let value = inferred_outlives;
let lazy = self.lazy_array(value);
self.tables.inferred_outlives_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives);
1492
1493 for param in &g.own_params {
1494 if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
1495 let default = self.tcx.const_param_default(param.def_id);
1496 {
{
let value = default;
let lazy = self.lazy(value);
self.tables.const_param_default.set_some(param.def_id.index, lazy);
}
};record!(self.tables.const_param_default[param.def_id] <- default);
1497 }
1498 }
1499 }
1500 if tcx.is_conditionally_const(def_id) {
1501 {
{
let value = self.tcx.const_conditions(def_id);
let lazy = self.lazy(value);
self.tables.const_conditions.set_some(def_id.index, lazy);
}
};record!(self.tables.const_conditions[def_id] <- self.tcx.const_conditions(def_id));
1502 }
1503 if should_encode_type(tcx, local_id, def_kind) {
1504 {
{
let value = self.tcx.type_of(def_id);
let lazy = self.lazy(value);
self.tables.type_of.set_some(def_id.index, lazy);
}
};record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
1505 }
1506 if should_encode_constness(def_kind) {
1507 let constness = self.tcx.constness(def_id);
1508 self.tables.constness.set(def_id.index, constness);
1509 }
1510 if let DefKind::Fn | DefKind::AssocFn = def_kind {
1511 let asyncness = tcx.asyncness(def_id);
1512 self.tables.asyncness.set(def_id.index, asyncness);
1513 {
{
let value = tcx.fn_arg_idents(def_id);
let lazy = self.lazy_array(value);
self.tables.fn_arg_idents.set_some(def_id.index, lazy);
}
};record_array!(self.tables.fn_arg_idents[def_id] <- tcx.fn_arg_idents(def_id));
1514 }
1515 if let Some(name) = tcx.intrinsic(def_id) {
1516 {
{
let value = name;
let lazy = self.lazy(value);
self.tables.intrinsic.set_some(def_id.index, lazy);
}
};record!(self.tables.intrinsic[def_id] <- name);
1517 }
1518 if let DefKind::TyParam | DefKind::Trait = def_kind {
1519 let default = self.tcx.object_lifetime_default(def_id);
1520 {
{
let value = default;
let lazy = self.lazy(value);
self.tables.object_lifetime_default.set_some(def_id.index, lazy);
}
};record!(self.tables.object_lifetime_default[def_id] <- default);
1521 }
1522 if let DefKind::Trait = def_kind {
1523 {
{
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
}
};record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1524 {
{
let value = self.tcx.explicit_super_clauses_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_super_clauses_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_super_clauses_of[def_id] <-
1525 self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1526 {
{
let value =
self.tcx.explicit_implied_clauses_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_clauses_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_clauses_of[def_id] <-
1527 self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1528 let module_children = self.tcx.module_children_local(local_id);
1529 {
{
let value =
module_children.iter().map(|child| child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.module_children_non_reexports[def_id] <-
1530 module_children.iter().map(|child| child.res.def_id().index));
1531 if self.tcx.is_const_trait(def_id) {
1532 {
{
let value =
self.tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1533 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1534 }
1535 }
1536 if let DefKind::TraitAlias = def_kind {
1537 {
{
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
}
};record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1538 {
{
let value = self.tcx.explicit_super_clauses_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_super_clauses_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_super_clauses_of[def_id] <-
1539 self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1540 {
{
let value =
self.tcx.explicit_implied_clauses_of(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_clauses_of.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_clauses_of[def_id] <-
1541 self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1542 }
1543 if let DefKind::Trait | DefKind::Impl { .. } = def_kind {
1544 let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
1545 {
{
let value =
associated_item_def_ids.iter().map(|&def_id|
{
if !def_id.is_local() {
::core::panicking::panic("assertion failed: def_id.is_local()")
};
def_id.index
});
let lazy = self.lazy_array(value);
self.tables.associated_item_or_field_def_ids.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.associated_item_or_field_def_ids[def_id] <-
1546 associated_item_def_ids.iter().map(|&def_id| {
1547 assert!(def_id.is_local());
1548 def_id.index
1549 })
1550 );
1551 for &def_id in associated_item_def_ids {
1552 self.encode_info_for_assoc_item(def_id);
1553 }
1554 }
1555 if let DefKind::Closure | DefKind::SyntheticCoroutineBody = def_kind
1556 && let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
1557 {
1558 self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
1559 }
1560 if def_kind == DefKind::Closure
1561 && tcx.type_of(def_id).skip_binder().is_coroutine_closure()
1562 {
1563 let coroutine_for_closure = self.tcx.coroutine_for_closure(def_id);
1564 self.tables
1565 .coroutine_for_closure
1566 .set_some(def_id.index, coroutine_for_closure.into());
1567
1568 if tcx.needs_coroutine_by_move_body_def_id(coroutine_for_closure) {
1570 self.tables.coroutine_by_move_body_def_id.set_some(
1571 coroutine_for_closure.index,
1572 self.tcx.coroutine_by_move_body_def_id(coroutine_for_closure).into(),
1573 );
1574 }
1575 }
1576 if let DefKind::Static { .. } = def_kind {
1577 if !self.tcx.is_foreign_item(def_id) {
1578 let data = self.tcx.eval_static_initializer(def_id).unwrap();
1579 {
{
let value = data;
let lazy = self.lazy(value);
self.tables.eval_static_initializer.set_some(def_id.index, lazy);
}
};record!(self.tables.eval_static_initializer[def_id] <- data);
1580 }
1581 }
1582 if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
1583 self.encode_info_for_adt(local_id);
1584 }
1585 if let DefKind::Mod = def_kind {
1586 self.encode_info_for_mod(local_id);
1587 }
1588 if let DefKind::Macro(_) = def_kind {
1589 self.encode_info_for_macro(local_id);
1590 }
1591 if let DefKind::TyAlias = def_kind {
1592 self.tables
1593 .type_alias_is_checked
1594 .set(def_id.index, self.tcx.type_alias_is_checked(def_id));
1595 if self.tcx.type_alias_is_checked(def_id) {
1596 {
{
let value = tcx.args_known_to_outlive_alias_params(def_id);
let lazy = self.lazy(value);
self.tables.args_known_to_outlive_alias_params.set_some(def_id.index,
lazy);
}
};record!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1597 }
1598 }
1599 if let DefKind::OpaqueTy = def_kind {
1600 self.encode_explicit_item_bounds(def_id);
1601 self.encode_explicit_item_self_bounds(def_id);
1602 {
{
let value = self.tcx.opaque_ty_origin(def_id);
let lazy = self.lazy(value);
self.tables.opaque_ty_origin.set_some(def_id.index, lazy);
}
};record!(self.tables.opaque_ty_origin[def_id] <- self.tcx.opaque_ty_origin(def_id));
1603 self.encode_precise_capturing_args(def_id);
1604 if tcx.is_conditionally_const(def_id) {
1605 {
{
let value = tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1606 <- tcx.explicit_implied_const_bounds(def_id).skip_binder());
1607 }
1608 {
{
let value = tcx.args_known_to_outlive_alias_params(def_id);
let lazy = self.lazy(value);
self.tables.args_known_to_outlive_alias_params.set_some(def_id.index,
lazy);
}
};record!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1609 }
1610 if let DefKind::AssocTy = def_kind {
1611 let assoc_item = tcx.associated_item(def_id);
1612 match assoc_item.container {
1613 ty::AssocContainer::Trait => {
1614 {
{
let value = tcx.args_known_to_outlive_alias_params(def_id);
let lazy = self.lazy(value);
self.tables.args_known_to_outlive_alias_params.set_some(def_id.index,
lazy);
}
};record!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1615 }
1616 ty::AssocContainer::InherentImpl => {
1617 {
{
let value = tcx.args_known_to_outlive_alias_params(def_id);
let lazy = self.lazy(value);
self.tables.args_known_to_outlive_alias_params.set_some(def_id.index,
lazy);
}
};record!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1618 }
1619 ty::AssocContainer::TraitImpl(_) => {}
1620 }
1621 }
1622 if let DefKind::AnonConst = def_kind {
1623 {
{
let value = self.tcx.anon_const_kind(def_id);
let lazy = self.lazy(value);
self.tables.anon_const_kind.set_some(def_id.index, lazy);
}
};record!(self.tables.anon_const_kind[def_id] <- self.tcx.anon_const_kind(def_id));
1624 }
1625 if should_encode_const_of_item(self.tcx, def_id, def_kind) {
1626 {
{
let value = self.tcx.const_of_item(def_id);
let lazy = self.lazy(value);
self.tables.const_of_item.set_some(def_id.index, lazy);
}
};record!(self.tables.const_of_item[def_id] <- self.tcx.const_of_item(def_id));
1627 }
1628 if tcx.impl_method_has_trait_impl_trait_tys(def_id)
1629 && let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
1630 {
1631 {
{
let value = table;
let lazy = self.lazy(value);
self.tables.collect_return_position_impl_trait_in_trait_tys.set_some(def_id.index,
lazy);
}
};record!(self.tables.collect_return_position_impl_trait_in_trait_tys[def_id] <- table);
1632 }
1633 if let DefKind::Impl { .. } | DefKind::Trait = def_kind {
1634 let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);
1635 {
{
let value = table;
let lazy = self.lazy(value);
self.tables.associated_types_for_impl_traits_in_trait_or_impl.set_some(def_id.index,
lazy);
}
};record!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table);
1636 }
1637 }
1638
1639 for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
1640 {
{
let value =
impls.iter().map(|def_id|
{
if !def_id.is_local() {
::core::panicking::panic("assertion failed: def_id.is_local()")
};
def_id.index
});
let lazy = self.lazy_array(value);
self.tables.inherent_impls.set(def_id.to_def_id().index, lazy);
}
};record_defaulted_array!(self.tables.inherent_impls[def_id.to_def_id()] <- impls.iter().map(|def_id| {
1641 assert!(def_id.is_local());
1642 def_id.index
1643 }));
1644 }
1645
1646 for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1647 {
{
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1648 }
1649
1650 for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1651 {
{
let value = traits;
let lazy = self.lazy_array(value);
self.tables.doc_link_traits_in_scope.set_some(def_id.to_def_id().index,
lazy);
}
};record_array!(self.tables.doc_link_traits_in_scope[def_id.to_def_id()] <- traits);
1652 }
1653 }
1654
1655 fn encode_externally_implementable_items(&mut self) -> LazyArray<EiiMapEncodedKeyValue> {
1656 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1657 let externally_implementable_items = self.tcx.externally_implementable_items(LOCAL_CRATE);
1658
1659 self.lazy_array(externally_implementable_items.iter().map(
1660 |(foreign_item, (decl, impls))| {
1661 (
1662 *foreign_item,
1663 (decl.clone(), impls.iter().map(|(impl_did, i)| (*impl_did, *i)).collect()),
1664 )
1665 },
1666 ))
1667 }
1668
1669 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_info_for_adt",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1669u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("local_def_id")
}> =
::tracing::__macro_support::FieldName::new("local_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&local_def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let def_id = local_def_id.to_def_id();
let tcx = self.tcx;
let adt_def = tcx.adt_def(def_id);
{
{
let value = adt_def.repr();
let lazy = self.lazy(value);
self.tables.repr_options.set_some(def_id.index, lazy);
}
};
let params_in_repr = self.tcx.params_in_repr(def_id);
{
{
let value = params_in_repr;
let lazy = self.lazy(value);
self.tables.params_in_repr.set_some(def_id.index, lazy);
}
};
if adt_def.is_enum() {
let module_children = tcx.module_children_local(local_def_id);
{
{
let value =
module_children.iter().map(|child|
child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};
} else {
if true {
{
match (&adt_def.variants().len(), &1) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
if true {
{
match (&adt_def.non_enum_variant().def_id, &def_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
}
for (idx, variant) in adt_def.variants().iter_enumerated() {
let data =
VariantData {
discr: variant.discr,
idx,
ctor: variant.ctor.map(|(kind, def_id)|
(kind, def_id.index)),
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};
{
{
let value = data;
let lazy = self.lazy(value);
self.tables.variant_data.set_some(variant.def_id.index,
lazy);
}
};
{
{
let value =
variant.fields.iter().map(|f|
{
if !f.did.is_local() {
::core::panicking::panic("assertion failed: f.did.is_local()")
};
f.did.index
});
let lazy = self.lazy_array(value);
self.tables.associated_item_or_field_def_ids.set_some(variant.def_id.index,
lazy);
}
};
for field in &variant.fields {
self.tables.safety.set(field.did.index, field.safety);
{
{
let value = field.mut_restriction;
let lazy = self.lazy(value);
self.tables.mut_restriction.set_some(field.did.index, lazy);
}
};
}
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
let fn_sig = tcx.fn_sig(ctor_def_id);
{
{
let value = fn_sig;
let lazy = self.lazy(value);
self.tables.fn_sig.set_some(variant.def_id.index, lazy);
}
};
}
}
if let Some(destructor) = tcx.adt_destructor(local_def_id) {
{
{
let value = destructor;
let lazy = self.lazy(value);
self.tables.adt_destructor.set_some(def_id.index, lazy);
}
};
}
if let Some(destructor) = tcx.adt_async_destructor(local_def_id) {
{
{
let value = destructor;
let lazy = self.lazy(value);
self.tables.adt_async_destructor.set_some(def_id.index,
lazy);
}
};
}
}
}
}#[instrument(level = "trace", skip(self))]
1670 fn encode_info_for_adt(&mut self, local_def_id: LocalDefId) {
1671 let def_id = local_def_id.to_def_id();
1672 let tcx = self.tcx;
1673 let adt_def = tcx.adt_def(def_id);
1674 record!(self.tables.repr_options[def_id] <- adt_def.repr());
1675
1676 let params_in_repr = self.tcx.params_in_repr(def_id);
1677 record!(self.tables.params_in_repr[def_id] <- params_in_repr);
1678
1679 if adt_def.is_enum() {
1680 let module_children = tcx.module_children_local(local_def_id);
1681 record_array!(self.tables.module_children_non_reexports[def_id] <-
1682 module_children.iter().map(|child| child.res.def_id().index));
1683 } else {
1684 debug_assert_eq!(adt_def.variants().len(), 1);
1686 debug_assert_eq!(adt_def.non_enum_variant().def_id, def_id);
1687 }
1689
1690 for (idx, variant) in adt_def.variants().iter_enumerated() {
1691 let data = VariantData {
1692 discr: variant.discr,
1693 idx,
1694 ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1695 is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1696 };
1697 record!(self.tables.variant_data[variant.def_id] <- data);
1698
1699 record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
1700 assert!(f.did.is_local());
1701 f.did.index
1702 }));
1703
1704 for field in &variant.fields {
1705 self.tables.safety.set(field.did.index, field.safety);
1706 record!(
1707 self.tables.mut_restriction[field.did] <- field.mut_restriction
1708 );
1709 }
1710
1711 if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
1712 let fn_sig = tcx.fn_sig(ctor_def_id);
1713 record!(self.tables.fn_sig[variant.def_id] <- fn_sig);
1715 }
1716 }
1717
1718 if let Some(destructor) = tcx.adt_destructor(local_def_id) {
1719 record!(self.tables.adt_destructor[def_id] <- destructor);
1720 }
1721
1722 if let Some(destructor) = tcx.adt_async_destructor(local_def_id) {
1723 record!(self.tables.adt_async_destructor[def_id] <- destructor);
1724 }
1725 }
1726
1727 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_info_for_mod",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1727u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("local_def_id")
}> =
::tracing::__macro_support::FieldName::new("local_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&local_def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let def_id = local_def_id.to_def_id();
if self.is_proc_macro {
{
{
let value = tcx.expn_that_defined(local_def_id);
let lazy = self.lazy(value);
self.tables.expn_that_defined.set_some(def_id.index, lazy);
}
};
} else {
let module_children = tcx.module_children_local(local_def_id);
{
{
let value =
module_children.iter().filter(|child|
child.reexport_chain.is_empty()).map(|child|
child.res.def_id().index);
let lazy = self.lazy_array(value);
self.tables.module_children_non_reexports.set_some(def_id.index,
lazy);
}
};
{
{
let value =
module_children.iter().filter(|child|
!child.reexport_chain.is_empty());
let lazy = self.lazy_array(value);
self.tables.module_children_reexports.set(def_id.index,
lazy);
}
};
let ambig_module_children =
tcx.resolutions(()).ambig_module_children.get(&local_def_id).map_or_default(|v|
&v[..]);
{
{
let value = ambig_module_children;
let lazy = self.lazy_array(value);
self.tables.ambig_module_children.set(def_id.index, lazy);
}
};
}
}
}
}#[instrument(level = "debug", skip(self))]
1728 fn encode_info_for_mod(&mut self, local_def_id: LocalDefId) {
1729 let tcx = self.tcx;
1730 let def_id = local_def_id.to_def_id();
1731
1732 if self.is_proc_macro {
1738 record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
1740 } else {
1741 let module_children = tcx.module_children_local(local_def_id);
1742
1743 record_array!(self.tables.module_children_non_reexports[def_id] <-
1744 module_children.iter().filter(|child| child.reexport_chain.is_empty())
1745 .map(|child| child.res.def_id().index));
1746
1747 record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
1748 module_children.iter().filter(|child| !child.reexport_chain.is_empty()));
1749
1750 let ambig_module_children = tcx
1751 .resolutions(())
1752 .ambig_module_children
1753 .get(&local_def_id)
1754 .map_or_default(|v| &v[..]);
1755 record_defaulted_array!(self.tables.ambig_module_children[def_id] <-
1756 ambig_module_children);
1757 }
1758 }
1759
1760 fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
1761 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1761",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1761u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("EncodeContext::encode_explicit_item_bounds({0:?})",
def_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
1762 let bounds = self.tcx.explicit_item_bounds(def_id).skip_binder();
1763 {
{
let value = bounds;
let lazy = self.lazy_array(value);
self.tables.explicit_item_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds);
1764 }
1765
1766 fn encode_explicit_item_self_bounds(&mut self, def_id: DefId) {
1767 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1767",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1767u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("EncodeContext::encode_explicit_item_self_bounds({0:?})",
def_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("EncodeContext::encode_explicit_item_self_bounds({:?})", def_id);
1768 let bounds = self.tcx.explicit_item_self_bounds(def_id).skip_binder();
1769 {
{
let value = bounds;
let lazy = self.lazy_array(value);
self.tables.explicit_item_self_bounds.set(def_id.index, lazy);
}
};record_defaulted_array!(self.tables.explicit_item_self_bounds[def_id] <- bounds);
1770 }
1771
1772 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_info_for_assoc_item",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1772u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let item = tcx.associated_item(def_id);
if #[allow(non_exhaustive_omitted_patterns)] match item.container
{
AssocContainer::Trait | AssocContainer::TraitImpl(_) =>
true,
_ => false,
} {
self.tables.defaultness.set(def_id.index,
item.defaultness(tcx));
}
{
{
let value = item.container;
let lazy = self.lazy(value);
self.tables.assoc_container.set_some(def_id.index, lazy);
}
};
if let AssocContainer::Trait = item.container && item.is_type() {
self.encode_explicit_item_bounds(def_id);
self.encode_explicit_item_self_bounds(def_id);
if tcx.is_conditionally_const(def_id) {
{
{
let value =
self.tcx.explicit_implied_const_bounds(def_id).skip_binder();
let lazy = self.lazy_array(value);
self.tables.explicit_implied_const_bounds.set(def_id.index,
lazy);
}
};
}
}
if let ty::AssocKind::Type {
data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
{
{
let value = rpitit_info;
let lazy = self.lazy(value);
self.tables.opt_rpitit_info.set_some(def_id.index, lazy);
}
};
if #[allow(non_exhaustive_omitted_patterns)] match rpitit_info
{
ty::ImplTraitInTraitData::Trait { .. } => true,
_ => false,
} {
{
{
let value = self.tcx.assumed_wf_types_for_rpitit(def_id);
let lazy = self.lazy_array(value);
self.tables.assumed_wf_types_for_rpitit.set_some(def_id.index,
lazy);
}
};
self.encode_precise_capturing_args(def_id);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1773 fn encode_info_for_assoc_item(&mut self, def_id: DefId) {
1774 let tcx = self.tcx;
1775 let item = tcx.associated_item(def_id);
1776
1777 if matches!(item.container, AssocContainer::Trait | AssocContainer::TraitImpl(_)) {
1778 self.tables.defaultness.set(def_id.index, item.defaultness(tcx));
1779 }
1780
1781 record!(self.tables.assoc_container[def_id] <- item.container);
1782
1783 if let AssocContainer::Trait = item.container
1784 && item.is_type()
1785 {
1786 self.encode_explicit_item_bounds(def_id);
1787 self.encode_explicit_item_self_bounds(def_id);
1788 if tcx.is_conditionally_const(def_id) {
1789 record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1790 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1791 }
1792 }
1793 if let ty::AssocKind::Type { data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
1794 record!(self.tables.opt_rpitit_info[def_id] <- rpitit_info);
1795 if matches!(rpitit_info, ty::ImplTraitInTraitData::Trait { .. }) {
1796 record_array!(
1797 self.tables.assumed_wf_types_for_rpitit[def_id]
1798 <- self.tcx.assumed_wf_types_for_rpitit(def_id)
1799 );
1800 self.encode_precise_capturing_args(def_id);
1801 }
1802 }
1803 }
1804
1805 fn encode_precise_capturing_args(&mut self, def_id: DefId) {
1806 let Some(precise_capturing_args) = self.tcx.rendered_precise_capturing_args(def_id) else {
1807 return;
1808 };
1809
1810 {
{
let value = precise_capturing_args;
let lazy = self.lazy_array(value);
self.tables.rendered_precise_capturing_args.set_some(def_id.index,
lazy);
}
};record_array!(self.tables.rendered_precise_capturing_args[def_id] <- precise_capturing_args);
1811 }
1812
1813 fn encode_mir(&mut self) {
1814 if self.is_proc_macro {
1815 return;
1816 }
1817
1818 let tcx = self.tcx;
1819 let reachable_set = tcx.reachable_set(());
1820
1821 let keys_and_jobs = tcx.mir_keys(()).iter().filter_map(|&def_id| {
1822 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
1823 if encode_const || encode_opt { Some((def_id, encode_const, encode_opt)) } else { None }
1824 });
1825 for (def_id, encode_const, encode_opt) in keys_and_jobs {
1826 if true {
if !(encode_const || encode_opt) {
::core::panicking::panic("assertion failed: encode_const || encode_opt")
};
};debug_assert!(encode_const || encode_opt);
1827
1828 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:1828",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1828u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("EntryBuilder::encode_mir({0:?})",
def_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("EntryBuilder::encode_mir({:?})", def_id);
1829 if encode_opt {
1830 {
{
let value = tcx.optimized_mir(def_id);
let lazy = self.lazy(value);
self.tables.optimized_mir.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
1831 self.tables
1832 .cross_crate_inlinable
1833 .set(def_id.to_def_id().index, self.tcx.cross_crate_inlinable(def_id));
1834 {
{
let value = tcx.closure_saved_names_of_captured_variables(def_id);
let lazy = self.lazy(value);
self.tables.closure_saved_names_of_captured_variables.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
1835 <- tcx.closure_saved_names_of_captured_variables(def_id));
1836
1837 if self.tcx.is_coroutine(def_id.to_def_id())
1838 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1839 {
1840 {
{
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1841 }
1842 }
1843 let mut is_trivial = false;
1844 if encode_const {
1845 if let Some((val, ty)) = tcx.trivial_const(def_id) {
1846 is_trivial = true;
1847 {
{
let value = (val, ty);
let lazy = self.lazy(value);
self.tables.trivial_const.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.trivial_const[def_id.to_def_id()] <- (val, ty));
1848 } else {
1849 is_trivial = false;
1850 {
{
let value = tcx.mir_for_ctfe(def_id);
let lazy = self.lazy(value);
self.tables.mir_for_ctfe.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
1851 }
1852
1853 let abstract_const = tcx.thir_abstract_const(def_id);
1855 if let Ok(Some(abstract_const)) = abstract_const {
1856 {
{
let value = abstract_const;
let lazy = self.lazy(value);
self.tables.thir_abstract_const.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.thir_abstract_const[def_id.to_def_id()] <- abstract_const);
1857 }
1858
1859 if should_encode_const(tcx.def_kind(def_id)) {
1860 let qualifs = tcx.mir_const_qualif(def_id);
1861 {
{
let value = qualifs;
let lazy = self.lazy(value);
self.tables.mir_const_qualif.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
1862 let body = tcx.hir_maybe_body_owned_by(def_id);
1863 if let Some(body) = body {
1864 let const_data = rendered_const(self.tcx, &body, def_id);
1865 {
{
let value = const_data;
let lazy = self.lazy(value);
self.tables.rendered_const.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
1866 }
1867 }
1868 }
1869 if !is_trivial {
1870 {
{
let value = tcx.promoted_mir(def_id);
let lazy = self.lazy(value);
self.tables.promoted_mir.set_some(def_id.to_def_id().index, lazy);
}
};record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
1871 }
1872
1873 if self.tcx.is_coroutine(def_id.to_def_id())
1874 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1875 {
1876 {
{
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
}
};record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1877 }
1878 }
1879
1880 if tcx.sess.opts.output_types.should_codegen()
1884 && tcx.sess.opts.optimize != OptLevel::No
1885 && tcx.sess.opts.incremental.is_none()
1886 {
1887 for &local_def_id in tcx.mir_keys(()) {
1888 if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
1889 {
{
let value = self.tcx.deduced_param_attrs(local_def_id.to_def_id());
let lazy = self.lazy_array(value);
self.tables.deduced_param_attrs.set_some(local_def_id.to_def_id().index,
lazy);
}
};record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <-
1890 self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
1891 }
1892 }
1893 }
1894 }
1895
1896 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1896u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) = self.tcx.lookup_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(def_id.index, lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1897 fn encode_stability(&mut self, def_id: DefId) {
1898 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1901 if let Some(stab) = self.tcx.lookup_stability(def_id) {
1902 record!(self.tables.lookup_stability[def_id] <- stab)
1903 }
1904 }
1905 }
1906
1907 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_const_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1907u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_const_stability.set_some(def_id.index,
lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1908 fn encode_const_stability(&mut self, def_id: DefId) {
1909 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1912 if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
1913 record!(self.tables.lookup_const_stability[def_id] <- stab)
1914 }
1915 }
1916 }
1917
1918 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_default_body_stability",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1918u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if self.feat.staged_api() ||
self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked
{
if let Some(stab) =
self.tcx.lookup_default_body_stability(def_id) {
{
{
let value = stab;
let lazy = self.lazy(value);
self.tables.lookup_default_body_stability.set_some(def_id.index,
lazy);
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1919 fn encode_default_body_stability(&mut self, def_id: DefId) {
1920 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1923 if let Some(stab) = self.tcx.lookup_default_body_stability(def_id) {
1924 record!(self.tables.lookup_default_body_stability[def_id] <- stab)
1925 }
1926 }
1927 }
1928
1929 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_deprecation",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1929u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(depr) = self.tcx.lookup_deprecation(def_id) {
{
{
let value = depr;
let lazy = self.lazy(value);
self.tables.lookup_deprecation_entry.set_some(def_id.index,
lazy);
}
};
}
}
}
}#[instrument(level = "debug", skip(self))]
1930 fn encode_deprecation(&mut self, def_id: DefId) {
1931 if let Some(depr) = self.tcx.lookup_deprecation(def_id) {
1932 record!(self.tables.lookup_deprecation_entry[def_id] <- depr);
1933 }
1934 }
1935
1936 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_info_for_macro",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1936u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let (_, macro_def, _) =
tcx.hir_expect_item(def_id).expect_macro();
self.tables.is_macro_rules.set(def_id.local_def_index,
macro_def.macro_rules);
{
{
let value = &*macro_def.body;
let lazy = self.lazy(value);
self.tables.macro_definition.set_some(def_id.to_def_id().index,
lazy);
}
};
}
}
}#[instrument(level = "debug", skip(self))]
1937 fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
1938 let tcx = self.tcx;
1939
1940 let (_, macro_def, _) = tcx.hir_expect_item(def_id).expect_macro();
1941 self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
1942 record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
1943 }
1944
1945 fn encode_native_libraries(&mut self) -> LazyArray<NativeLib> {
1946 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1947 let used_libraries = self.tcx.native_libraries(LOCAL_CRATE);
1948 self.lazy_array(used_libraries.iter())
1949 }
1950
1951 fn encode_foreign_modules(&mut self) -> LazyArray<ForeignModule> {
1952 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1953 let foreign_modules = self.tcx.foreign_modules(LOCAL_CRATE);
1954 self.lazy_array(foreign_modules.iter().map(|(_, m)| m).cloned())
1955 }
1956
1957 fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable, ExpnHashTable) {
1958 let mut syntax_contexts: TableBuilder<_, _> = Default::default();
1959 let mut expn_data_table: TableBuilder<_, _> = Default::default();
1960 let mut expn_hash_table: TableBuilder<_, _> = Default::default();
1961
1962 self.hygiene_ctxt.encode(
1963 &mut (&mut *self, &mut syntax_contexts, &mut expn_data_table, &mut expn_hash_table),
1964 |(this, syntax_contexts, _, _), index, ctxt_data| {
1965 syntax_contexts.set_some(index, this.lazy(ctxt_data));
1966 },
1967 |(this, _, expn_data_table, expn_hash_table), index, expn_data, hash| {
1968 if let Some(index) = index.as_local() {
1969 expn_data_table.set_some(index.as_raw(), this.lazy(expn_data));
1970 expn_hash_table.set_some(index.as_raw(), this.lazy(hash));
1971 }
1972 },
1973 );
1974
1975 (
1976 syntax_contexts.encode(&mut self.opaque),
1977 expn_data_table.encode(&mut self.opaque),
1978 expn_hash_table.encode(&mut self.opaque),
1979 )
1980 }
1981
1982 fn encode_proc_macros(&mut self) -> Option<ProcMacroData> {
1983 let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro);
1984 if is_proc_macro {
1985 let tcx = self.tcx;
1986 let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
1987 let stability = tcx.lookup_stability(CRATE_DEF_ID);
1988 for (i, span) in self.tcx.sess.proc_macro_quoted_spans() {
1989 let span = self.lazy(span);
1990 self.tables.proc_macro_quoted_spans.set_some(i, span);
1991 }
1992
1993 self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
1994 {
{
let value = tcx.def_span(LOCAL_CRATE.as_def_id());
let lazy = self.lazy(value);
self.tables.def_span.set_some(LOCAL_CRATE.as_def_id().index, lazy);
}
};record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
1995 self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
1996 let vis = tcx
1997 .local_visibility(CRATE_DEF_ID)
1998 .map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
1999 {
{
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(LOCAL_CRATE.as_def_id().index, lazy);
}
};record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis);
2000 if let Some(stability) = stability {
2001 {
{
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability);
2002 }
2003 self.encode_deprecation(LOCAL_CRATE.as_def_id());
2004 if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_MOD_ID) {
2005 {
{
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record!(self.tables.doc_link_resolutions[LOCAL_CRATE.as_def_id()] <- res_map);
2006 }
2007 if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_MOD_ID) {
2008 {
{
let value = traits;
let lazy = self.lazy_array(value);
self.tables.doc_link_traits_in_scope.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
}
};record_array!(self.tables.doc_link_traits_in_scope[LOCAL_CRATE.as_def_id()] <- traits);
2009 }
2010
2011 let mut macros = ::alloc::vec::Vec::new()vec![];
2012
2013 for &proc_macro in &tcx.resolutions(()).proc_macros {
2017 let id = proc_macro;
2018 let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
2019 let mut name = tcx.hir_name(proc_macro);
2020 let span = tcx.hir_span(proc_macro);
2021 let attrs = tcx.hir_attrs(proc_macro);
2024 let (macro_kind, kind) = if {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(ProcMacro) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
}find_attr!(attrs, ProcMacro) {
2025 (MacroKind::Bang, ProcMacroKind::Bang { name: name.as_str().to_owned() })
2026 } else if {
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(ProcMacroAttribute) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
}find_attr!(attrs, ProcMacroAttribute) {
2027 (MacroKind::Attr, ProcMacroKind::Attr { name: name.as_str().to_owned() })
2028 } else if let Some((trait_name, helper_attrs)) = {
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(ProcMacroDerive {
trait_name, helper_attrs }) => {
break 'done Some((trait_name, helper_attrs));
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}find_attr!(attrs,
2029 ProcMacroDerive { trait_name, helper_attrs } => (trait_name, helper_attrs))
2030 {
2031 name = *trait_name;
2032 (
2033 MacroKind::Derive,
2034 ProcMacroKind::CustomDerive {
2035 trait_name: name.as_str().to_owned(),
2036 attributes: helper_attrs
2037 .iter()
2038 .map(|attr| attr.as_str().to_owned())
2039 .collect(),
2040 },
2041 )
2042 } else {
2043 ::rustc_middle::util::bug::bug_fmt(format_args!("Unknown proc-macro type for item {0:?}",
id));bug!("Unknown proc-macro type for item {:?}", id);
2044 };
2045
2046 macros.push((id.local_def_index, self.lazy(kind)));
2047
2048 let mut def_key = self.tcx.hir_def_key(id);
2049 def_key.disambiguated_data.data = DefPathData::MacroNs(name);
2050
2051 let def_id = id.to_def_id();
2052 self.tables.def_kind.set_some(def_id.index, DefKind::Macro(macro_kind.into()));
2053 self.encode_attrs(id);
2054 {
{
let value = def_key;
let lazy = self.lazy(value);
self.tables.def_keys.set_some(def_id.index, lazy);
}
};record!(self.tables.def_keys[def_id] <- def_key);
2055 {
{
let value = span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_ident_span[def_id] <- span);
2056 {
{
let value = span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
}
};record!(self.tables.def_span[def_id] <- span);
2057 {
{
let value = ty::Visibility::Public;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
}
};record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
2058 if let Some(stability) = stability {
2059 {
{
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(def_id.index, lazy);
}
};record!(self.tables.lookup_stability[def_id] <- stability);
2060 }
2061 }
2062
2063 let macros = self.lazy_array(macros);
2064
2065 Some(ProcMacroData { proc_macro_decls_static, stability, macros })
2066 } else {
2067 None
2068 }
2069 }
2070
2071 fn encode_debugger_visualizers(&mut self) -> LazyArray<DebuggerVisualizerFile> {
2072 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2073 self.lazy_array(
2074 self.tcx
2075 .debugger_visualizers(LOCAL_CRATE)
2076 .iter()
2077 .map(DebuggerVisualizerFile::path_erased),
2082 )
2083 }
2084
2085 fn encode_crate_deps(&mut self) -> LazyArray<CrateDep> {
2086 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2087
2088 let deps = self
2089 .tcx
2090 .crates(())
2091 .iter()
2092 .map(|&cnum| {
2093 let dep = CrateDep {
2094 name: self.tcx.crate_name(cnum),
2095 hash: self.tcx.crate_hash(cnum),
2096 host_hash: self.tcx.crate_host_hash(cnum),
2097 kind: self.tcx.crate_dep_kind(cnum),
2098 extra_filename: self.tcx.extra_filename(cnum).clone(),
2099 is_private: self.tcx.is_private_dep(cnum),
2100 };
2101 (cnum, dep)
2102 })
2103 .collect::<Vec<_>>();
2104
2105 {
2106 let mut expected_cnum = 1;
2108 for &(n, _) in &deps {
2109 {
match (&n, &CrateNum::new(expected_cnum)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(n, CrateNum::new(expected_cnum));
2110 expected_cnum += 1;
2111 }
2112 }
2113
2114 self.lazy_array(deps.iter().map(|(_, dep)| dep))
2119 }
2120
2121 fn encode_target_modifiers(&mut self) -> LazyArray<TargetModifier> {
2122 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2123 let tcx = self.tcx;
2124 self.lazy_array(tcx.sess.opts.gather_target_modifiers())
2125 }
2126
2127 fn encode_enabled_denied_partial_mitigations(&mut self) -> LazyArray<DeniedPartialMitigation> {
2128 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2129 let tcx = self.tcx;
2130 self.lazy_array(tcx.sess.gather_enabled_denied_partial_mitigations())
2131 }
2132
2133 fn encode_lib_features(&mut self) -> LazyArray<(Symbol, FeatureStability)> {
2134 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2135 let tcx = self.tcx;
2136 let lib_features = tcx.lib_features(LOCAL_CRATE);
2137 self.lazy_array(lib_features.to_sorted_vec())
2138 }
2139
2140 fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> {
2141 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2142 let tcx = self.tcx;
2143 let implications = tcx.stability_implications(LOCAL_CRATE);
2144 let sorted = implications.to_sorted_stable_ord();
2145 self.lazy_array(sorted.into_iter().map(|(k, v)| (*k, *v)))
2146 }
2147
2148 fn encode_canonical_symbols(&mut self) -> LazyArray<(Symbol, DefIndex)> {
2149 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2150 let tcx = self.tcx;
2151 let canonical_symbols = &tcx.canonical_symbols(LOCAL_CRATE);
2152 self.lazy_array(canonical_symbols.iter().map(|cs| (cs.symbol, cs.def_id.index)))
2153 }
2154
2155 fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
2156 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2157 let tcx = self.tcx;
2158 let diagnostic_items = &tcx.diagnostic_items(LOCAL_CRATE).name_to_id;
2159 self.lazy_array(diagnostic_items.iter().map(|(&name, def_id)| (name, def_id.index)))
2160 }
2161
2162 fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, LangItem)> {
2163 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2164 let lang_items = self.tcx.lang_items().iter();
2165 self.lazy_array(lang_items.filter_map(|(lang_item, def_id)| {
2166 def_id.as_local().map(|id| (id.local_def_index, lang_item))
2167 }))
2168 }
2169
2170 fn encode_lang_items_missing(&mut self) -> LazyArray<LangItem> {
2171 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2172 let tcx = self.tcx;
2173 self.lazy_array(&tcx.lang_items().missing)
2174 }
2175
2176 fn encode_stripped_cfg_items(&mut self) -> LazyArray<StrippedCfgItem<DefIndex>> {
2177 self.lazy_array(
2178 self.tcx
2179 .stripped_cfg_items(LOCAL_CRATE)
2180 .into_iter()
2181 .map(|item| item.clone().map_scope_id(|def_id| def_id.index)),
2182 )
2183 }
2184
2185 fn encode_traits(&mut self) -> LazyArray<DefIndex> {
2186 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2187 self.lazy_array(self.tcx.traits(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2188 }
2189
2190 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_impls",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2191u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: LazyArray<TraitImpls> = loop {};
return __tracing_attr_fake_return;
}
{
if self.is_proc_macro { return LazyArray::default(); };
let tcx = self.tcx;
let mut trait_impls:
FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
FxIndexMap::default();
for id in tcx.hir_free_items() {
let DefKind::Impl { of_trait } =
tcx.def_kind(id.owner_id) else { continue; };
let def_id = id.owner_id.to_def_id();
if of_trait {
let header = tcx.impl_trait_header(def_id);
{
{
let value = header;
let lazy = self.lazy(value);
self.tables.impl_trait_header.set_some(def_id.index, lazy);
}
};
let impl_is_fully_generic_for_reflection =
tcx.impl_is_fully_generic_for_reflection(def_id);
self.tables.impl_is_fully_generic_for_reflection.set(def_id.index,
impl_is_fully_generic_for_reflection);
self.tables.defaultness.set(def_id.index,
tcx.defaultness(def_id));
let trait_ref =
header.trait_ref.instantiate_identity().skip_norm_wip();
let simplified_self_ty =
fast_reject::simplify_type(self.tcx, trait_ref.self_ty(),
TreatParams::InstantiateWithInfer);
trait_impls.entry(trait_ref.def_id).or_default().push((id.owner_id.def_id.local_def_index,
simplified_self_ty));
let trait_def = tcx.trait_def(trait_ref.def_id);
if let Ok(mut an) = trait_def.ancestors(tcx, def_id) &&
let Some(specialization_graph::Node::Impl(parent)) =
an.nth(1) {
self.tables.impl_parent.set_some(def_id.index,
parent.into());
}
if tcx.is_lang_item(trait_ref.def_id,
LangItem::CoerceUnsized) {
let coerce_unsized_info =
tcx.coerce_unsized_info(def_id).unwrap();
{
{
let value = coerce_unsized_info;
let lazy = self.lazy(value);
self.tables.coerce_unsized_info.set_some(def_id.index,
lazy);
}
};
}
}
}
let trait_impls: Vec<_> =
trait_impls.into_iter().map(|(trait_def_id, impls)|
TraitImpls {
trait_id: (trait_def_id.krate.as_u32(), trait_def_id.index),
impls: self.lazy_array(&impls),
}).collect();
self.lazy_array(&trait_impls)
}
}
}#[instrument(level = "debug", skip(self))]
2192 fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
2193 empty_proc_macro!(self);
2194 let tcx = self.tcx;
2195 let mut trait_impls: FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
2196 FxIndexMap::default();
2197
2198 for id in tcx.hir_free_items() {
2199 let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
2200 continue;
2201 };
2202 let def_id = id.owner_id.to_def_id();
2203
2204 if of_trait {
2205 let header = tcx.impl_trait_header(def_id);
2206 record!(self.tables.impl_trait_header[def_id] <- header);
2207
2208 let impl_is_fully_generic_for_reflection =
2209 tcx.impl_is_fully_generic_for_reflection(def_id);
2210 self.tables
2211 .impl_is_fully_generic_for_reflection
2212 .set(def_id.index, impl_is_fully_generic_for_reflection);
2213
2214 self.tables.defaultness.set(def_id.index, tcx.defaultness(def_id));
2215
2216 let trait_ref = header.trait_ref.instantiate_identity().skip_norm_wip();
2217 let simplified_self_ty = fast_reject::simplify_type(
2218 self.tcx,
2219 trait_ref.self_ty(),
2220 TreatParams::InstantiateWithInfer,
2221 );
2222 trait_impls
2223 .entry(trait_ref.def_id)
2224 .or_default()
2225 .push((id.owner_id.def_id.local_def_index, simplified_self_ty));
2226
2227 let trait_def = tcx.trait_def(trait_ref.def_id);
2228 if let Ok(mut an) = trait_def.ancestors(tcx, def_id)
2229 && let Some(specialization_graph::Node::Impl(parent)) = an.nth(1)
2230 {
2231 self.tables.impl_parent.set_some(def_id.index, parent.into());
2232 }
2233
2234 if tcx.is_lang_item(trait_ref.def_id, LangItem::CoerceUnsized) {
2237 let coerce_unsized_info = tcx.coerce_unsized_info(def_id).unwrap();
2238 record!(self.tables.coerce_unsized_info[def_id] <- coerce_unsized_info);
2239 }
2240 }
2241 }
2242
2243 let trait_impls: Vec<_> = trait_impls
2244 .into_iter()
2245 .map(|(trait_def_id, impls)| TraitImpls {
2246 trait_id: (trait_def_id.krate.as_u32(), trait_def_id.index),
2247 impls: self.lazy_array(&impls),
2248 })
2249 .collect();
2250
2251 self.lazy_array(&trait_impls)
2252 }
2253
2254 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_incoherent_impls",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2254u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: LazyArray<IncoherentImpls> =
loop {};
return __tracing_attr_fake_return;
}
{
if self.is_proc_macro { return LazyArray::default(); };
let tcx = self.tcx;
let all_impls: Vec<_> =
tcx.crate_inherent_impls(()).0.incoherent_impls.iter().map(|(&simp,
impls)|
IncoherentImpls {
self_ty: self.lazy(simp),
impls: self.lazy_array(impls.iter().map(|def_id|
def_id.local_def_index)),
}).collect();
self.lazy_array(&all_impls)
}
}
}#[instrument(level = "debug", skip(self))]
2255 fn encode_incoherent_impls(&mut self) -> LazyArray<IncoherentImpls> {
2256 empty_proc_macro!(self);
2257 let tcx = self.tcx;
2258
2259 let all_impls: Vec<_> = tcx
2260 .crate_inherent_impls(())
2261 .0
2262 .incoherent_impls
2263 .iter()
2264 .map(|(&simp, impls)| IncoherentImpls {
2265 self_ty: self.lazy(simp),
2266 impls: self.lazy_array(impls.iter().map(|def_id| def_id.local_def_index)),
2267 })
2268 .collect();
2269
2270 self.lazy_array(&all_impls)
2271 }
2272
2273 fn encode_exportable_items(&mut self) -> LazyArray<DefIndex> {
2274 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2275 self.lazy_array(self.tcx.exportable_items(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2276 }
2277
2278 fn encode_stable_order_of_exportable_impls(&mut self) -> LazyArray<(DefIndex, usize)> {
2279 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2280 let stable_order_of_exportable_impls =
2281 self.tcx.stable_order_of_exportable_impls(LOCAL_CRATE);
2282 self.lazy_array(
2283 stable_order_of_exportable_impls.iter().map(|(def_id, idx)| (def_id.index, *idx)),
2284 )
2285 }
2286
2287 fn encode_exported_symbols(
2294 &mut self,
2295 exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)],
2296 ) -> LazyArray<(ExportedSymbol<'static>, SymbolExportInfo)> {
2297 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2298
2299 self.lazy_array(exported_symbols.iter().cloned())
2300 }
2301
2302 fn encode_dylib_dependency_formats(&mut self) -> LazyArray<Option<LinkagePreference>> {
2303 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2304 let formats = self.tcx.dependency_formats(());
2305 if let Some(arr) = formats.get(&CrateType::Dylib) {
2306 return self.lazy_array(arr.iter().skip(1 ).map(
2307 |slot| match *slot {
2308 Linkage::NotLinked | Linkage::IncludedFromDylib => None,
2309
2310 Linkage::Dynamic => Some(LinkagePreference::RequireDynamic),
2311 Linkage::Static => Some(LinkagePreference::RequireStatic),
2312 },
2313 ));
2314 }
2315 LazyArray::default()
2316 }
2317}
2318
2319fn prefetch_mir(tcx: TyCtxt<'_>) {
2322 if !tcx.sess.opts.output_types.should_codegen() {
2323 return;
2325 }
2326
2327 let reachable_set = tcx.reachable_set(());
2328 par_for_each_in(tcx.mir_keys(()), |&&def_id| {
2329 if tcx.is_trivial_const(def_id) {
2330 return;
2331 }
2332 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
2333
2334 if encode_const {
2335 tcx.ensure_done().mir_for_ctfe(def_id);
2336 }
2337 if encode_opt {
2338 tcx.ensure_done().optimized_mir(def_id);
2339 }
2340 if encode_opt || encode_const {
2341 tcx.ensure_done().promoted_mir(def_id);
2342 }
2343 })
2344}
2345
2346pub struct EncodedMetadata {
2370 full_metadata: Option<Mmap>,
2373 stub_metadata: Option<Vec<u8>>,
2376 path: Option<Box<Path>>,
2378 _temp_dir: Option<MaybeTempDir>,
2381}
2382
2383impl EncodedMetadata {
2384 #[inline]
2385 pub fn from_path(
2386 path: PathBuf,
2387 stub_path: Option<PathBuf>,
2388 temp_dir: Option<MaybeTempDir>,
2389 ) -> std::io::Result<Self> {
2390 let file = std::fs::File::open(&path)?;
2391 let file_metadata = file.metadata()?;
2392 if file_metadata.len() == 0 {
2393 return Ok(Self {
2394 full_metadata: None,
2395 stub_metadata: None,
2396 path: None,
2397 _temp_dir: None,
2398 });
2399 }
2400 let full_mmap = unsafe { Some(Mmap::map(file)?) };
2401
2402 let stub =
2403 if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
2404
2405 Ok(Self {
2406 full_metadata: full_mmap,
2407 stub_metadata: stub,
2408 path: Some(path.into()),
2409 _temp_dir: temp_dir,
2410 })
2411 }
2412
2413 #[inline]
2414 pub fn full(&self) -> &[u8] {
2415 &self.full_metadata.as_deref().unwrap_or_default()
2416 }
2417
2418 #[inline]
2419 pub fn stub_or_full(&self) -> &[u8] {
2420 self.stub_metadata.as_deref().unwrap_or(self.full())
2421 }
2422
2423 #[inline]
2424 pub fn path(&self) -> Option<&Path> {
2425 self.path.as_deref()
2426 }
2427}
2428
2429impl<S: Encoder> Encodable<S> for EncodedMetadata {
2430 fn encode(&self, s: &mut S) {
2431 self.stub_metadata.encode(s);
2432
2433 let slice = self.full();
2434 slice.encode(s)
2435 }
2436}
2437
2438impl<D: Decoder> Decodable<D> for EncodedMetadata {
2439 fn decode(d: &mut D) -> Self {
2440 let stub = <Option<Vec<u8>>>::decode(d);
2441
2442 let len = d.read_usize();
2443 let full_metadata = if len > 0 {
2444 let mut mmap = MmapMut::map_anon(len).unwrap();
2445 mmap.copy_from_slice(d.read_raw_bytes(len));
2446 Some(mmap.make_read_only().unwrap())
2447 } else {
2448 None
2449 };
2450
2451 Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
2452 }
2453}
2454
2455#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("encode_metadata",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2455u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ref_path")
}> =
::tracing::__macro_support::FieldName::new("ref_path");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ref_path)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
tcx.dep_graph.assert_ignored();
if let Some(ref_path) = ref_path {
let _prof_timer =
tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
with_encode_metadata_header(tcx, ref_path,
|ecx|
{
let header: LazyValue<CrateHeader> =
ecx.lazy(CrateHeader {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
hash: tcx.crate_hash(LOCAL_CRATE),
is_proc_macro_crate: false,
is_stub: true,
});
header.position.get()
})
}
let _prof_timer =
tcx.prof.verbose_generic_activity("generate_crate_metadata");
let dep_node = tcx.metadata_dep_node();
if tcx.dep_graph.is_fully_enabled() &&
let work_product_id =
WorkProductId::from_cgu_name("metadata") &&
let Some(work_product) =
tcx.dep_graph.previous_work_product(&work_product_id) &&
tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some() {
let saved_path = &work_product.saved_files["rmeta"];
let incr_comp_session_dir =
&tcx.incr_comp_session.unwrap().session_directory;
let source_file_in_incr_dir =
&incr_comp_session_dir.join(saved_path);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_metadata/src/rmeta/encoder.rs:2490",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2490u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("copying preexisting metadata from {0:?} to {1:?}",
source_file_in_incr_dir, path) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
match rustc_fs_util::link_or_copy(&source_file_in_incr_dir,
path) {
Ok(_) => {}
Err(err) =>
tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
};
return;
};
if tcx.sess.opts.jobs.frontend.is_some() {
par_join(|| prefetch_mir(tcx),
||
{
let _ = tcx.exported_non_generic_symbols(LOCAL_CRATE);
let _ = tcx.exported_generic_symbols(LOCAL_CRATE);
});
}
tcx.dep_graph.with_task(dep_node, tcx,
||
{
with_encode_metadata_header(tcx, path,
|ecx|
{
let root = ecx.encode_crate_root();
ecx.opaque.flush();
tcx.prof.artifact_size("crate_metadata", "crate_metadata",
ecx.opaque.file().metadata().unwrap().len());
root.position.get()
})
}, None);
}
}
}#[instrument(level = "trace", skip(tcx))]
2456pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2457 tcx.dep_graph.assert_ignored();
2460
2461 if let Some(ref_path) = ref_path {
2463 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
2464
2465 with_encode_metadata_header(tcx, ref_path, |ecx| {
2466 let header: LazyValue<CrateHeader> = ecx.lazy(CrateHeader {
2467 name: tcx.crate_name(LOCAL_CRATE),
2468 triple: tcx.sess.opts.target_triple.clone(),
2469 hash: tcx.crate_hash(LOCAL_CRATE),
2470 is_proc_macro_crate: false,
2471 is_stub: true,
2472 });
2473 header.position.get()
2474 })
2475 }
2476
2477 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
2478
2479 let dep_node = tcx.metadata_dep_node();
2480
2481 if tcx.dep_graph.is_fully_enabled()
2483 && let work_product_id = WorkProductId::from_cgu_name("metadata")
2484 && let Some(work_product) = tcx.dep_graph.previous_work_product(&work_product_id)
2485 && tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some()
2486 {
2487 let saved_path = &work_product.saved_files["rmeta"];
2488 let incr_comp_session_dir = &tcx.incr_comp_session.unwrap().session_directory;
2489 let source_file_in_incr_dir = &incr_comp_session_dir.join(saved_path);
2490 debug!("copying preexisting metadata from {source_file_in_incr_dir:?} to {path:?}");
2491 match rustc_fs_util::link_or_copy(&source_file_in_incr_dir, path) {
2492 Ok(_) => {}
2493 Err(err) => tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
2494 };
2495 return;
2496 };
2497
2498 if tcx.sess.opts.jobs.frontend.is_some() {
2499 par_join(
2503 || prefetch_mir(tcx),
2504 || {
2505 let _ = tcx.exported_non_generic_symbols(LOCAL_CRATE);
2506 let _ = tcx.exported_generic_symbols(LOCAL_CRATE);
2507 },
2508 );
2509 }
2510
2511 tcx.dep_graph.with_task(
2514 dep_node,
2515 tcx,
2516 || {
2517 with_encode_metadata_header(tcx, path, |ecx| {
2518 let root = ecx.encode_crate_root();
2521
2522 ecx.opaque.flush();
2524 tcx.prof.artifact_size(
2526 "crate_metadata",
2527 "crate_metadata",
2528 ecx.opaque.file().metadata().unwrap().len(),
2529 );
2530
2531 root.position.get()
2532 })
2533 },
2534 None,
2535 );
2536}
2537
2538fn with_encode_metadata_header(
2539 tcx: TyCtxt<'_>,
2540 path: &Path,
2541 f: impl FnOnce(&mut EncodeContext<'_, '_>) -> usize,
2542) {
2543 let mut encoder = opaque::FileEncoder::new(path)
2544 .unwrap_or_else(|err| tcx.dcx().emit_fatal(FailCreateFileEncoder { err }));
2545 encoder.emit_raw_bytes(METADATA_HEADER);
2546
2547 encoder.emit_raw_bytes(&0u64.to_le_bytes());
2549
2550 let source_map_files = tcx.sess.source_map().files();
2551 let source_file_cache = (Arc::clone(&source_map_files[0]), 0);
2552 let required_source_files = Some(FxIndexSet::default());
2553 drop(source_map_files);
2554
2555 let hygiene_ctxt = HygieneEncodeContext::default();
2556
2557 let mut ecx = EncodeContext {
2558 opaque: encoder,
2559 tcx,
2560 feat: tcx.features(),
2561 tables: Default::default(),
2562 lazy_state: LazyState::NoNode,
2563 span_shorthands: Default::default(),
2564 type_shorthands: Default::default(),
2565 predicate_shorthands: Default::default(),
2566 source_file_cache,
2567 interpret_allocs: Default::default(),
2568 required_source_files,
2569 is_proc_macro: tcx.crate_types().contains(&CrateType::ProcMacro),
2570 hygiene_ctxt: &hygiene_ctxt,
2571 symbol_index_table: Default::default(),
2572 };
2573
2574 rustc_version(tcx.sess.cfg_version).encode(&mut ecx);
2576
2577 let root_position = f(&mut ecx);
2578
2579 if let Err((path, err)) = ecx.opaque.finish() {
2583 tcx.dcx().emit_fatal(FailWriteFile { path: &path, err });
2584 }
2585
2586 let file = ecx.opaque.file();
2587 if let Err(err) = encode_root_position(file, root_position) {
2588 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2589 }
2590}
2591
2592fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Error> {
2593 let pos_before_seek = file.stream_position().unwrap();
2595
2596 let header = METADATA_HEADER.len();
2598 file.seek(std::io::SeekFrom::Start(header as u64))?;
2599 file.write_all(&pos.to_le_bytes())?;
2600
2601 file.seek(std::io::SeekFrom::Start(pos_before_seek))?;
2603 Ok(())
2604}
2605
2606pub(crate) fn provide(providers: &mut Providers) {
2607 *providers = Providers {
2608 doc_link_resolutions: |tcx, def_id| {
2609 tcx.resolutions(())
2610 .doc_link_resolutions
2611 .get(&def_id)
2612 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("no resolutions for a doc link"))span_bug!(tcx.def_span(def_id), "no resolutions for a doc link"))
2613 },
2614 doc_link_traits_in_scope: |tcx, def_id| {
2615 tcx.resolutions(()).doc_link_traits_in_scope.get(&def_id).unwrap_or_else(|| {
2616 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("no traits in scope for a doc link"))span_bug!(tcx.def_span(def_id), "no traits in scope for a doc link")
2617 })
2618 },
2619
2620 ..*providers
2621 }
2622}
2623
2624pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String {
2652 let value = body.value;
2653
2654 #[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for Classification {
#[inline]
fn eq(&self, other: &Classification) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Classification {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq)]
2655 enum Classification {
2656 Literal,
2657 Simple,
2658 Complex,
2659 }
2660
2661 use Classification::*;
2662
2663 fn classify(expr: &hir::Expr<'_>) -> Classification {
2664 match &expr.kind {
2665 hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
2666 if #[allow(non_exhaustive_omitted_patterns)] match expr.kind {
hir::ExprKind::Lit(_) => true,
_ => false,
}matches!(expr.kind, hir::ExprKind::Lit(_)) { Literal } else { Complex }
2667 }
2668 hir::ExprKind::Lit(_) => Literal,
2669 hir::ExprKind::Tup([]) => Simple,
2670 hir::ExprKind::Block(hir::Block { stmts: [], expr: Some(expr), .. }, _) => {
2671 if classify(expr) == Complex { Complex } else { Simple }
2672 }
2673 hir::ExprKind::Path(hir::QPath::Resolved(_, hir::Path { segments, .. })) => {
2678 if segments.iter().all(|segment| segment.args.is_none()) { Simple } else { Complex }
2679 }
2680 hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => Simple,
2683 _ => Complex,
2684 }
2685 }
2686
2687 match classify(value) {
2688 Literal
2698 if !value.span.from_expansion()
2699 && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) =>
2700 {
2701 snippet
2702 }
2703
2704 Literal | Simple => id_to_string(&tcx, body.id().hir_id),
2707
2708 Complex => {
2712 if tcx.def_kind(def_id) == DefKind::AnonConst {
2713 "{ _ }".to_owned()
2714 } else {
2715 "_".to_owned()
2716 }
2717 }
2718 }
2719}