Skip to content

Commit bed17cf

Browse files
committed
temp
1 parent f38c33a commit bed17cf

File tree

3 files changed

+19
-74
lines changed

3 files changed

+19
-74
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_middle::{bug, implement_ty_decoder};
2929
use rustc_proc_macro::bridge::client::ProcMacro;
3030
use rustc_serialize::opaque::MemDecoder;
3131
use rustc_serialize::{Decodable, Decoder};
32-
use rustc_session::Session;
3332
use rustc_session::config::TargetModifier;
3433
use rustc_session::cstore::{CrateSource, ExternCrate};
3534
use rustc_span::hygiene::HygieneDecodeContext;
@@ -214,8 +213,7 @@ impl<'a> LazyDecoder for BlobDecodeContext<'a> {
214213
pub(super) struct MetadataDecodeContext<'a, 'tcx> {
215214
blob_decoder: BlobDecodeContext<'a>,
216215
cdata: CrateMetadataRef<'a>,
217-
sess: Option<&'tcx Session>,
218-
tcx: Option<TyCtxt<'tcx>>,
216+
tcx: TyCtxt<'tcx>,
219217

220218
// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
221219
alloc_decoding_session: AllocDecodingSession<'a>,
@@ -245,25 +243,14 @@ impl<'a, 'tcx> Deref for MetadataDecodeContext<'a, 'tcx> {
245243
}
246244
}
247245

248-
pub(super) trait BlobMetadata<'a>: Copy {
246+
pub(super) trait Metadata<'a>: Copy {
249247
type Context: BlobDecoder + LazyDecoder;
250248

251249
fn blob(self) -> &'a MetadataBlob;
252250
fn decoder(self, pos: usize) -> Self::Context;
253251
}
254252

255-
/// Abstract over the various ways one can create metadata decoders.
256-
pub(super) trait Metadata<'a, 'tcx>: Copy {
257-
fn cdata(self) -> CrateMetadataRef<'a>;
258-
fn sess(self) -> Option<&'tcx Session> {
259-
None
260-
}
261-
fn tcx(self) -> Option<TyCtxt<'tcx>> {
262-
None
263-
}
264-
}
265-
266-
impl<'a> BlobMetadata<'a> for &'a MetadataBlob {
253+
impl<'a> Metadata<'a> for &'a MetadataBlob {
267254
type Context = BlobDecodeContext<'a>;
268255

269256
fn blob(self) -> &'a MetadataBlob {
@@ -286,40 +273,26 @@ impl<'a> BlobMetadata<'a> for &'a MetadataBlob {
286273
}
287274
}
288275

289-
impl<'a, 'tcx> BlobMetadata<'a> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
276+
impl<'a, 'tcx> Metadata<'a> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
290277
type Context = MetadataDecodeContext<'a, 'tcx>;
291278

292279
fn blob(self) -> &'a MetadataBlob {
293280
&self.0.cdata.blob
294281
}
295282

296283
fn decoder(self, pos: usize) -> MetadataDecodeContext<'a, 'tcx> {
297-
let tcx = self.tcx();
298-
let cdata = self.cdata();
299284
MetadataDecodeContext {
300285
blob_decoder: self.blob().decoder(pos),
301-
cdata,
302-
sess: self.sess().or(tcx.map(|tcx| tcx.sess)),
303-
tcx,
304-
alloc_decoding_session: cdata.cdata.alloc_decoding_state.new_decoding_session(),
286+
cdata: self.0,
287+
tcx: self.1,
288+
alloc_decoding_session: self.0.cdata.alloc_decoding_state.new_decoding_session(),
305289
}
306290
}
307291
}
308292

