summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_metadata/src/rmeta/decoder.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_metadata/src/rmeta/decoder.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_metadata/src/rmeta/decoder.rs')
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs49
1 files changed, 37 insertions, 12 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index b9318aee5..e8f66c36a 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -34,7 +34,7 @@ use rustc_session::cstore::{
use rustc_session::Session;
use rustc_span::hygiene::ExpnIndex;
use rustc_span::symbol::{kw, Ident, Symbol};
-use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP};
+use rustc_span::{self, BytePos, ExpnId, Pos, Span, SpanData, SyntaxContext, DUMMY_SP};
use proc_macro::bridge::client::ProcMacro;
use std::iter::TrustedLen;
@@ -311,8 +311,10 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
let Some(tcx) = self.tcx else {
- bug!("No TyCtxt found for decoding. \
- You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
+ bug!(
+ "No TyCtxt found for decoding. \
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
+ );
};
tcx
}
@@ -448,8 +450,10 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
let cdata = decoder.cdata();
let Some(sess) = decoder.sess else {
- bug!("Cannot decode SyntaxContext without Session.\
- You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
+ bug!(
+ "Cannot decode SyntaxContext without Session.\
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
+ );
};
let cname = cdata.root.name();
@@ -470,8 +474,10 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
let local_cdata = decoder.cdata();
let Some(sess) = decoder.sess else {
- bug!("Cannot decode ExpnId without Session. \
- You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
+ bug!(
+ "Cannot decode ExpnId without Session. \
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
+ );
};
let cnum = CrateNum::decode(decoder);
@@ -507,11 +513,26 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Span {
+ let mode = SpanEncodingMode::decode(decoder);
+ let data = match mode {
+ SpanEncodingMode::Direct => SpanData::decode(decoder),
+ SpanEncodingMode::Shorthand(position) => decoder.with_position(position, |decoder| {
+ let mode = SpanEncodingMode::decode(decoder);
+ debug_assert!(matches!(mode, SpanEncodingMode::Direct));
+ SpanData::decode(decoder)
+ }),
+ };
+ Span::new(data.lo, data.hi, data.ctxt, data.parent)
+ }
+}
+
+impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SpanData {
+ fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> SpanData {
let ctxt = SyntaxContext::decode(decoder);
let tag = u8::decode(decoder);
if tag == TAG_PARTIAL_SPAN {
- return DUMMY_SP.with_ctxt(ctxt);
+ return DUMMY_SP.with_ctxt(ctxt).data();
}
debug_assert!(tag == TAG_VALID_SPAN_LOCAL || tag == TAG_VALID_SPAN_FOREIGN);
@@ -521,8 +542,10 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
let hi = lo + len;
let Some(sess) = decoder.sess else {
- bug!("Cannot decode Span without Session. \
- You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.")
+ bug!(
+ "Cannot decode Span without Session. \
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
+ )
};
// Index of the file in the corresponding crate's list of encoded files.
@@ -604,7 +627,7 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
let hi = hi + source_file.translated_source_file.start_pos;
// Do not try to decode parent for foreign spans.
- Span::new(lo, hi, ctxt, None)
+ SpanData { lo, hi, ctxt, parent: None }
}
}
@@ -819,7 +842,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, sess))
}
- fn load_proc_macro(self, id: DefIndex, sess: &Session) -> SyntaxExtension {
+ fn load_proc_macro(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> SyntaxExtension {
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
ProcMacro::CustomDerive { trait_name, attributes, client } => {
let helper_attrs =
@@ -838,9 +861,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
};
+ let sess = tcx.sess;
let attrs: Vec<_> = self.get_item_attrs(id, sess).collect();
SyntaxExtension::new(
sess,
+ tcx.features(),
kind,
self.get_span(id, sess),
helper_attrs,