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, Ie, Id, T> Encodable<EncodeContext<'a, 'tcx>> for LazyTable<Ie, Id, 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_some_lazy {
409 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
410 let value = $value;
411 let lazy = $self.lazy(value);
412 $self.$tables.$table.set_some($def_id.index, lazy);
413 }};
414}
415
416macro_rules! record_some {
417 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {
418 $self.$tables.$table.set_some($def_id.index, $value)
419 };
420}
421
422macro_rules! record_value {
423 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {
424 $self.$tables.$table.set($def_id.index, $value)
425 };
426}
427
428macro_rules! record_array {
431 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
432 let value = $value;
433 let lazy = $self.lazy_array(value);
434 $self.$tables.$table.set_some($def_id.index, lazy);
435 }};
436}
437
438macro_rules! record_defaulted_array {
439 ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
440 let value = $value;
441 let lazy = $self.lazy_array(value);
442 $self.$tables.$table.set($def_id.index, lazy);
443 }};
444}
445
446impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
447 fn emit_lazy_distance(&mut self, position: NonZero<usize>) {
448 let pos = position.get();
449 let distance = match self.lazy_state {
450 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"),
451 LazyState::NodeStart(start) => {
452 let start = start.get();
453 if !(pos <= start) {
::core::panicking::panic("assertion failed: pos <= start")
};assert!(pos <= start);
454 start - pos
455 }
456 LazyState::Previous(last_pos) => {
457 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!(
458 last_pos <= position,
459 "make sure that the calls to `lazy*` \
460 are in the same order as the metadata fields",
461 );
462 position.get() - last_pos.get()
463 }
464 };
465 self.lazy_state = LazyState::Previous(NonZero::new(pos).unwrap());
466 self.emit_usize(distance);
467 }
468
469 fn lazy<T: ParameterizedOverTcx, B: Borrow<T::Value<'tcx>>>(&mut self, value: B) -> LazyValue<T>
470 where
471 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
472 {
473 let pos = NonZero::new(self.position()).unwrap();
474
475 {
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);
476 self.lazy_state = LazyState::NodeStart(pos);
477 value.borrow().encode(self);
478 self.lazy_state = LazyState::NoNode;
479
480 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
481
482 LazyValue::from_position(pos)
483 }
484
485 fn lazy_array<T: ParameterizedOverTcx, I: IntoIterator<Item = B>, B: Borrow<T::Value<'tcx>>>(
486 &mut self,
487 values: I,
488 ) -> LazyArray<T>
489 where
490 T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
491 {
492 let pos = NonZero::new(self.position()).unwrap();
493
494 {
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);
495 self.lazy_state = LazyState::NodeStart(pos);
496 let len = values.into_iter().map(|value| value.borrow().encode(self)).count();
497 self.lazy_state = LazyState::NoNode;
498
499 if !(pos.get() <= self.position()) {
::core::panicking::panic("assertion failed: pos.get() <= self.position()")
};assert!(pos.get() <= self.position());
500
501 LazyArray::from_position_and_num_elems(pos, len)
502 }
503
504 fn encode_symbol_or_byte_symbol(
505 &mut self,
506 index: u32,
507 emit_str_or_byte_str: impl Fn(&mut Self),
508 ) {
509 if Symbol::is_predefined(index) {
511 self.opaque.emit_u8(SYMBOL_PREDEFINED);
512 self.opaque.emit_u32(index);
513 } else {
514 match self.symbol_index_table.entry(index) {
516 Entry::Vacant(o) => {
517 self.opaque.emit_u8(SYMBOL_STR);
518 let pos = self.opaque.position();
519 o.insert(pos);
520 emit_str_or_byte_str(self);
521 }
522 Entry::Occupied(o) => {
523 let x = *o.get();
524 self.emit_u8(SYMBOL_OFFSET);
525 self.emit_usize(x);
526 }
527 }
528 }
529 }
530
531 fn encode_def_path_table(&mut self) {
532 let defs = self.tcx.definitions();
533 if self.is_proc_macro {
534 for def_id in std::iter::once(CRATE_DEF_ID)
535 .chain(self.tcx.resolutions(()).proc_macros.iter().copied())
536 {
537 let def_key = defs.def_key(def_id);
538 let def_path_hash = defs.def_path_hash(def_id);
539 let def_id = def_id.to_def_id();
540
541 {
let value = def_key;
let lazy = self.lazy(value);
self.tables.def_keys.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_keys[def_id] <- def_key);
542 self.tables.def_path_hashes.set(def_id.index,
def_path_hash.local_hash().as_u64())record_value!(self.tables.def_path_hashes[def_id] <- def_path_hash.local_hash().as_u64())
543 }
544 } else {
545 for (def_index, def_key, def_path_hash) in defs.enumerated_keys_and_path_hashes() {
546 let def_id = LocalDefId { local_def_index: def_index }.to_def_id();
547 {
let value = def_key;
let lazy = self.lazy(value);
self.tables.def_keys.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_keys[def_id] <- def_key);
548 self.tables.def_path_hashes.set(def_id.index,
def_path_hash.local_hash().as_u64())record_value!(self.tables.def_path_hashes[def_id] <- def_path_hash.local_hash().as_u64())
549 }
550 }
551 }
552
553 fn encode_def_path_hash_map(&mut self) -> LazyValue<DefPathHashMapRef<'static>> {
554 self.lazy(DefPathHashMapRef::BorrowedFromTcx(self.tcx.def_path_hash_to_def_index_map()))
555 }
556
557 fn encode_source_map(
558 &mut self,
559 ) -> LazyTable<u32, u32, Option<LazyValue<rustc_span::SourceFile>>> {
560 let source_map = self.tcx.sess.source_map();
561 let all_source_files = source_map.files();
562
563 let required_source_files = self.required_source_files.take().unwrap();
567
568 let mut adapted = TableBuilder::default();
569
570 let local_crate_stable_id = self.tcx.stable_crate_id(LOCAL_CRATE);
571
572 for (on_disk_index, &source_file_index) in required_source_files.iter().enumerate() {
577 let source_file = &all_source_files[source_file_index];
578 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);
580
581 let mut adapted_source_file = (**source_file).clone();
589
590 match source_file.name {
591 FileName::Real(ref original_file_name) => {
592 let mut adapted_file_name = original_file_name.clone();
593 adapted_file_name.update_for_crate_metadata();
594 adapted_source_file.name = FileName::Real(adapted_file_name);
595 }
596 _ => {
597 }
599 };
600
601 if self.is_proc_macro {
608 adapted_source_file.cnum = LOCAL_CRATE;
609 }
610
611 adapted_source_file.stable_id = StableSourceFileId::from_filename_for_export(
615 &adapted_source_file.name,
616 local_crate_stable_id,
617 );
618
619 let on_disk_index: u32 =
620 on_disk_index.try_into().expect("cannot export more than U32_MAX files");
621 adapted.set_some(on_disk_index, self.lazy(adapted_source_file));
622 }
623
624 adapted.encode(&mut self.opaque)
625 }
626
627 fn encode_crate_root(&mut self) -> (LazyValue<CrateRoot>, LazyValue<CrateRootUnhashed>) {
628 let tcx = self.tcx;
629 let mut stats: Vec<(&'static str, usize)> = Vec::with_capacity(32);
630
631 macro_rules! stat {
632 ($label:literal, $f:expr) => {{
633 let orig_pos = self.position();
634 let res = $f();
635 stats.push(($label, self.position() - orig_pos));
636 res
637 }};
638 }
639
640 stats.push(("preamble", self.position()));
642
643 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
644 .encode_externally_implementable_items());
645
646 let (crate_deps, dylib_dependency_formats) =
647 {
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()));
648
649 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());
650
651 let stability_implications =
652 {
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());
653
654 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", || {
655 (self.encode_lang_items(), self.encode_lang_items_missing())
656 });
657
658 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());
659
660 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());
661
662 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());
663
664 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());
665
666 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());
667
668 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());
669
670 _ = {
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());
671
672 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());
674
675 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());
677
678 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());
679
680 _ = {
let orig_pos = self.position();
let res = (|| self.encode_mir())();
stats.push(("mir", self.position() - orig_pos));
res
}stat!("mir", || self.encode_mir());
681
682 _ = {
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());
683
684 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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:687",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(687u32),
::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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:695",
"rustc_metadata::rmeta::encoder", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(695u32),
::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", || {
685 let mut interpret_alloc_index = Vec::new();
686 let mut n = 0;
687 trace!("beginning to encode alloc ids");
688 loop {
689 let new_n = self.interpret_allocs.len();
690 if n == new_n {
692 break;
694 }
695 trace!("encoding {} further alloc ids", new_n - n);
696 for idx in n..new_n {
697 let id = self.interpret_allocs[idx];
698 let pos = self.position() as u64;
699 interpret_alloc_index.push(pos);
700 interpret::specialized_encode_alloc_id(self, tcx, id);
701 }
702 n = new_n;
703 }
704 self.lazy_array(interpret_alloc_index)
705 });
706
707 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());
711
712 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));
713
714 let debugger_visualizers =
715 {
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());
716
717 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());
718
719 let stable_order_of_exportable_impls =
720 {
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());
721
722 let (exported_non_generic_symbols, exported_generic_symbols) =
724 {
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", || {
725 (
726 self.encode_exported_symbols(tcx.exported_non_generic_symbols(LOCAL_CRATE)),
727 self.encode_exported_symbols(tcx.exported_generic_symbols(LOCAL_CRATE)),
728 )
729 });
730
731 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());
738
739 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());
740
741 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());
744 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());
745 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
746 .encode_enabled_denied_partial_mitigations());
747
748 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", || {
749 let attrs = tcx.hir_krate_attrs();
750 self.lazy(CrateRoot {
751 header: CrateHeader {
752 name: tcx.crate_name(LOCAL_CRATE),
753 triple: tcx.sess.opts.target_triple.clone(),
754 is_proc_macro_crate: proc_macro_data.is_some(),
755 is_stub: false,
756 },
757
758 stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
759 required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
760 panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
761 edition: tcx.sess.edition(),
762 has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
763 has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE),
764 has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
765 has_default_lib_allocator: find_attr!(attrs, DefaultLibAllocator),
766 externally_implementable_items,
767 proc_macro_data,
768 debugger_visualizers,
769 compiler_builtins: find_attr!(attrs, CompilerBuiltins),
770 needs_allocator: find_attr!(attrs, NeedsAllocator),
771 needs_panic_runtime: find_attr!(attrs, NeedsPanicRuntime),
772 no_builtins: find_attr!(attrs, NoBuiltins),
773 panic_runtime: find_attr!(attrs, PanicRuntime),
774 profiler_runtime: find_attr!(attrs, ProfilerRuntime),
775 symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
776
777 crate_deps,
778 dylib_dependency_formats,
779 lib_features,
780 stability_implications,
781 lang_items,
782 diagnostic_items,
783 canonical_symbols,
784 fake_doc_items,
785 lang_items_missing,
786 stripped_cfg_items,
787 native_libraries,
788 foreign_modules,
789 source_map,
790 target_modifiers,
791 denied_partial_mitigations,
792 traits,
793 impls,
794 incoherent_impls,
795 exportable_items,
796 stable_order_of_exportable_impls,
797 exported_non_generic_symbols,
798 exported_generic_symbols,
799 interpret_alloc_index,
800 tables,
801 syntax_contexts,
802 expn_data,
803 expn_hashes,
804 def_path_hash_map,
805 specialization_enabled_in: tcx.specialization_enabled_in(LOCAL_CRATE),
806 })
807 });
808
809 let hash = if tcx.sess.opts.unstable_opts.metadata_crate_hash {
813 self.opaque.flush();
814 Svh::new(Fingerprint::from_le_bytes(
815 self.metadata_hasher.lock().unwrap().finish_128().to_le_bytes(),
816 ))
817 } else {
818 tcx.crate_hash(LOCAL_CRATE)
819 };
820 tcx.untracked().local_crate_hash.set(hash).expect("local_crate_hash set twice");
821
822 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", || {
823 let mut dep_extra_filenames = IndexVec::from_elem_n(String::new(), 1);
826 if !self.is_proc_macro {
827 for &cnum in self.tcx.crates(()).iter() {
828 let idx = dep_extra_filenames.push(self.tcx.extra_filename(cnum).to_owned());
829 assert_eq!(idx, cnum, "dep_extra_filenames must be indexed by CrateNum");
830 }
831 }
832
833 self.lazy(CrateRootUnhashed {
834 extra_filename: self.tcx.sess.opts.cg.extra_filename.clone(),
835 dep_extra_filenames,
836 })
837 });
838
839 let total_bytes = self.position();
840
841 let computed_total_bytes: usize = stats.iter().map(|(_, size)| size).sum();
842 {
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);
843
844 if tcx.sess.opts.unstable_opts.meta_stats {
845 use std::fmt::Write;
846
847 self.opaque.flush();
848
849 let pos_before_rewind = self.opaque.file().stream_position().unwrap();
851 let mut zero_bytes = 0;
852 self.opaque.file().rewind().unwrap();
853 let file = std::io::BufReader::new(self.opaque.file());
854 for e in file.bytes() {
855 if e.unwrap() == 0 {
856 zero_bytes += 1;
857 }
858 }
859 {
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);
860
861 stats.sort_by_key(|&(_, usize)| usize);
862 stats.reverse(); let prefix = "meta-stats";
865 let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
866
867 let section_w = 23;
868 let size_w = 10;
869 let banner_w = 64;
870
871 let mut s = String::new();
877 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
878 _ = 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));
879 _ = 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");
880 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
881 for (label, size) in stats {
882 _ = 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!(
883 s,
884 "{prefix} {:<section_w$}{:>size_w$} ({:4.1}%)",
885 label,
886 usize_with_underscores(size),
887 perc(size)
888 );
889 }
890 _ = s.write_fmt(format_args!("{1} {0}\n", "-".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "-".repeat(banner_w));
891 _ = 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!(
892 s,
893 "{prefix} {:<section_w$}{:>size_w$} (of which {:.1}% are zero bytes)",
894 "Total",
895 usize_with_underscores(total_bytes),
896 perc(zero_bytes)
897 );
898 _ = s.write_fmt(format_args!("{1} {0}\n", "=".repeat(banner_w), prefix))writeln!(s, "{prefix} {}", "=".repeat(banner_w));
899 { ::std::io::_eprint(format_args!("{0}", s)); };eprint!("{s}");
900 }
901
902 (root, unhashed)
903 }
904}
905
906struct AnalyzeAttrState {
907 is_exported: bool,
908 is_doc_hidden: bool,
909}
910
911#[inline]
921fn analyze_attr(attr: &rustc_attr_ir::Attribute, state: &mut AnalyzeAttrState) -> bool {
922 let mut should_encode = false;
923 if let rustc_attr_ir::Attribute::Parsed(p) = attr
924 && p.encode_cross_crate() == EncodeCrossCrate::No
925 {
926 } else if let Some(name) = attr.name()
928 && [sym::warn, sym::allow, sym::expect, sym::forbid, sym::deny].contains(&name)
929 {
930 } else if let rustc_attr_ir::Attribute::Parsed(AttributeKind::DocComment { .. }) = attr {
933 if state.is_exported {
937 should_encode = true;
938 }
939 } else if let rustc_attr_ir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
940 should_encode = true;
941 if d.hidden.is_some() {
942 state.is_doc_hidden = true;
943 }
944 } else {
945 should_encode = true;
946 }
947 should_encode
948}
949
950fn should_encode_span(def_kind: DefKind) -> bool {
951 match def_kind {
952 DefKind::Mod
953 | DefKind::Struct
954 | DefKind::Union
955 | DefKind::Enum
956 | DefKind::Variant
957 | DefKind::Trait
958 | DefKind::TyAlias
959 | DefKind::ForeignTy
960 | DefKind::TraitAlias
961 | DefKind::AssocTy
962 | DefKind::TyParam
963 | DefKind::ConstParam
964 | DefKind::LifetimeParam
965 | DefKind::Fn
966 | DefKind::Const
967 | DefKind::Static { .. }
968 | DefKind::Ctor(..)
969 | DefKind::AssocFn
970 | DefKind::AssocConst
971 | DefKind::Macro(_)
972 | DefKind::ExternCrate
973 | DefKind::Use
974 | DefKind::AnonConst
975 | DefKind::OpaqueTy
976 | DefKind::Field
977 | DefKind::Impl { .. }
978 | DefKind::Closure
979 | DefKind::SyntheticCoroutineBody => true,
980 DefKind::ForeignMod | DefKind::GlobalAsm | DefKind::TestBinderConstraints => false,
981 }
982}
983
984fn should_encode_attrs(def_kind: DefKind) -> bool {
985 match def_kind {
986 DefKind::Mod
987 | DefKind::Struct
988 | DefKind::Union
989 | DefKind::Enum
990 | DefKind::Variant
991 | DefKind::Trait
992 | DefKind::TyAlias
993 | DefKind::ForeignTy
994 | DefKind::TraitAlias
995 | DefKind::AssocTy
996 | DefKind::Fn
997 | DefKind::Const
998 | DefKind::Static { nested: false, .. }
999 | DefKind::AssocFn
1000 | DefKind::AssocConst
1001 | DefKind::Macro(_)
1002 | DefKind::Field
1003 | DefKind::ConstParam
1004 | DefKind::Impl { .. } => true,
1005 DefKind::Use => true,
1009 DefKind::Closure => true,
1014 DefKind::SyntheticCoroutineBody => false,
1015 DefKind::TyParam
1016 | DefKind::Ctor(..)
1017 | DefKind::ExternCrate
1018 | DefKind::ForeignMod
1019 | DefKind::AnonConst
1020 | DefKind::OpaqueTy
1021 | DefKind::LifetimeParam
1022 | DefKind::Static { nested: true, .. }
1023 | DefKind::GlobalAsm
1024 | DefKind::TestBinderConstraints => false,
1025 }
1026}
1027
1028fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
1029 match def_kind {
1030 DefKind::Mod
1031 | DefKind::Struct
1032 | DefKind::Union
1033 | DefKind::Enum
1034 | DefKind::Variant
1035 | DefKind::Trait
1036 | DefKind::Impl { .. } => true,
1037 DefKind::TyAlias
1038 | DefKind::ForeignTy
1039 | DefKind::TraitAlias
1040 | DefKind::AssocTy
1041 | DefKind::TyParam
1042 | DefKind::Fn
1043 | DefKind::Const
1044 | DefKind::ConstParam
1045 | DefKind::Static { .. }
1046 | DefKind::Ctor(..)
1047 | DefKind::AssocFn
1048 | DefKind::AssocConst
1049 | DefKind::Macro(_)
1050 | DefKind::ExternCrate
1051 | DefKind::Use
1052 | DefKind::ForeignMod
1053 | DefKind::AnonConst
1054 | DefKind::OpaqueTy
1055 | DefKind::Field
1056 | DefKind::LifetimeParam
1057 | DefKind::GlobalAsm
1058 | DefKind::Closure
1059 | DefKind::SyntheticCoroutineBody
1060 | DefKind::TestBinderConstraints => false,
1061 }
1062}
1063
1064fn should_encode_visibility(def_kind: DefKind) -> bool {
1065 match def_kind {
1066 DefKind::Mod
1067 | DefKind::Struct
1068 | DefKind::Union
1069 | DefKind::Enum
1070 | DefKind::Variant
1071 | DefKind::Trait
1072 | DefKind::TyAlias
1073 | DefKind::ForeignTy
1074 | DefKind::TraitAlias
1075 | DefKind::AssocTy
1076 | DefKind::Fn
1077 | DefKind::Const
1078 | DefKind::Static { nested: false, .. }
1079 | DefKind::Ctor(..)
1080 | DefKind::AssocFn
1081 | DefKind::AssocConst
1082 | DefKind::Macro(..)
1083 | DefKind::Field => true,
1084 DefKind::Use
1085 | DefKind::ForeignMod
1086 | DefKind::TyParam
1087 | DefKind::ConstParam
1088 | DefKind::LifetimeParam
1089 | DefKind::AnonConst
1090 | DefKind::Static { nested: true, .. }
1091 | DefKind::OpaqueTy
1092 | DefKind::GlobalAsm
1093 | DefKind::Impl { .. }
1094 | DefKind::Closure
1095 | DefKind::ExternCrate
1096 | DefKind::SyntheticCoroutineBody
1097 | DefKind::TestBinderConstraints => false,
1098 }
1099}
1100
1101fn should_encode_stability(def_kind: DefKind) -> bool {
1102 match def_kind {
1103 DefKind::Mod
1104 | DefKind::Ctor(..)
1105 | DefKind::Variant
1106 | DefKind::Field
1107 | DefKind::Struct
1108 | DefKind::AssocTy
1109 | DefKind::AssocFn
1110 | DefKind::AssocConst
1111 | DefKind::TyParam
1112 | DefKind::ConstParam
1113 | DefKind::Static { .. }
1114 | DefKind::Const
1115 | DefKind::Fn
1116 | DefKind::ForeignMod
1117 | DefKind::TyAlias
1118 | DefKind::OpaqueTy
1119 | DefKind::Enum
1120 | DefKind::Union
1121 | DefKind::Impl { .. }
1122 | DefKind::Trait
1123 | DefKind::TraitAlias
1124 | DefKind::Macro(..)
1125 | DefKind::ForeignTy => true,
1126 DefKind::Use
1127 | DefKind::LifetimeParam
1128 | DefKind::AnonConst
1129 | DefKind::GlobalAsm
1130 | DefKind::Closure
1131 | DefKind::ExternCrate
1132 | DefKind::SyntheticCoroutineBody
1133 | DefKind::TestBinderConstraints => false,
1134 }
1135}
1136
1137fn should_encode_mir(
1158 tcx: TyCtxt<'_>,
1159 reachable_set: &LocalDefIdSet,
1160 def_id: LocalDefId,
1161) -> (bool, bool) {
1162 match tcx.def_kind(def_id) {
1163 DefKind::Ctor(_, _) => (true, false),
1165 DefKind::AnonConst | DefKind::AssocConst | DefKind::Const => (true, false),
1167 DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
1169 DefKind::SyntheticCoroutineBody => (false, true),
1170 DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
1172 let opt = tcx.sess.opts.unstable_opts.always_encode_mir
1173 || (tcx.sess.opts.output_types.should_codegen()
1174 && reachable_set.contains(&def_id)
1175 && (tcx.generics_of(def_id).requires_monomorphization(tcx)
1176 || tcx.cross_crate_inlinable(def_id)));
1177 let opt =
1179 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 });
1180 let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
1182 (is_const_fn, opt)
1183 }
1184 _ => (false, false),
1186 }
1187}
1188
1189fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
1190 match def_kind {
1191 DefKind::Struct
1192 | DefKind::Union
1193 | DefKind::Enum
1194 | DefKind::OpaqueTy
1195 | DefKind::Fn
1196 | DefKind::Ctor(..)
1197 | DefKind::AssocFn => true,
1198 DefKind::AssocTy => {
1199 #[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 { .. }))
1201 }
1202 DefKind::Mod
1203 | DefKind::Variant
1204 | DefKind::Field
1205 | DefKind::AssocConst
1206 | DefKind::TyParam
1207 | DefKind::ConstParam
1208 | DefKind::Static { .. }
1209 | DefKind::Const
1210 | DefKind::ForeignMod
1211 | DefKind::TyAlias
1212 | DefKind::Impl { .. }
1213 | DefKind::Trait
1214 | DefKind::TraitAlias
1215 | DefKind::Macro(..)
1216 | DefKind::ForeignTy
1217 | DefKind::Use
1218 | DefKind::LifetimeParam
1219 | DefKind::AnonConst
1220 | DefKind::GlobalAsm
1221 | DefKind::Closure
1222 | DefKind::ExternCrate
1223 | DefKind::SyntheticCoroutineBody
1224 | DefKind::TestBinderConstraints => false,
1225 }
1226}
1227
1228fn should_encode_generics(def_kind: DefKind) -> bool {
1229 match def_kind {
1230 DefKind::Struct
1231 | DefKind::Union
1232 | DefKind::Enum
1233 | DefKind::Variant
1234 | DefKind::Trait
1235 | DefKind::TyAlias
1236 | DefKind::ForeignTy
1237 | DefKind::TraitAlias
1238 | DefKind::AssocTy
1239 | DefKind::Fn
1240 | DefKind::Const
1241 | DefKind::Static { .. }
1242 | DefKind::Ctor(..)
1243 | DefKind::AssocFn
1244 | DefKind::AssocConst
1245 | DefKind::AnonConst
1246 | DefKind::OpaqueTy
1247 | DefKind::Impl { .. }
1248 | DefKind::Field
1249 | DefKind::TyParam
1250 | DefKind::Closure
1251 | DefKind::SyntheticCoroutineBody => true,
1252 DefKind::Mod
1253 | DefKind::ForeignMod
1254 | DefKind::ConstParam
1255 | DefKind::Macro(..)
1256 | DefKind::Use
1257 | DefKind::LifetimeParam
1258 | DefKind::GlobalAsm
1259 | DefKind::ExternCrate
1260 | DefKind::TestBinderConstraints => false,
1261 }
1262}
1263
1264fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> bool {
1265 match def_kind {
1266 DefKind::Struct
1267 | DefKind::Union
1268 | DefKind::Enum
1269 | DefKind::Variant
1270 | DefKind::Ctor(..)
1271 | DefKind::Field
1272 | DefKind::Fn
1273 | DefKind::Const
1274 | DefKind::Static { nested: false, .. }
1275 | DefKind::TyAlias
1276 | DefKind::ForeignTy
1277 | DefKind::Impl { .. }
1278 | DefKind::AssocFn
1279 | DefKind::AssocConst
1280 | DefKind::Closure
1281 | DefKind::ConstParam
1282 | DefKind::AnonConst
1283 | DefKind::SyntheticCoroutineBody => true,
1284
1285 DefKind::OpaqueTy => {
1286 let origin = tcx.local_opaque_ty_origin(def_id);
1287 if let hir::OpaqueTyOrigin::FnReturn { parent, .. }
1288 | hir::OpaqueTyOrigin::AsyncFn { parent, .. } = origin
1289 && let hir::Node::TraitItem(trait_item) = tcx.hir_node_by_def_id(parent)
1290 && let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
1291 {
1292 false
1293 } else {
1294 true
1295 }
1296 }
1297
1298 DefKind::AssocTy => {
1299 let assoc_item = tcx.associated_item(def_id);
1300 match assoc_item.container {
1301 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => true,
1302 ty::AssocContainer::Trait => assoc_item.defaultness(tcx).has_value(),
1303 }
1304 }
1305 DefKind::TyParam => {
1306 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!() };
1307 let hir::GenericParamKind::Type { default, .. } = param.kind else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!() };
1308 default.is_some()
1309 }
1310
1311 DefKind::Trait
1312 | DefKind::TraitAlias
1313 | DefKind::Mod
1314 | DefKind::ForeignMod
1315 | DefKind::Macro(..)
1316 | DefKind::Static { nested: true, .. }
1317 | DefKind::Use
1318 | DefKind::LifetimeParam
1319 | DefKind::GlobalAsm
1320 | DefKind::ExternCrate
1321 | DefKind::TestBinderConstraints => false,
1322 }
1323}
1324
1325fn should_encode_fn_sig(def_kind: DefKind) -> bool {
1326 match def_kind {
1327 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) => true,
1328
1329 DefKind::Struct
1330 | DefKind::Union
1331 | DefKind::Enum
1332 | DefKind::Variant
1333 | DefKind::Field
1334 | DefKind::Const
1335 | DefKind::Static { .. }
1336 | DefKind::Ctor(..)
1337 | DefKind::TyAlias
1338 | DefKind::OpaqueTy
1339 | DefKind::ForeignTy
1340 | DefKind::Impl { .. }
1341 | DefKind::AssocConst
1342 | DefKind::Closure
1343 | DefKind::ConstParam
1344 | DefKind::AnonConst
1345 | DefKind::AssocTy
1346 | DefKind::TyParam
1347 | DefKind::Trait
1348 | DefKind::TraitAlias
1349 | DefKind::Mod
1350 | DefKind::ForeignMod
1351 | DefKind::Macro(..)
1352 | DefKind::Use
1353 | DefKind::LifetimeParam
1354 | DefKind::GlobalAsm
1355 | DefKind::ExternCrate
1356 | DefKind::SyntheticCoroutineBody
1357 | DefKind::TestBinderConstraints => false,
1358 }
1359}
1360
1361fn should_encode_constness(def_kind: DefKind) -> bool {
1362 match def_kind {
1363 DefKind::Fn
1364 | DefKind::AssocFn
1365 | DefKind::Closure
1366 | DefKind::Ctor(_, CtorKind::Fn)
1367 | DefKind::Impl { of_trait: false } => true,
1368
1369 DefKind::Struct
1370 | DefKind::Union
1371 | DefKind::Enum
1372 | DefKind::Field
1373 | DefKind::Const
1374 | DefKind::AssocConst
1375 | DefKind::AnonConst
1376 | DefKind::Static { .. }
1377 | DefKind::TyAlias
1378 | DefKind::OpaqueTy
1379 | DefKind::Impl { .. }
1380 | DefKind::ForeignTy
1381 | DefKind::ConstParam
1382 | DefKind::AssocTy
1383 | DefKind::TyParam
1384 | DefKind::Trait
1385 | DefKind::TraitAlias
1386 | DefKind::Mod
1387 | DefKind::ForeignMod
1388 | DefKind::Macro(..)
1389 | DefKind::Use
1390 | DefKind::LifetimeParam
1391 | DefKind::GlobalAsm
1392 | DefKind::ExternCrate
1393 | DefKind::Ctor(_, CtorKind::Const)
1394 | DefKind::Variant
1395 | DefKind::SyntheticCoroutineBody
1396 | DefKind::TestBinderConstraints => false,
1397 }
1398}
1399
1400fn should_encode_const(def_kind: DefKind) -> bool {
1401 match def_kind {
1402 DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => true,
1404
1405 DefKind::Struct
1406 | DefKind::Union
1407 | DefKind::Enum
1408 | DefKind::Variant
1409 | DefKind::Ctor(..)
1410 | DefKind::Field
1411 | DefKind::Fn
1412 | DefKind::Static { .. }
1413 | DefKind::TyAlias
1414 | DefKind::OpaqueTy
1415 | DefKind::ForeignTy
1416 | DefKind::Impl { .. }
1417 | DefKind::AssocFn
1418 | DefKind::Closure
1419 | DefKind::ConstParam
1420 | DefKind::AssocTy
1421 | DefKind::TyParam
1422 | DefKind::Trait
1423 | DefKind::TraitAlias
1424 | DefKind::Mod
1425 | DefKind::ForeignMod
1426 | DefKind::Macro(..)
1427 | DefKind::Use
1428 | DefKind::LifetimeParam
1429 | DefKind::GlobalAsm
1430 | DefKind::ExternCrate
1431 | DefKind::SyntheticCoroutineBody
1432 | DefKind::TestBinderConstraints => false,
1433 }
1434}
1435
1436impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1437 fn encode_attrs(&mut self, def_id: LocalDefId) {
1438 let tcx = self.tcx;
1439 let mut state = AnalyzeAttrState {
1440 is_exported: tcx.effective_visibilities(()).is_exported(def_id),
1441 is_doc_hidden: false,
1442 };
1443 let attr_iter = tcx
1444 .hir_attrs(tcx.local_def_id_to_hir_id(def_id))
1445 .iter()
1446 .filter(|attr| analyze_attr(*attr, &mut state));
1447
1448 {
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);
1449
1450 let mut attr_flags = AttrFlags::empty();
1451 if state.is_doc_hidden {
1452 attr_flags |= AttrFlags::IS_DOC_HIDDEN;
1453 }
1454
1455 self.tables.attr_flags.set(def_id.to_def_id().index, attr_flags)record_value!(self.tables.attr_flags[def_id.to_def_id()] <- attr_flags)
1456 }
1457
1458 fn encode_def_ids(&mut self) {
1459 self.encode_info_for_mod(CRATE_DEF_ID);
1460
1461 if self.is_proc_macro {
1464 return;
1465 }
1466
1467 let tcx = self.tcx;
1468
1469 for local_id in tcx.iter_local_def_id() {
1470 let def_id = local_id.to_def_id();
1471 let def_kind = tcx.def_kind(local_id);
1472 self.tables.def_kind.set_some(def_id.index, def_kind);record_some!(self.tables.def_kind[def_id] <- def_kind);
1473
1474 if def_kind == DefKind::AnonConst
1480 && #[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!(
1481 tcx.hir_node_by_def_id(local_id),
1482 hir::Node::ConstArg(_)
1483 | hir::Node::Infer(hir::InferArg { kind: hir::InferArgKind::Const, .. })
1484 )
1485 {
1486 continue;
1487 }
1488
1489 if def_kind == DefKind::Field
1490 && let hir::Node::Field(field) = tcx.hir_node_by_def_id(local_id)
1491 && let Some(anon) = field.default
1492 {
1493 {
let value = anon.def_id.to_def_id();
let lazy = self.lazy(value);
self.tables.default_fields.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.default_fields[def_id] <- anon.def_id.to_def_id());
1494 }
1495
1496 if should_encode_span(def_kind) {
1497 let def_span = tcx.def_span(local_id);
1498 {
let value = def_span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_span[def_id] <- def_span);
1499 }
1500 if should_encode_attrs(def_kind) {
1501 self.encode_attrs(local_id);
1502 }
1503 if should_encode_expn_that_defined(def_kind) {
1504 {
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_some_lazy!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
1505 }
1506 if should_encode_span(def_kind)
1507 && let Some(ident_span) = tcx.def_ident_span(def_id)
1508 {
1509 {
let value = ident_span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_ident_span[def_id] <- ident_span);
1510 }
1511 if def_kind.has_codegen_attrs() {
1512 {
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_some_lazy!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
1513 }
1514 if should_encode_visibility(def_kind) {
1515 let vis = self
1516 .tcx
1517 .local_visibility(local_id)
1518 .map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
1519 {
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.visibility[def_id] <- vis);
1520 }
1521 if should_encode_stability(def_kind) {
1522 self.encode_stability(def_id);
1523 self.encode_const_stability(def_id);
1524 self.encode_default_body_stability(def_id);
1525 self.encode_deprecation(def_id);
1526 }
1527 if should_encode_variances(tcx, def_id, def_kind) {
1528 let v = self.tcx.variances_of(def_id);
1529 {
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);
1530 }
1531 if should_encode_fn_sig(def_kind) {
1532 {
let value = tcx.fn_sig(def_id);
let lazy = self.lazy(value);
self.tables.fn_sig.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
1533 }
1534 if should_encode_generics(def_kind) {
1535 let g = tcx.generics_of(def_id);
1536 {
let value = g;
let lazy = self.lazy(value);
self.tables.generics_of.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.generics_of[def_id] <- g);
1537 {
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_some_lazy!(self.tables.explicit_clauses_of[def_id] <- self.tcx.explicit_clauses_of(def_id));
1538 let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
1539 {
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);
1540
1541 for param in &g.own_params {
1542 if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
1543 let default = self.tcx.const_param_default(param.def_id);
1544 {
let value = default;
let lazy = self.lazy(value);
self.tables.const_param_default.set_some(param.def_id.index, lazy);
};record_some_lazy!(self.tables.const_param_default[param.def_id] <- default);
1545 }
1546 }
1547 }
1548 if tcx.is_conditionally_const(def_id) {
1549 {
let value = self.tcx.const_conditions(def_id);
let lazy = self.lazy(value);
self.tables.const_conditions.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.const_conditions[def_id] <- self.tcx.const_conditions(def_id));
1550 }
1551 if should_encode_type(tcx, local_id, def_kind) {
1552 {
let value = self.tcx.type_of(def_id);
let lazy = self.lazy(value);
self.tables.type_of.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
1553 }
1554 if should_encode_constness(def_kind) {
1555 let constness = self.tcx.constness(def_id);
1556 self.tables.constness.set(def_id.index, constness)record_value!(self.tables.constness[def_id] <- constness)
1557 }
1558 if let DefKind::Fn | DefKind::AssocFn = def_kind {
1559 let asyncness = tcx.asyncness(def_id);
1560 self.tables.asyncness.set(def_id.index, asyncness);record_value!(self.tables.asyncness[def_id] <- asyncness);
1561 {
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));
1562 }
1563 if let Some(name) = tcx.intrinsic(def_id) {
1564 {
let value = name;
let lazy = self.lazy(value);
self.tables.intrinsic.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.intrinsic[def_id] <- name);
1565 }
1566 if let DefKind::TyParam | DefKind::Trait = def_kind {
1567 let default = self.tcx.object_lifetime_default(def_id);
1568 {
let value = default;
let lazy = self.lazy(value);
self.tables.object_lifetime_default.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.object_lifetime_default[def_id] <- default);
1569 }
1570 if let DefKind::Trait = def_kind {
1571 {
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1572 {
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] <-
1573 self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1574 {
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] <-
1575 self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1576 let module_children = self.tcx.module_children_local(local_id);
1577 {
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] <-
1578 module_children.iter().map(|child| child.res.def_id().index));
1579 if self.tcx.is_const_trait(def_id) {
1580 {
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]
1581 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1582 }
1583 }
1584 if let DefKind::TraitAlias = def_kind {
1585 {
let value = self.tcx.trait_def(def_id);
let lazy = self.lazy(value);
self.tables.trait_def.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1586 {
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] <-
1587 self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1588 {
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] <-
1589 self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1590 }
1591 if let DefKind::Trait | DefKind::Impl { .. } = def_kind {
1592 let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
1593 {
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] <-
1594 associated_item_def_ids.iter().map(|&def_id| {
1595 assert!(def_id.is_local());
1596 def_id.index
1597 })
1598 );
1599 for &def_id in associated_item_def_ids {
1600 self.encode_info_for_assoc_item(def_id);
1601 }
1602 }
1603 if let DefKind::Closure | DefKind::SyntheticCoroutineBody = def_kind
1604 && let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
1605 {
1606 self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))record_value!(self.tables.coroutine_kind[def_id] <- Some(coroutine_kind))
1607 }
1608 if def_kind == DefKind::Closure
1609 && tcx.type_of(def_id).skip_binder().is_coroutine_closure()
1610 {
1611 let coroutine_for_closure = self.tcx.coroutine_for_closure(def_id);
1612 self.tables.coroutine_for_closure.set_some(def_id.index,
coroutine_for_closure.into());record_some!(self.tables.coroutine_for_closure[def_id] <- coroutine_for_closure.into());
1613
1614 if tcx.needs_coroutine_by_move_body_def_id(coroutine_for_closure) {
1616 let id = self.tcx.coroutine_by_move_body_def_id(coroutine_for_closure);
1617 self.tables.coroutine_by_move_body_def_id.set_some(coroutine_for_closure.index,
id.into())record_some!(
1618 self.tables.coroutine_by_move_body_def_id[coroutine_for_closure] <- id.into()
1619 )
1620 }
1621 }
1622 if let DefKind::Static { .. } = def_kind {
1623 if !self.tcx.is_foreign_item(def_id) {
1624 match self.tcx.eval_static_initializer(def_id) {
1625 Ok(data) => {
1626 {
let value = data;
let lazy = self.lazy(value);
self.tables.eval_static_initializer.set_some(def_id.index, lazy);
}record_some_lazy!(self.tables.eval_static_initializer[def_id] <- data)
1627 }
1628 Err(err) => match err {
1629 interpret::ErrorHandled::Reported(_, _) => {
1630 self.tcx.dcx().delayed_bug(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("eval_static_initializer returned an error in metadata emission"))
})format!(
1631 "eval_static_initializer returned an error in metadata emission"
1632 ));
1633 }
1634 interpret::ErrorHandled::TooGeneric(span) => {
1635 ::rustc_span::macros::bug_impl(Some(span), format_args!("generic static???"),
Location::caller());span_bug!(span, "generic static???");
1636 }
1637 },
1638 };
1639 }
1640 }
1641 if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
1642 self.encode_info_for_adt(local_id);
1643 }
1644 if let DefKind::Mod = def_kind {
1645 self.encode_info_for_mod(local_id);
1646 }
1647 if let DefKind::Macro(_) = def_kind {
1648 self.encode_info_for_macro(local_id);
1649 }
1650 if let DefKind::TyAlias = def_kind {
1651 self.tables.type_alias_is_checked.set(def_id.index,
self.tcx.type_alias_is_checked(def_id));record_value!(self.tables.type_alias_is_checked[def_id] <- self.tcx.type_alias_is_checked(def_id));
1652
1653 if self.tcx.type_alias_is_checked(def_id) {
1654 {
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_some_lazy!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1655 }
1656 }
1657 if let DefKind::OpaqueTy = def_kind {
1658 self.encode_explicit_item_bounds(def_id);
1659 self.encode_explicit_item_self_bounds(def_id);
1660 {
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_some_lazy!(self.tables.opaque_ty_origin[def_id] <- self.tcx.opaque_ty_origin(def_id));
1661 self.encode_precise_capturing_args(def_id);
1662 if tcx.is_conditionally_const(def_id) {
1663 {
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]
1664 <- tcx.explicit_implied_const_bounds(def_id).skip_binder());
1665 }
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_some_lazy!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1667 }
1668 if let DefKind::AssocTy = def_kind {
1669 let assoc_item = tcx.associated_item(def_id);
1670 match assoc_item.container {
1671 ty::AssocContainer::Trait => {
1672 {
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_some_lazy!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1673 }
1674 ty::AssocContainer::InherentImpl => {
1675 {
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_some_lazy!(self.tables.args_known_to_outlive_alias_params[def_id] <- tcx.args_known_to_outlive_alias_params(def_id));
1676 }
1677 ty::AssocContainer::TraitImpl(_) => {}
1678 }
1679 }
1680 if let DefKind::AnonConst = def_kind {
1681 {
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_some_lazy!(self.tables.anon_const_kind[def_id] <- self.tcx.anon_const_kind(def_id));
1682 }
1683 if let DefKind::Const | DefKind::AssocConst = def_kind {
1684 {
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_some_lazy!(self.tables.const_of_item[def_id] <- self.tcx.const_of_item(def_id));
1685 }
1686 if tcx.impl_method_has_trait_impl_trait_tys(def_id)
1687 && let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
1688 {
1689 {
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_some_lazy!(self.tables.collect_return_position_impl_trait_in_trait_tys[def_id] <- table);
1690 }
1691 if let DefKind::Impl { .. } | DefKind::Trait = def_kind {
1692 let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);
1693 {
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_some_lazy!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table);
1694 }
1695 }
1696
1697 for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
1698 {
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| {
1699 assert!(def_id.is_local());
1700 def_id.index
1701 }));
1702 }
1703
1704 for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1705 {
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(def_id.to_def_id().index, lazy);
};record_some_lazy!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1706 }
1707
1708 for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1709 {
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);
1710 }
1711 }
1712
1713 fn encode_externally_implementable_items(&mut self) -> LazyArray<EiiMapEncodedKeyValue> {
1714 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
1715 let externally_implementable_items = self.tcx.externally_implementable_items(LOCAL_CRATE);
1716
1717 self.lazy_array(externally_implementable_items.iter().map(
1718 |(foreign_item, (decl, impls))| {
1719 (
1720 *foreign_item,
1721 (decl.clone(), impls.iter().map(|(impl_did, i)| (*impl_did, *i)).collect()),
1722 )
1723 },
1724 ))
1725 }
1726
1727 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1727u32),
::tracing_core::__macro_support::Option::Some("rustc_metadata::rmeta::encoder"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("local_def_id")
}> =
::tracing::__macro_support::FieldName::new("local_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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))]
1728 fn encode_info_for_adt(&mut self, local_def_id: LocalDefId) {
1729 let def_id = local_def_id.to_def_id();
1730 let tcx = self.tcx;
1731 let adt_def = tcx.adt_def(def_id);
1732 record_some_lazy!(self.tables.repr_options[def_id] <- adt_def.repr());
1733
1734 let params_in_repr = self.tcx.params_in_repr(def_id);
1735 record_some_lazy!(self.tables.params_in_repr[def_id] <- params_in_repr);
1736
1737 if adt_def.is_enum() {
1738 let module_children = tcx.module_children_local(local_def_id);
1739 record_array!(self.tables.module_children_non_reexports[def_id] <-
1740 module_children.iter().map(|child| child.res.def_id().index));
1741 } else {
1742 debug_assert_eq!(adt_def.variants().len(), 1);
1744 debug_assert_eq!(adt_def.non_enum_variant().def_id, def_id);
1745 }
1747
1748 for (idx, variant) in adt_def.variants().iter_enumerated() {
1749 let data = VariantData {
1750 discr: variant.discr,
1751 idx,
1752 ctor: variant.ctor.map(|(kind, def_id)| (kind, def_id.index)),
1753 is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1754 };
1755 record_some_lazy!(self.tables.variant_data[variant.def_id] <- data);
1756
1757 record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
1758 assert!(f.did.is_local());
1759 f.did.index
1760 }));
1761
1762 for field in &variant.fields {
1763 record_value!(self.tables.safety[field.did] <- field.safety);
1764 record_some_lazy!(
1765 self.tables.mut_restriction[field.did] <- field.mut_restriction
1766 );
1767 }
1768
1769 if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
1770 let fn_sig = tcx.fn_sig(ctor_def_id);
1771 record_some_lazy!(self.tables.fn_sig[variant.def_id] <- fn_sig);
1773 }
1774 }
1775
1776 if let Some(destructor) = tcx.adt_destructor(local_def_id) {
1777 record_some_lazy!(self.tables.adt_destructor[def_id] <- destructor);
1778 }
1779
1780 if let Some(destructor) = tcx.adt_async_destructor(local_def_id) {
1781 record_some_lazy!(self.tables.adt_async_destructor[def_id] <- destructor);
1782 }
1783 }
1784
1785 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1785u32),
::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))]
1786 fn encode_info_for_mod(&mut self, local_def_id: LocalDefId) {
1787 let tcx = self.tcx;
1788 let def_id = local_def_id.to_def_id();
1789
1790 if self.is_proc_macro {
1796 record_some_lazy!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
1798 } else {
1799 let module_children = tcx.module_children_local(local_def_id);
1800
1801 record_array!(self.tables.module_children_non_reexports[def_id] <-
1802 module_children.iter().filter(|child| child.reexport_chain.is_empty())
1803 .map(|child| child.res.def_id().index));
1804
1805 record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
1806 module_children.iter().filter(|child| !child.reexport_chain.is_empty()));
1807
1808 let ambig_module_children = tcx
1809 .resolutions(())
1810 .ambig_module_children
1811 .get(&local_def_id)
1812 .map_or_default(|v| &v[..]);
1813 record_defaulted_array!(self.tables.ambig_module_children[def_id] <-
1814 ambig_module_children);
1815 }
1816 }
1817
1818 fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
1819 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:1819",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1819u32),
::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);
1820 let bounds = self.tcx.explicit_item_bounds(def_id).skip_binder();
1821 {
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);
1822 }
1823
1824 fn encode_explicit_item_self_bounds(&mut self, def_id: DefId) {
1825 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:1825",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1825u32),
::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);
1826 let bounds = self.tcx.explicit_item_self_bounds(def_id).skip_binder();
1827 {
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);
1828 }
1829
1830 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1830u32),
::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))]
1831 fn encode_info_for_assoc_item(&mut self, def_id: DefId) {
1832 let tcx = self.tcx;
1833 let item = tcx.associated_item(def_id);
1834
1835 if matches!(item.container, AssocContainer::Trait | AssocContainer::TraitImpl(_)) {
1836 record_value!(self.tables.defaultness[def_id] <- item.defaultness(tcx));
1837 }
1838
1839 record_some_lazy!(self.tables.assoc_container[def_id] <- item.container);
1840
1841 if let AssocContainer::Trait = item.container
1842 && item.is_type()
1843 {
1844 self.encode_explicit_item_bounds(def_id);
1845 self.encode_explicit_item_self_bounds(def_id);
1846 if tcx.is_conditionally_const(def_id) {
1847 record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1848 <- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1849 }
1850 }
1851 if let ty::AssocKind::Type { data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
1852 record_some_lazy!(self.tables.opt_rpitit_info[def_id] <- rpitit_info);
1853 if matches!(rpitit_info, ty::ImplTraitInTraitData::Trait { .. }) {
1854 record_array!(
1855 self.tables.assumed_wf_types_for_rpitit[def_id]
1856 <- self.tcx.assumed_wf_types_for_rpitit(def_id)
1857 );
1858 self.encode_precise_capturing_args(def_id);
1859 }
1860 }
1861 }
1862
1863 fn encode_precise_capturing_args(&mut self, def_id: DefId) {
1864 let Some(precise_capturing_args) = self.tcx.rendered_precise_capturing_args(def_id) else {
1865 return;
1866 };
1867
1868 {
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);
1869 }
1870
1871 fn encode_mir(&mut self) {
1872 if self.is_proc_macro {
1873 return;
1874 }
1875
1876 let tcx = self.tcx;
1877 let reachable_set = tcx.reachable_set(());
1878
1879 let keys_and_jobs = tcx.mir_keys(()).iter().filter_map(|&def_id| {
1880 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
1881 if encode_const || encode_opt { Some((def_id, encode_const, encode_opt)) } else { None }
1882 });
1883 for (def_id, encode_const, encode_opt) in keys_and_jobs {
1884 if true {
if !(encode_const || encode_opt) {
::core::panicking::panic("assertion failed: encode_const || encode_opt")
};
};debug_assert!(encode_const || encode_opt);
1885
1886 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:1886",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1886u32),
::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);
1887 if encode_opt {
1888 {
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_some_lazy!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
1889
1890 self.tables.cross_crate_inlinable.set(def_id.to_def_id().index,
self.tcx.cross_crate_inlinable(def_id));record_value!(self.tables.cross_crate_inlinable[def_id.to_def_id()] <- self.tcx.cross_crate_inlinable(def_id));
1891
1892 {
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_some_lazy!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
1893 <- tcx.closure_saved_names_of_captured_variables(def_id));
1894
1895 if self.tcx.is_coroutine(def_id.to_def_id())
1896 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1897 {
1898 {
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
};record_some_lazy!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1899 }
1900 }
1901 let mut is_trivial = false;
1902 if encode_const {
1903 if let Some((val, ty)) = tcx.trivial_const(def_id) {
1904 is_trivial = true;
1905 {
let value = (val, ty);
let lazy = self.lazy(value);
self.tables.trivial_const.set_some(def_id.to_def_id().index, lazy);
};record_some_lazy!(self.tables.trivial_const[def_id.to_def_id()] <- (val, ty));
1906 } else {
1907 is_trivial = false;
1908 {
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_some_lazy!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
1909 }
1910
1911 let abstract_const = tcx.thir_abstract_const(def_id);
1913 if let Ok(Some(abstract_const)) = abstract_const {
1914 {
let value = abstract_const;
let lazy = self.lazy(value);
self.tables.thir_abstract_const.set_some(def_id.to_def_id().index, lazy);
};record_some_lazy!(self.tables.thir_abstract_const[def_id.to_def_id()] <- abstract_const);
1915 }
1916
1917 if should_encode_const(tcx.def_kind(def_id)) {
1918 let qualifs = tcx.mir_const_qualif(def_id);
1919 {
let value = qualifs;
let lazy = self.lazy(value);
self.tables.mir_const_qualif.set_some(def_id.to_def_id().index, lazy);
};record_some_lazy!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
1920 let body = tcx.hir_maybe_body_owned_by(def_id);
1921 if let Some(body) = body {
1922 let const_data = rendered_const(self.tcx, &body, def_id);
1923 {
let value = const_data;
let lazy = self.lazy(value);
self.tables.rendered_const.set_some(def_id.to_def_id().index, lazy);
};record_some_lazy!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
1924 }
1925 }
1926 }
1927 if !is_trivial {
1928 {
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_some_lazy!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
1929 }
1930
1931 if self.tcx.is_coroutine(def_id.to_def_id())
1932 && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
1933 {
1934 {
let value = witnesses;
let lazy = self.lazy(value);
self.tables.mir_coroutine_witnesses.set_some(def_id.to_def_id().index,
lazy);
};record_some_lazy!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
1935 }
1936 }
1937
1938 if tcx.sess.opts.output_types.should_codegen()
1942 && tcx.sess.opts.optimize != OptLevel::No
1943 && tcx.sess.opts.incremental.is_none()
1944 {
1945 for &local_def_id in tcx.mir_keys(()) {
1946 if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
1947 {
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()] <-
1948 self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
1949 }
1950 }
1951 }
1952 }
1953
1954 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1954u32),
::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))]
1955 fn encode_stability(&mut self, def_id: DefId) {
1956 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1959 if let Some(stab) = self.tcx.lookup_stability(def_id) {
1960 record_some_lazy!(self.tables.lookup_stability[def_id] <- stab)
1961 }
1962 }
1963 }
1964
1965 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1965u32),
::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))]
1966 fn encode_const_stability(&mut self, def_id: DefId) {
1967 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1970 if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
1971 record_some_lazy!(self.tables.lookup_const_stability[def_id] <- stab)
1972 }
1973 }
1974 }
1975
1976 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1976u32),
::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))]
1977 fn encode_default_body_stability(&mut self, def_id: DefId) {
1978 if self.feat.staged_api() || self.tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
1981 if let Some(stab) = self.tcx.lookup_default_body_stability(def_id) {
1982 record_some_lazy!(self.tables.lookup_default_body_stability[def_id] <- stab)
1983 }
1984 }
1985 }
1986
1987 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1987u32),
::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))]
1988 fn encode_deprecation(&mut self, def_id: DefId) {
1989 if let Some(depr) = self.tcx.lookup_deprecation(def_id) {
1990 record_some_lazy!(self.tables.lookup_deprecation_entry[def_id] <- depr);
1991 }
1992 }
1993
1994 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(1994u32),
::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.to_def_id().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))]
1995 fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
1996 let tcx = self.tcx;
1997
1998 let (_, macro_def, _) = tcx.hir_expect_item(def_id).expect_macro();
1999 record_value!(self.tables.is_macro_rules[def_id.to_def_id()] <- macro_def.macro_rules);
2000 record_some_lazy!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
2001 }
2002
2003 fn encode_native_libraries(&mut self) -> LazyArray<NativeLib> {
2004 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2005 let used_libraries = self.tcx.native_libraries(LOCAL_CRATE);
2006 self.lazy_array(used_libraries.iter())
2007 }
2008
2009 fn encode_foreign_modules(&mut self) -> LazyArray<ForeignModule> {
2010 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2011 let foreign_modules = self.tcx.foreign_modules(LOCAL_CRATE);
2012 self.lazy_array(foreign_modules.iter().map(|(_, m)| m).cloned())
2013 }
2014
2015 fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable, ExpnHashTable) {
2016 let mut syntax_contexts: TableBuilder<_, _, _> = Default::default();
2017 let mut expn_data_table: TableBuilder<_, _, _> = Default::default();
2018 let mut expn_hash_table: TableBuilder<_, _, _> = Default::default();
2019
2020 HygieneEncodeContext::encode(
2021 &Rc::clone(&self.hygiene_ctxt),
2022 &mut (&mut *self, &mut syntax_contexts, &mut expn_data_table, &mut expn_hash_table),
2023 |(this, syntax_contexts, _, _), index, ctxt_data| {
2024 syntax_contexts.set_some(index, this.lazy(ctxt_data));
2025 },
2026 |(this, _, expn_data_table, expn_hash_table), index, expn_data, hash| {
2027 if let Some(index) = index.as_local() {
2028 expn_data_table
2029 .set_some(index.as_raw(), this.lazy(expn_data.expect("local expn")));
2030
2031 expn_hash_table.set_some(index.as_raw(), this.lazy(hash));
2032 }
2033 },
2034 );
2035
2036 (
2037 syntax_contexts.encode(&mut self.opaque),
2038 expn_data_table.encode(&mut self.opaque),
2039 expn_hash_table.encode(&mut self.opaque),
2040 )
2041 }
2042
2043 fn encode_proc_macros(&mut self) -> Option<ProcMacroData> {
2044 let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro);
2045 if is_proc_macro {
2046 let tcx = self.tcx;
2047 let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
2048 let stability = tcx.lookup_stability(CRATE_DEF_ID);
2049
2050 self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod);record_some!(self.tables.def_kind[LOCAL_CRATE.as_def_id()] <- DefKind::Mod);
2051 {
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_some_lazy!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
2052 self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
2053 let vis = tcx
2054 .local_visibility(CRATE_DEF_ID)
2055 .map_id(|mod_id| mod_id.to_local_def_id().local_def_index);
2056 {
let value = vis;
let lazy = self.lazy(value);
self.tables.visibility.set_some(LOCAL_CRATE.as_def_id().index, lazy);
};record_some_lazy!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis);
2057 if let Some(stability) = stability {
2058 {
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
};record_some_lazy!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability);
2059 }
2060 self.encode_deprecation(LOCAL_CRATE.as_def_id());
2061 if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_MOD_ID) {
2062 {
let value = res_map;
let lazy = self.lazy(value);
self.tables.doc_link_resolutions.set_some(LOCAL_CRATE.as_def_id().index,
lazy);
};record_some_lazy!(self.tables.doc_link_resolutions[LOCAL_CRATE.as_def_id()] <- res_map);
2063 }
2064 if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_MOD_ID) {
2065 {
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);
2066 }
2067
2068 let mut macros = ::alloc::vec::Vec::new()vec![];
2069
2070 for &proc_macro in &tcx.resolutions(()).proc_macros {
2074 let id = proc_macro;
2075 let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
2076 let mut name = tcx.hir_name(proc_macro);
2077 let span = tcx.hir_span(proc_macro);
2078 let attrs = tcx.hir_attrs(proc_macro);
2081 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) {
2082 (MacroKind::Bang, ProcMacroKind::Bang { name: name.as_str().to_owned() })
2083 } 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) {
2084 (MacroKind::Attr, ProcMacroKind::Attr { name: name.as_str().to_owned() })
2085 } 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,
2086 ProcMacroDerive { trait_name, helper_attrs } => (trait_name, helper_attrs))
2087 {
2088 name = *trait_name;
2089 (
2090 MacroKind::Derive,
2091 ProcMacroKind::CustomDerive {
2092 trait_name: name.as_str().to_owned(),
2093 attributes: helper_attrs
2094 .iter()
2095 .map(|attr| attr.as_str().to_owned())
2096 .collect(),
2097 },
2098 )
2099 } else {
2100 ::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);
2101 };
2102
2103 macros.push((id.local_def_index, self.lazy(kind)));
2104
2105 let mut def_key = self.tcx.hir_def_key(id);
2106 def_key.disambiguated_data.data = DefPathData::MacroNs(name);
2107
2108 let def_id = id.to_def_id();
2109 self.tables.def_kind.set_some(def_id.index,
DefKind::Macro(macro_kind.into()));record_some!(self.tables.def_kind[def_id] <- DefKind::Macro(macro_kind.into()));
2110
2111 self.encode_attrs(id);
2112 {
let value = def_key;
let lazy = self.lazy(value);
self.tables.def_keys.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_keys[def_id] <- def_key);
2113 {
let value = span;
let lazy = self.lazy(value);
self.tables.def_ident_span.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_ident_span[def_id] <- span);
2114 {
let value = span;
let lazy = self.lazy(value);
self.tables.def_span.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.def_span[def_id] <- span);
2115 {
let value = ty::Visibility::Public;
let lazy = self.lazy(value);
self.tables.visibility.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.visibility[def_id] <- ty::Visibility::Public);
2116 if let Some(stability) = stability {
2117 {
let value = stability;
let lazy = self.lazy(value);
self.tables.lookup_stability.set_some(def_id.index, lazy);
};record_some_lazy!(self.tables.lookup_stability[def_id] <- stability);
2118 }
2119 }
2120
2121 let macros = self.lazy_array(macros);
2122
2123 let mut proc_macro_quoted_spans = TableBuilder::default();
2124 for (i, span) in self.tcx.sess.proc_macro_quoted_spans() {
2125 proc_macro_quoted_spans.set_some(i, self.lazy(span));
2126 }
2127
2128 let proc_macro_quoted_spans = proc_macro_quoted_spans.encode(&mut self.opaque);
2129
2130 Some(ProcMacroData {
2131 proc_macro_decls_static,
2132 stability,
2133 macros,
2134 proc_macro_quoted_spans,
2135 })
2136 } else {
2137 None
2138 }
2139 }
2140
2141 fn encode_debugger_visualizers(&mut self) -> LazyArray<DebuggerVisualizerFile> {
2142 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2143 self.lazy_array(
2144 self.tcx
2145 .debugger_visualizers(LOCAL_CRATE)
2146 .iter()
2147 .map(DebuggerVisualizerFile::path_erased),
2152 )
2153 }
2154
2155 fn encode_crate_deps(&mut self) -> LazyArray<CrateDep> {
2156 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2157
2158 let deps = self
2159 .tcx
2160 .crates(())
2161 .iter()
2162 .map(|&cnum| {
2163 let dep = CrateDep {
2164 name: self.tcx.crate_name(cnum),
2165 hash: self.tcx.crate_hash(cnum),
2166 host_hash: self.tcx.crate_host_hash(cnum),
2167 kind: self.tcx.crate_dep_kind(cnum),
2168 is_private: self.tcx.is_private_dep(cnum),
2169 };
2170 (cnum, dep)
2171 })
2172 .collect::<Vec<_>>();
2173
2174 {
2175 let mut expected_cnum = 1;
2177 for &(n, _) in &deps {
2178 {
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));
2179 expected_cnum += 1;
2180 }
2181 }
2182
2183 self.lazy_array(deps.iter().map(|(_, dep)| dep))
2188 }
2189
2190 fn encode_target_modifiers(&mut self) -> LazyArray<TargetModifier> {
2191 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2192 let tcx = self.tcx;
2193 self.lazy_array(tcx.sess.opts.gather_target_modifiers())
2194 }
2195
2196 fn encode_enabled_denied_partial_mitigations(&mut self) -> LazyArray<DeniedPartialMitigation> {
2197 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2198 let tcx = self.tcx;
2199 self.lazy_array(tcx.sess.gather_enabled_denied_partial_mitigations())
2200 }
2201
2202 fn encode_lib_features(&mut self) -> LazyArray<(Symbol, FeatureStability)> {
2203 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2204 let tcx = self.tcx;
2205 let lib_features = tcx.lib_features(LOCAL_CRATE);
2206 self.lazy_array(lib_features.to_sorted_vec())
2207 }
2208
2209 fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> {
2210 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2211 let tcx = self.tcx;
2212 let implications = tcx.stability_implications(LOCAL_CRATE);
2213 let sorted = implications.to_sorted_stable_ord();
2214 self.lazy_array(sorted.into_iter().map(|(k, v)| (*k, *v)))
2215 }
2216
2217 fn encode_canonical_symbols(&mut self) -> LazyArray<(Symbol, DefIndex)> {
2218 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2219 let tcx = self.tcx;
2220 let canonical_symbols = &tcx.canonical_symbols(LOCAL_CRATE);
2221 self.lazy_array(canonical_symbols.iter().map(|cs| (cs.symbol, cs.def_id.index)))
2222 }
2223
2224 fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
2225 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2226 let tcx = self.tcx;
2227 let diagnostic_items = &tcx.diagnostic_items(LOCAL_CRATE).name_to_id;
2228 self.lazy_array(diagnostic_items.iter().map(|(&name, def_id)| (name, def_id.index)))
2229 }
2230
2231 fn encode_fake_doc_items(&mut self) -> LazyArray<DefIndex> {
2232 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2233 let tcx = self.tcx;
2234 let fake_doc_items = &tcx.fake_doc_items(LOCAL_CRATE);
2235 self.lazy_array(fake_doc_items.iter().map(|cs| cs.index))
2236 }
2237
2238 fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, LangItem)> {
2239 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2240 let lang_items = self.tcx.lang_items().iter();
2241 self.lazy_array(lang_items.filter_map(|(lang_item, def_id)| {
2242 def_id.as_local().map(|id| (id.local_def_index, lang_item))
2243 }))
2244 }
2245
2246 fn encode_lang_items_missing(&mut self) -> LazyArray<LangItem> {
2247 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2248 let tcx = self.tcx;
2249 self.lazy_array(&tcx.lang_items().missing)
2250 }
2251
2252 fn encode_stripped_cfg_items(&mut self) -> LazyArray<StrippedCfgItem<DefIndex>> {
2253 self.lazy_array(
2254 self.tcx
2255 .stripped_cfg_items(LOCAL_CRATE)
2256 .into_iter()
2257 .map(|item| item.clone().map_scope_id(|def_id| def_id.index)),
2258 )
2259 }
2260
2261 fn encode_traits(&mut self) -> LazyArray<DefIndex> {
2262 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2263 self.lazy_array(self.tcx.traits(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2264 }
2265
2266 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2267u32),
::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))]
2268 fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
2269 empty_proc_macro!(self);
2270 let tcx = self.tcx;
2271 let mut trait_impls: FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
2272 FxIndexMap::default();
2273
2274 for id in tcx.hir_free_items() {
2275 let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
2276 continue;
2277 };
2278 let def_id = id.owner_id.to_def_id();
2279
2280 if of_trait {
2281 let header = tcx.impl_trait_header(def_id);
2282 record_some_lazy!(self.tables.impl_trait_header[def_id] <- header);
2283
2284 let impl_is_fully_generic_for_reflection =
2285 tcx.impl_is_fully_generic_for_reflection(def_id);
2286
2287 record_value!(self.tables.impl_is_fully_generic_for_reflection[def_id] <- impl_is_fully_generic_for_reflection);
2288 record_value!(self.tables.defaultness[def_id] <- tcx.defaultness(def_id));
2289
2290 let trait_ref = header.trait_ref.instantiate_identity().skip_norm_wip();
2291 let simplified_self_ty = fast_reject::simplify_type(
2292 self.tcx,
2293 trait_ref.self_ty(),
2294 TreatParams::InstantiateWithInfer,
2295 );
2296 trait_impls
2297 .entry(trait_ref.def_id)
2298 .or_default()
2299 .push((id.owner_id.def_id.local_def_index, simplified_self_ty));
2300
2301 let trait_def = tcx.trait_def(trait_ref.def_id);
2302 if let Ok(mut an) = trait_def.ancestors(tcx, def_id)
2303 && let Some(specialization_graph::Node::Impl(parent)) = an.nth(1)
2304 {
2305 record_some!(self.tables.impl_parent[def_id] <- parent.into());
2306 }
2307
2308 if tcx.is_lang_item(trait_ref.def_id, LangItem::CoerceUnsized) {
2311 let coerce_unsized_info = tcx.coerce_unsized_info(def_id).unwrap();
2312 record_some_lazy!(self.tables.coerce_unsized_info[def_id] <- coerce_unsized_info);
2313 }
2314 }
2315 }
2316
2317 let trait_impls: Vec<_> = trait_impls
2318 .into_iter()
2319 .map(|(trait_def_id, impls)| TraitImpls {
2320 trait_id: (trait_def_id.krate.as_u32(), trait_def_id.index),
2321 impls: self.lazy_array(&impls),
2322 })
2323 .collect();
2324
2325 self.lazy_array(&trait_impls)
2326 }
2327
2328 {}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2328u32),
::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))]
2329 fn encode_incoherent_impls(&mut self) -> LazyArray<IncoherentImpls> {
2330 empty_proc_macro!(self);
2331 let tcx = self.tcx;
2332
2333 let all_impls: Vec<_> = tcx
2334 .crate_inherent_impls(())
2335 .0
2336 .incoherent_impls
2337 .iter()
2338 .map(|(&simp, impls)| IncoherentImpls {
2339 self_ty: self.lazy(simp),
2340 impls: self.lazy_array(impls.iter().map(|def_id| def_id.local_def_index)),
2341 })
2342 .collect();
2343
2344 self.lazy_array(&all_impls)
2345 }
2346
2347 fn encode_exportable_items(&mut self) -> LazyArray<DefIndex> {
2348 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2349 self.lazy_array(self.tcx.exportable_items(LOCAL_CRATE).iter().map(|def_id| def_id.index))
2350 }
2351
2352 fn encode_stable_order_of_exportable_impls(&mut self) -> LazyArray<(DefIndex, usize)> {
2353 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2354 let stable_order_of_exportable_impls =
2355 self.tcx.stable_order_of_exportable_impls(LOCAL_CRATE);
2356 self.lazy_array(
2357 stable_order_of_exportable_impls.iter().map(|(def_id, idx)| (def_id.index, *idx)),
2358 )
2359 }
2360
2361 fn encode_exported_symbols(
2368 &mut self,
2369 exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)],
2370 ) -> LazyArray<(ExportedSymbol<'static>, SymbolExportInfo)> {
2371 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2372
2373 self.lazy_array(exported_symbols.iter().cloned())
2374 }
2375
2376 fn encode_dylib_dependency_formats(&mut self) -> LazyArray<Option<LinkagePreference>> {
2377 if self.is_proc_macro { return LazyArray::default(); };empty_proc_macro!(self);
2378 let formats = self.tcx.dependency_formats(());
2379 if let Some(arr) = formats.get(&CrateType::Dylib) {
2380 return self.lazy_array(arr.iter().skip(1 ).map(
2381 |slot| match *slot {
2382 Linkage::NotLinked | Linkage::IncludedFromDylib => None,
2383
2384 Linkage::Dynamic => Some(LinkagePreference::RequireDynamic),
2385 Linkage::Static => Some(LinkagePreference::RequireStatic),
2386 },
2387 ));
2388 }
2389 LazyArray::default()
2390 }
2391}
2392
2393fn prefetch_mir(tcx: TyCtxt<'_>) {
2396 if !tcx.sess.opts.output_types.should_codegen() {
2397 return;
2399 }
2400
2401 let reachable_set = tcx.reachable_set(());
2402 par_for_each_in(tcx.mir_keys(()), |&&def_id| {
2403 if tcx.is_trivial_const(def_id) {
2404 return;
2405 }
2406 let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
2407
2408 if encode_const {
2409 tcx.ensure_done().mir_for_ctfe(def_id);
2410 }
2411 if encode_opt {
2412 tcx.ensure_done().optimized_mir(def_id);
2413 }
2414 if encode_opt || encode_const {
2415 tcx.ensure_done().promoted_mir(def_id);
2416 }
2417 })
2418}
2419
2420pub struct EncodedMetadata {
2444 full_metadata: Option<Mmap>,
2447 stub_metadata: Option<Vec<u8>>,
2450 path: Option<Box<Path>>,
2452 _temp_dir: Option<MaybeTempDir>,
2455}
2456
2457impl EncodedMetadata {
2458 #[inline]
2459 pub fn from_path(
2460 path: PathBuf,
2461 stub_path: Option<PathBuf>,
2462 temp_dir: Option<MaybeTempDir>,
2463 ) -> std::io::Result<Self> {
2464 let file = std::fs::File::open(&path)?;
2465 let file_metadata = file.metadata()?;
2466 if file_metadata.len() == 0 {
2467 return Ok(Self {
2468 full_metadata: None,
2469 stub_metadata: None,
2470 path: None,
2471 _temp_dir: None,
2472 });
2473 }
2474 let full_mmap = unsafe { Some(Mmap::map(file)?) };
2475
2476 let stub =
2477 if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
2478
2479 Ok(Self {
2480 full_metadata: full_mmap,
2481 stub_metadata: stub,
2482 path: Some(path.into()),
2483 _temp_dir: temp_dir,
2484 })
2485 }
2486
2487 #[inline]
2488 pub fn full(&self) -> &[u8] {
2489 &self.full_metadata.as_deref().unwrap_or_default()
2490 }
2491
2492 #[inline]
2493 pub fn stub_or_full(&self) -> &[u8] {
2494 self.stub_metadata.as_deref().unwrap_or(self.full())
2495 }
2496
2497 #[inline]
2498 pub fn path(&self) -> Option<&Path> {
2499 self.path.as_deref()
2500 }
2501}
2502
2503impl<S: Encoder> Encodable<S> for EncodedMetadata {
2504 fn encode(&self, s: &mut S) {
2505 self.stub_metadata.encode(s);
2506
2507 let slice = self.full();
2508 slice.encode(s)
2509 }
2510}
2511
2512impl<D: Decoder> Decodable<D> for EncodedMetadata {
2513 fn decode(d: &mut D) -> Self {
2514 let stub = <Option<Vec<u8>>>::decode(d);
2515
2516 let len = d.read_usize();
2517 let full_metadata = if len > 0 {
2518 let mut mmap = MmapMut::map_anon(len).unwrap();
2519 mmap.copy_from_slice(d.read_raw_bytes(len));
2520 Some(mmap.make_read_only().unwrap())
2521 } else {
2522 None
2523 };
2524
2525 Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
2526 }
2527}
2528
2529{}
#[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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2529u32),
::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/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs:2550",
"rustc_metadata::rmeta::encoder", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1d81eb4ad9cd207e3e638bd32b17ec4fce8412a6/compiler/rustc_metadata/src/rmeta/encoder.rs"),
::tracing_core::__macro_support::Option::Some(2550u32),
::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))]
2530pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2531 tcx.dep_graph.assert_ignored();
2534
2535 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
2536
2537 let dep_node = tcx.metadata_dep_node();
2538
2539 if tcx.dep_graph.is_fully_enabled()
2541 && let incr_comp_session = tcx.incr_comp_session.unwrap()
2542 && let Some(old_incr_comp_session_dir) = &incr_comp_session.old_session_directory
2543 && let work_product_id =
2544 WorkProductId::from_cgu_name(WorkProduct::METADATA_WORKPRODUCT_CGU_NAME)
2545 && let Some(work_product) = tcx.dep_graph.previous_work_product(&work_product_id)
2546 && tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some()
2547 {
2548 let saved_path = &work_product.saved_files[OutputType::Metadata.extension()];
2549 let source_file_in_incr_dir = &old_incr_comp_session_dir.join(saved_path);
2550 debug!("copying preexisting metadata from {source_file_in_incr_dir:?} to {path:?}");
2551 match rustc_fs_util::link_or_copy(&source_file_in_incr_dir, path) {
2552 Ok(_) => {}
2553 Err(err) => tcx.dcx().emit_fatal(FailCreateFileEncoder { err }),
2554 };
2555
2556 let file = std::fs::File::open(&source_file_in_incr_dir).unwrap();
2558 let mmap = unsafe { Mmap::map(file) }.unwrap();
2559 let owned = slice_owned(mmap, Deref::deref);
2560 let blob = MetadataBlob::new(owned);
2561 let hash = blob.expect("file already created").get_crate_hash();
2562 tcx.untracked().local_crate_hash.set(hash).expect("local_crate_hash set twice");
2563
2564 if let Some(ref_path) = ref_path {
2566 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
2567
2568 with_encode_metadata_header(tcx, ref_path, |ecx| {
2569 let header: LazyValue<CrateHeader> = ecx.lazy(CrateHeader {
2570 name: tcx.crate_name(LOCAL_CRATE),
2571 triple: tcx.sess.opts.target_triple.clone(),
2572 is_proc_macro_crate: false,
2573 is_stub: true,
2574 });
2575 (header.position.get(), 0)
2576 })
2577 }
2578
2579 return;
2580 };
2581
2582 if tcx.sess.opts.jobs.frontend.is_some() {
2583 par_join(
2587 || prefetch_mir(tcx),
2588 || {
2589 let _ = tcx.exported_non_generic_symbols(LOCAL_CRATE);
2590 let _ = tcx.exported_generic_symbols(LOCAL_CRATE);
2591 },
2592 );
2593 }
2594
2595 tcx.dep_graph.with_task(
2598 dep_node,
2599 tcx,
2600 || {
2601 with_encode_metadata_header(tcx, path, |ecx| {
2602 let (root, unhashed) = ecx.encode_crate_root();
2605
2606 ecx.opaque.flush();
2608 tcx.prof.artifact_size(
2610 "crate_metadata",
2611 "crate_metadata",
2612 ecx.opaque.file().metadata().unwrap().len(),
2613 );
2614
2615 (root.position.get(), unhashed.position.get())
2616 })
2617 },
2618 None,
2619 );
2620
2621 if let Some(ref_path) = ref_path {
2623 let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
2624
2625 with_encode_metadata_header(tcx, ref_path, |ecx| {
2626 let header: LazyValue<CrateHeader> = ecx.lazy(CrateHeader {
2627 name: tcx.crate_name(LOCAL_CRATE),
2628 triple: tcx.sess.opts.target_triple.clone(),
2629 is_proc_macro_crate: false,
2630 is_stub: true,
2631 });
2632 (header.position.get(), 0)
2633 })
2634 }
2635}
2636
2637fn with_encode_metadata_header(
2638 tcx: TyCtxt<'_>,
2639 path: &Path,
2640 f: impl FnOnce(&mut EncodeContext<'_, '_>) -> (usize, usize),
2641) {
2642 let metadata_crate_hash = tcx.sess.opts.unstable_opts.metadata_crate_hash;
2646 let metadata_hasher = Arc::new(Mutex::new(XxHash3_128::new()));
2651 if metadata_crate_hash {
2652 let hir_body_hash = compute_hir_hash(tcx);
2655 let supplement: Fingerprint = tcx.with_stable_hashing_context(|mut hcx| {
2656 let mut hasher = StableHasher::new();
2657 tcx.sess.opts.dep_tracking_hash(true).stable_hash(&mut hcx, &mut hasher);
2659 hir_body_hash.stable_hash(&mut hcx, &mut hasher);
2661 hasher.finish()
2662 });
2663 metadata_hasher.lock().unwrap().write(&supplement.to_le_bytes());
2664 }
2665
2666 let mut flush_strategy = {
2668 let metadata_hasher = Arc::clone(&metadata_hasher);
2669 move |bytes: &[u8]| metadata_hasher.lock().unwrap().write(bytes)
2670 };
2671
2672 let mut encoder = if metadata_crate_hash {
2673 FileEncoder::with_flush_strategy(path, &mut flush_strategy)
2674 } else {
2675 FileEncoder::new(path)
2676 }
2677 .unwrap_or_else(|err| tcx.dcx().emit_fatal(FailCreateFileEncoder { err }));
2678 encoder.emit_raw_bytes(METADATA_HEADER);
2679
2680 encoder.emit_raw_bytes(&0u64.to_le_bytes());
2682
2683 encoder.emit_raw_bytes(&0u64.to_le_bytes());
2685
2686 encoder.emit_raw_bytes(&Fingerprint::ZERO.to_le_bytes());
2688
2689 let source_map_files = tcx.sess.source_map().files();
2690 let source_file_cache = (Arc::clone(&source_map_files[0]), 0);
2691 let required_source_files = Some(FxIndexSet::default());
2692 drop(source_map_files);
2693
2694 let mut ecx = EncodeContext {
2695 opaque: encoder,
2696 metadata_hasher: Arc::clone(&metadata_hasher),
2697 tcx,
2698 feat: tcx.features(),
2699 tables: Default::default(),
2700 lazy_state: LazyState::NoNode,
2701 span_shorthands: Default::default(),
2702 type_shorthands: Default::default(),
2703 predicate_shorthands: Default::default(),
2704 source_file_cache,
2705 interpret_allocs: Default::default(),
2706 required_source_files,
2707 is_proc_macro: tcx.crate_types().contains(&CrateType::ProcMacro),
2708 hygiene_ctxt: Default::default(),
2709 symbol_index_table: Default::default(),
2710 };
2711
2712 rustc_version(tcx.sess.cfg_version).encode(&mut ecx);
2714
2715 let (root_position, unhashed_position) = f(&mut ecx);
2716
2717 if let Err((path, err)) = ecx.opaque.finish() {
2721 tcx.dcx().emit_fatal(FailWriteFile { path: &path, err });
2722 }
2723
2724 let mut file = ecx.opaque.file();
2725 let pos_before_seek = file.stream_position().unwrap();
2727
2728 if let Err(err) = encode_root_position(file, root_position) {
2729 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2730 }
2731
2732 if let Err(err) = encode_unhashed_position(file, unhashed_position) {
2733 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2734 }
2735
2736 let hash = tcx
2737 .untracked()
2738 .local_crate_hash
2739 .get()
2740 .copied()
2741 .expect("local_crate_hash set during encoding");
2742 if let Err(err) = encode_crate_hash(file, hash) {
2743 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2744 }
2745
2746 if let Err(err) = file.seek(SeekFrom::Start(pos_before_seek)) {
2747 tcx.dcx().emit_fatal(FailWriteFile { path: ecx.opaque.path(), err });
2748 }
2749}
2750
2751fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Error> {
2752 file.seek(SeekFrom::Start(ROOT_POS_OFFSET as u64))?;
2753 file.write_all(&pos.to_le_bytes())?;
2754 Ok(())
2755}
2756
2757fn encode_unhashed_position(mut file: &File, pos: usize) -> Result<(), std::io::Error> {
2758 file.seek(SeekFrom::Start(UNHASHED_POS_OFFSET as u64))?;
2759 file.write_all(&pos.to_le_bytes())?;
2760 Ok(())
2761}
2762
2763fn encode_crate_hash(mut file: &File, hash: Svh) -> Result<(), std::io::Error> {
2764 file.seek(SeekFrom::Start(CRATE_HASH_OFFSET as u64))?;
2765 file.write_all(&hash.as_fingerprint().to_le_bytes())?;
2766 Ok(())
2767}
2768
2769pub(crate) fn provide(providers: &mut Providers) {
2770 *providers = Providers {
2771 doc_link_resolutions: |tcx, def_id| {
2772 tcx.resolutions(())
2773 .doc_link_resolutions
2774 .get(&def_id)
2775 .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"))
2776 },
2777 doc_link_traits_in_scope: |tcx, def_id| {
2778 tcx.resolutions(()).doc_link_traits_in_scope.get(&def_id).unwrap_or_else(|| {
2779 ::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")
2780 })
2781 },
2782
2783 ..*providers
2784 }
2785}
2786
2787pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String {
2815 let value = body.value;
2816
2817 #[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)]
2818 enum Classification {
2819 Literal,
2820 Simple,
2821 Complex,
2822 }
2823
2824 use Classification::*;
2825
2826 fn classify(expr: &hir::Expr<'_>) -> Classification {
2827 match &expr.kind {
2828 hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
2829 if #[allow(non_exhaustive_omitted_patterns)] match expr.kind {
hir::ExprKind::Lit(_) => true,
_ => false,
}matches!(expr.kind, hir::ExprKind::Lit(_)) { Literal } else { Complex }
2830 }
2831 hir::ExprKind::Lit(_) => Literal,
2832 hir::ExprKind::Tup([]) => Simple,
2833 hir::ExprKind::Block(hir::Block { stmts: [], expr: Some(expr), .. }, _) => {
2834 if classify(expr) == Complex { Complex } else { Simple }
2835 }
2836 hir::ExprKind::Path(hir::QPath::Resolved(_, hir::Path { segments, .. })) => {
2841 if segments.iter().all(|segment| segment.args.is_none()) { Simple } else { Complex }
2842 }
2843 hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => Simple,
2846 _ => Complex,
2847 }
2848 }
2849
2850 match classify(value) {
2851 Literal
2861 if !value.span.from_expansion()
2862 && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) =>
2863 {
2864 snippet
2865 }
2866
2867 Literal | Simple => id_to_string(&tcx, body.id().hir_id),
2870
2871 Complex => {
2875 if tcx.def_kind(def_id) == DefKind::AnonConst {
2876 "{ _ }".to_owned()
2877 } else {
2878 "_".to_owned()
2879 }
2880 }
2881 }
2882}