309-
impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
310-
#[inline]
311-
fn cdata(self) -> CrateMetadataRef<'a> {
312-
self.0
313-
}
314-
#[inline]
315-
fn tcx(self) -> Option<TyCtxt<'tcx>> {
316-
Some(self.1)
317-
}
318-
}
319-
320293
impl<T: ParameterizedOverTcx> LazyValue<T> {
321294
#[inline]
322-
fn decode<'a, 'tcx, M: BlobMetadata<'a>>(self, metadata: M) -> T::Value<'tcx>
295+
fn decode<'a, 'tcx, M: Metadata<'a>>(self, metadata: M) -> T::Value<'tcx>
323296
where
324297
T::Value<'tcx>: Decodable<M::Context>,
325298
{
@@ -359,7 +332,7 @@ unsafe impl<D: Decoder, T: Decodable<D>> TrustedLen for DecodeIterator<T, D> {}
359332

360333
impl<T: ParameterizedOverTcx> LazyArray<T> {
361334
#[inline]
362-
fn decode<'a, 'tcx, M: BlobMetadata<'a>>(
335+
fn decode<'a, 'tcx, M: Metadata<'a>>(
363336
self,
364337
metadata: M,
365338
) -> DecodeIterator<T::Value<'tcx>, M::Context>
@@ -373,17 +346,6 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
373346
}
374347

375348
impl<'a, 'tcx> MetadataDecodeContext<'a, 'tcx> {
376-
#[inline]
377-
fn tcx(&self) -> TyCtxt<'tcx> {
378-
let Some(tcx) = self.tcx else {
379-
bug!(
380-
"No TyCtxt found for decoding. \
381-
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
382-
);
383-
};
384-
tcx
385-
}
386-
387349
#[inline]
388350
fn map_encoded_cnum_to_current(&self, cnum: CrateNum) -> CrateNum {
389351
self.cdata.map_encoded_cnum_to_current(cnum)
@@ -424,14 +386,14 @@ impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> {
424386

425387
#[inline]
426388
fn interner(&self) -> TyCtxt<'tcx> {
427-
self.tcx()
389+
self.tcx
428390
}
429391

430392
fn cached_ty_for_shorthand<F>(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx>
431393
where
432394
F: FnOnce(&mut Self) -> Ty<'tcx>,
433395
{
434-
let tcx = self.tcx();
396+
let tcx = self.tcx;
435397

436398
let key = ty::CReaderCacheKey { cnum: Some(self.cdata.cnum), pos: shorthand };
437399

@@ -472,8 +434,7 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for ExpnIndex {
472434

473435
impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
474436
fn decode_attr_id(&mut self) -> rustc_span::AttrId {
475-
let sess = self.sess.expect("can't decode AttrId without Session");
476-
sess.psess.attr_id_generator.mk_attr_id()
437+
self.tcx.sess.psess.attr_id_generator.mk_attr_id()
477438
}
478439

479440
fn decode_crate_num(&mut self) -> CrateNum {
@@ -487,12 +448,7 @@ impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
487448

488449
fn decode_syntax_context(&mut self) -> SyntaxContext {
489450
let cdata = self.cdata;
490-
let Some(tcx) = self.tcx else {
491-
bug!(
492-
"Cannot decode SyntaxContext without Session.\
493-
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
494-
);
495-
};
451+
let tcx = self.tcx;
496452

497453
let cname = cdata.root.name();
498454
rustc_span::hygiene::decode_syntax_context(self, &cdata.hygiene_context, |_, id| {
@@ -509,13 +465,7 @@ impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
509465
fn decode_expn_id(&mut self) -> ExpnId {
510466
let local_cdata = self.cdata;
511467

512-
let Some(tcx) = self.tcx else {
513-
bug!(
514-
"Cannot decode ExpnId without Session. \
515-
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
516-
);
517-
};
518-
468+
let tcx = self.tcx;
519469
let cnum = CrateNum::decode(self);
520470
let index = u32::decode(self);
521471

@@ -619,12 +569,7 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for SpanData {
619569
let len = tag.length().unwrap_or_else(|| BytePos::decode(decoder));
620570
let hi = lo + len;
621571

622-
let Some(tcx) = decoder.tcx else {
623-
bug!(
624-
"Cannot decode Span without Session. \
625-
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
626-
)
627-
};
572+
let tcx = decoder.tcx;
628573

629574
// Index of the file in the corresponding crate's list of encoded files.
630575
let metadata_index = u32::decode(decoder);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def::CtorOf;
22
use rustc_index::Idx;
33

4-
use crate::rmeta::decoder::BlobMetadata;
4+
use crate::rmeta::decoder::Metadata;
55
use crate::rmeta::*;
66

77
pub(super) trait IsDefault: Default {
@@ -523,7 +523,7 @@ where
523523
for<'tcx> T::Value<'tcx>: FixedSizeEncoding<ByteArray = [u8; N]>,
524524
{
525525
/// Given the metadata, extract out the value at a particular index (if any).
526-
pub(super) fn get<'a, 'tcx, M: BlobMetadata<'a>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
526+
pub(super) fn get<'a, 'tcx, M: Metadata<'a>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
527527
// Access past the end of the table returns a Default
528528
if i.index() >= self.len {
529529
return Default::default();

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub(crate) fn get_item_path(tcx: TyCtxt<'_>, def_id: DefId, kind: ItemType) -> V
239239
// Check to see if it is a macro 2.0 or built-in macro
240240
// More information in <https://rust-lang.github.io/rfcs/1584-macros.html>.
241241
if matches!(
242-
CStore::from_tcx(tcx).load_macro_untracked(def_id, tcx),
242+
CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id),
243243
LoadedMacro::MacroDef { def, .. } if !def.macro_rules
244244
) {
245245
once(crate_name).chain(relative).collect()
@@ -772,7 +772,7 @@ fn build_macro(
772772
name: Symbol,
773773
macro_kinds: MacroKinds,
774774
) -> clean::ItemKind {
775-
match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx) {
775+
match CStore::from_tcx(cx.tcx).load_macro_untracked(cx.tcx, def_id) {
776776
// FIXME: handle attributes and derives that aren't proc macros, and macros with multiple
777777
// kinds
778778
LoadedMacro::MacroDef { def, .. } => match macro_kinds {

0 commit comments

Comments
 (0)