Skip to content

Commit 41c1f39

Browse files
committed
Drop ExpnData::krate.
1 parent dbd2d77 commit 41c1f39

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

Diff for: compiler/rustc_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16531653
};
16541654

16551655
let data = self.root.expn_data.get(self, index).unwrap().decode(self);
1656-
rustc_span::hygiene::register_expn_id(index, data, hash)
1656+
rustc_span::hygiene::register_expn_id(self.cnum, index, data, hash)
16571657
}
16581658

16591659
/// Imports the source_map from an external crate into the source_map of the crate

Diff for: compiler/rustc_span/src/hygiene.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ impl LocalExpnId {
184184
HygieneData::with(|data| {
185185
let old_expn_data = &mut data.local_expn_data[self];
186186
assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID");
187-
debug_assert_eq!(expn_data.krate, LOCAL_CRATE);
188187
*old_expn_data = Some(expn_data);
189188
});
190189
update_disambiguator(self, ctx)
@@ -337,11 +336,7 @@ impl HygieneData {
337336
}
338337

339338
fn fresh_expn(&mut self, expn_data: Option<ExpnData>) -> LocalExpnId {
340-
if let Some(data) = &expn_data {
341-
debug_assert_eq!(data.krate, LOCAL_CRATE);
342-
}
343-
let expn_id = self.local_expn_data.next_index();
344-
self.local_expn_data.push(expn_data);
339+
let expn_id = self.local_expn_data.push(expn_data);
345340
let _eid = self.local_expn_hashes.push(ExpnHash(Fingerprint::ZERO));
346341
debug_assert_eq!(expn_id, _eid);
347342
expn_id
@@ -873,12 +868,6 @@ pub struct ExpnData {
873868
/// call_site span would have its own ExpnData, with the call_site
874869
/// pointing to the `foo!` invocation.
875870
pub call_site: Span,
876-
/// The crate that originally created this `ExpnData`. During
877-
/// metadata serialization, we only encode `ExpnData`s that were
878-
/// created locally - when our serialized metadata is decoded,
879-
/// foreign `ExpnId`s will have their `ExpnData` looked up
880-
/// from the crate specified by `Crate
881-
krate: CrateNum,
882871
/// Used to force two `ExpnData`s to have different `Fingerprint`s.
883872
/// Due to macro expansion, it's possible to end up with two `ExpnId`s
884873
/// that have identical `ExpnData`s. This violates the contract of `HashStable`
@@ -944,7 +933,6 @@ impl ExpnData {
944933
edition,
945934
macro_def_id,
946935
parent_module,
947-
krate: LOCAL_CRATE,
948936
disambiguator: 0,
949937
}
950938
}
@@ -968,7 +956,6 @@ impl ExpnData {
968956
edition,
969957
macro_def_id,
970958
parent_module,
971-
krate: LOCAL_CRATE,
972959
disambiguator: 0,
973960
}
974961
}
@@ -1222,8 +1209,13 @@ pub fn register_local_expn_id(data: ExpnData, hash: ExpnHash) -> ExpnId {
12221209
}
12231210

12241211
/// Register an expansion which has been decoded from the metadata of a foreign crate.
1225-
pub fn register_expn_id(local_id: ExpnIndex, data: ExpnData, hash: ExpnHash) -> ExpnId {
1226-
let expn_id = ExpnId { krate: data.krate, local_id };
1212+
pub fn register_expn_id(
1213+
krate: CrateNum,
1214+
local_id: ExpnIndex,
1215+
data: ExpnData,
1216+
hash: ExpnHash,
1217+
) -> ExpnId {
1218+
let expn_id = ExpnId { krate, local_id };
12271219
HygieneData::with(|hygiene_data| {
12281220
let _old_data = hygiene_data.foreign_expn_data.insert(expn_id, data);
12291221
debug_assert!(_old_data.is_none());
@@ -1260,9 +1252,8 @@ pub fn decode_expn_id(
12601252
// Don't decode the data inside `HygieneData::with`, since we need to recursively decode
12611253
// other ExpnIds
12621254
let (expn_data, hash) = decode_data(expn_id);
1263-
debug_assert_eq!(krate, expn_data.krate);
12641255

1265-
register_expn_id(index, expn_data, hash)
1256+
register_expn_id(krate, index, expn_data, hash)
12661257
}
12671258

12681259
// Decodes `SyntaxContext`, using the provided `HygieneDecodeContext`
@@ -1420,7 +1411,7 @@ impl<D: Decoder> Decodable<D> for SyntaxContext {
14201411
/// This method is called only when an `ExpnData` is first associated
14211412
/// with an `ExpnId` (when the `ExpnId` is initially constructed, or via
14221413
/// `set_expn_data`). It is *not* called for foreign `ExpnId`s deserialized
1423-
/// from another crate's metadata - since `ExpnData` includes a `krate` field,
1414+
/// from another crate's metadata - since `ExpnHash` includes the stable crate id,
14241415
/// collisions are only possible between `ExpnId`s within the same crate.
14251416
fn update_disambiguator(expn_id: LocalExpnId, mut ctx: impl HashStableContext) {
14261417
let mut expn_data = expn_id.expn_data();

0 commit comments

Comments
 (0)