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