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