Skip to content

Commit 25b88c6

Browse files
committed
temp
1 parent 50984bf commit 25b88c6

File tree

2 files changed

+17
-72
lines changed

2 files changed

+17
-72
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;
@@ -215,8 +214,7 @@ impl<'a> LazyDecoder for BlobDecodeContext<'a> {
215214
pub(super) struct MetadataDecodeContext<'a, 'tcx> {
216215
blob_decoder: BlobDecodeContext<'a>,
217216
cdata: CrateMetadataRef<'a>,
218-
sess: Option<&'tcx Session>,
219-
tcx: Option<TyCtxt<'tcx>>,
217+
tcx: TyCtxt<'tcx>,
220218

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

249-
pub(super) trait BlobMetadata<'a>: Copy {
247+
pub(super) trait Metadata<'a>: Copy {
250248
type Context: BlobDecoder + LazyDecoder;
251249

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

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

270257
fn blob(self) -> &'a MetadataBlob {
@@ -287,40 +274,26 @@ impl<'a> BlobMetadata<'a> for &'a MetadataBlob {
287274
}
288275
}
289276

290-
impl<'a, 'tcx> BlobMetadata<'a> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
277+
impl<'a, 'tcx> Metadata<'a> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
291278
type Context = MetadataDecodeContext<'a, 'tcx>;
292279

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

297284
fn decoder(self, pos: usize) -> MetadataDecodeContext<'a, 'tcx> {
298-
let tcx = self.tcx();
299-
let cdata = self.cdata();
300285
MetadataDecodeContext {
301286
blob_decoder: self.blob().decoder(pos),
302-
cdata,
303-
sess: self.sess().or(tcx.map(|tcx| tcx.sess)),
304-
tcx,
305-
alloc_decoding_session: cdata.cdata.alloc_decoding_state.new_decoding_session(),
287+
cdata: self.0,
288+
tcx: self.1,
289+
alloc_decoding_session: self.0.cdata.alloc_decoding_state.new_decoding_session(),
306290
}
307291
}
308292
}
309293

310-
impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
311-
#[inline]
312-
fn cdata(self) -> CrateMetadataRef<'a> {
313-
self.0
314-
}
315-
#[inline]
316-
fn tcx(self) -> Option<TyCtxt<'tcx>> {
317-
Some(self.1)
318-
}
319-
}
320-
321294
impl<T: ParameterizedOverTcx> LazyValue<T> {
322295
#[inline]
323-
fn decode<'a, 'tcx, M: BlobMetadata<'a>>(self, metadata: M) -> T::Value<'tcx>
296+
fn decode<'a, 'tcx, M: Metadata<'a>>(self, metadata: M) -> T::Value<'tcx>
324297
where
325298
T::Value<'tcx>: Decodable<M::Context>,
326299
{
@@ -360,7 +333,7 @@ unsafe impl<D: Decoder, T: Decodable<D>> TrustedLen for DecodeIterator<T, D> {}
360333

361334
impl<T: ParameterizedOverTcx> LazyArray<T> {
362335
#[inline]
363-
fn decode<'a, 'tcx, M: BlobMetadata<'a>>(
336+
fn decode<'a, 'tcx, M: Metadata<'a>>(
364337
self,
365338
metadata: M,
366339
) -> DecodeIterator<T::Value<'tcx>, M::Context>
@@ -374,17 +347,6 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
374347
}
375348

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

426388
#[inline]
427389
fn interner(&self) -> TyCtxt<'tcx> {
428-
self.tcx()
390+
self.tcx
429391
}
430392

431393
fn cached_ty_for_shorthand<F>(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx>
432394
where
433395
F: FnOnce(&mut Self) -> Ty<'tcx>,
434396
{
435-
let tcx = self.tcx();
397+
let tcx = self.tcx;
436398

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

@@ -473,8 +435,7 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for ExpnIndex {
473435

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

480441
fn decode_crate_num(&mut self) -> CrateNum {
@@ -488,12 +449,7 @@ impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
488449

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

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

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

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

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

630575
// Index of the file in the corresponding crate's list of encoded files.
631576
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 {
@@ -548,7 +548,7 @@ where
548548
for<'tcx> T::Value<'tcx>: FixedSizeEncoding<ByteArray = [u8; N]>,
549549
{
550550
/// Given the metadata, extract out the value at a particular index (if any).
551-
pub(super) fn get<'a, 'tcx, M: BlobMetadata<'a>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
551+
pub(super) fn get<'a, 'tcx, M: Metadata<'a>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
552552
// Access past the end of the table returns a Default
553553
if i.index() >= self.len {
554554
return Default::default();

0 commit comments

Comments
 (0)