Skip to content

Commit 19c84c8

Browse files
Move codec module back into middle
1 parent 6438b9e commit 19c84c8

File tree

16 files changed

+129
-187
lines changed

16 files changed

+129
-187
lines changed

Diff for: compiler/rustc_macros/src/serialize.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ use syn::spanned::Spanned;
66
pub(super) fn type_decodable_derive(
77
mut s: synstructure::Structure<'_>,
88
) -> proc_macro2::TokenStream {
9+
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
10+
s.add_impl_generic(parse_quote! { 'tcx });
11+
}
912
let decoder_ty = quote! { __D };
10-
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
11-
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
12-
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
13-
quote! { <I = I> }
14-
} else {
15-
quote! {}
16-
};
17-
18-
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder #bound });
13+
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder<'tcx> });
1914
s.add_bounds(synstructure::AddBounds::Fields);
2015
s.underscore_const(true);
2116

@@ -132,16 +127,11 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
132127
pub(super) fn type_encodable_derive(
133128
mut s: synstructure::Structure<'_>,
134129
) -> proc_macro2::TokenStream {
135-
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
136-
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
137-
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
138-
quote! { <I = I> }
139-
} else {
140-
quote! {}
141-
};
142-
143130
let encoder_ty = quote! { __E };
144-
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder #bound });
131+
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
132+
s.add_impl_generic(parse_quote! { 'tcx });
133+
}
134+
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder<'tcx> });
145135
s.add_bounds(synstructure::AddBounds::Fields);
146136
s.underscore_const(true);
147137

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,11 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
386386
}
387387
}
388388

389-
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
389+
impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
390390
const CLEAR_CROSS_CRATE: bool = true;
391391

392-
type I = TyCtxt<'tcx>;
393-
394392
#[inline]
395-
fn interner(&self) -> Self::I {
393+
fn interner(&self) -> TyCtxt<'tcx> {
396394
self.tcx()
397395
}
398396

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,9 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
378378
}
379379
}
380380

381-
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
381+
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
382382
const CLEAR_CROSS_CRATE: bool = true;
383383

384-
type I = TyCtxt<'tcx>;
385-
386384
fn position(&self) -> usize {
387385
self.opaque.position()
388386
}

Diff for: compiler/rustc_middle/src/mir/interpret/allocation.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use rustc_abi::{Align, HasDataLayout, Size};
1616
use rustc_ast::Mutability;
1717
use rustc_data_structures::intern::Interned;
1818
use rustc_macros::HashStable;
19-
use rustc_serialize::{Decodable, Encodable};
20-
use rustc_type_ir::{TyDecoder, TyEncoder};
19+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2120

2221
use super::{
2322
AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer,
@@ -112,7 +111,7 @@ struct AllocFlags {
112111
all_zero: bool,
113112
}
114113

115-
impl<E: TyEncoder> Encodable<E> for AllocFlags {
114+
impl<E: Encoder> Encodable<E> for AllocFlags {
116115
fn encode(&self, encoder: &mut E) {
117116
// Make sure Align::MAX can be stored with the high 2 bits unset.
118117
const {
@@ -131,7 +130,7 @@ impl<E: TyEncoder> Encodable<E> for AllocFlags {
131130
}
132131
}
133132

134-
impl<D: TyDecoder> Decodable<D> for AllocFlags {
133+
impl<D: Decoder> Decodable<D> for AllocFlags {
135134
fn decode(decoder: &mut D) -> Self {
136135
let flags: u8 = Decodable::decode(decoder);
137136
let align = flags & 0b0011_1111;
@@ -173,7 +172,7 @@ fn all_zero(buf: &[u8]) -> bool {
173172
}
174173

175174
/// Custom encoder for [`Allocation`] to more efficiently represent the case where all bytes are 0.
176-
impl<Prov: Provenance, Extra, Bytes, E: TyEncoder> Encodable<E> for Allocation<Prov, Extra, Bytes>
175+
impl<Prov: Provenance, Extra, Bytes, E: Encoder> Encodable<E> for Allocation<Prov, Extra, Bytes>
177176
where
178177
Bytes: AllocBytes,
179178
ProvenanceMap<Prov>: Encodable<E>,
@@ -193,7 +192,7 @@ where
193192
}
194193
}
195194

196-
impl<Prov: Provenance, Extra, Bytes, D: TyDecoder> Decodable<D> for Allocation<Prov, Extra, Bytes>
195+
impl<Prov: Provenance, Extra, Bytes, D: Decoder> Decodable<D> for Allocation<Prov, Extra, Bytes>
197196
where
198197
Bytes: AllocBytes,
199198
ProvenanceMap<Prov>: Decodable<D>,

Diff for: compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use std::ops::Range;
55
use std::{hash, iter};
66

77
use rustc_abi::Size;
8-
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
9-
use rustc_serialize::{Decodable, Encodable};
10-
use rustc_type_ir::{TyDecoder, TyEncoder};
8+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
9+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
1110

1211
use super::AllocRange;
1312

@@ -19,13 +18,13 @@ type Block = u64;
1918
/// possible. Currently, if all the blocks have the same value, then the mask represents either a
2019
/// fully initialized or fully uninitialized const allocation, so we can only store that single
2120
/// value.
22-
#[derive(Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
21+
#[derive(Clone, Debug, Eq, PartialEq, Encodable_NoContext, Decodable_NoContext, Hash, HashStable)]
2322
pub struct InitMask {
2423
blocks: InitMaskBlocks,
2524
len: Size,
2625
}
2726

28-
#[derive(Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
27+
#[derive(Clone, Debug, Eq, PartialEq, Encodable_NoContext, Decodable_NoContext, Hash, HashStable)]
2928
enum InitMaskBlocks {
3029
Lazy {
3130
/// Whether the lazy init mask is fully initialized or uninitialized.
@@ -194,7 +193,7 @@ struct InitMaskMaterialized {
194193
// and also produces more output when the high bits of each `u64` are occupied.
195194
// Note: There is probably a remaining optimization for masks that do not use an entire
196195
// `Block`.
197-
impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized {
196+
impl<E: Encoder> Encodable<E> for InitMaskMaterialized {
198197
fn encode(&self, encoder: &mut E) {
199198
encoder.emit_usize(self.blocks.len());
200199
for block in &self.blocks {
@@ -204,7 +203,7 @@ impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized {
204203
}
205204

206205
// This implementation is deliberately not derived, see the matching `Encodable` impl.
207-
impl<D: TyDecoder> Decodable<D> for InitMaskMaterialized {
206+
impl<D: Decoder> Decodable<D> for InitMaskMaterialized {
208207
fn decode(decoder: &mut D) -> Self {
209208
let num_blocks = decoder.read_usize();
210209
let mut blocks = Vec::with_capacity(num_blocks);

Diff for: compiler/rustc_middle/src/mir/interpret/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ enum AllocDiscriminant {
105105
Static,
106106
}
107107

108-
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>>(
108+
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
109109
encoder: &mut E,
110110
tcx: TyCtxt<'tcx>,
111111
alloc_id: AllocId,
@@ -175,7 +175,7 @@ impl<'s> AllocDecodingSession<'s> {
175175
/// Decodes an `AllocId` in a thread-safe way.
176176
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
177177
where
178-
D: TyDecoder<I = TyCtxt<'tcx>>,
178+
D: TyDecoder<'tcx>,
179179
{
180180
// Read the index of the allocation.
181181
let idx = usize::try_from(decoder.read_u32()).unwrap();

Diff for: compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<T> ClearCrossCrate<T> {
790790
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
791791
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
792792

793-
impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
793+
impl<'tcx, E: TyEncoder<'tcx>, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
794794
#[inline]
795795
fn encode(&self, e: &mut E) {
796796
if E::CLEAR_CROSS_CRATE {
@@ -806,7 +806,7 @@ impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
806806
}
807807
}
808808
}
809-
impl<D: TyDecoder, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
809+
impl<'tcx, D: TyDecoder<'tcx>, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
810810
#[inline]
811811
fn decode(d: &mut D) -> ClearCrossCrate<T> {
812812
if D::CLEAR_CROSS_CRATE {

Diff for: compiler/rustc_middle/src/query/on_disk_cache.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ where
518518
value
519519
}
520520

521-
impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
522-
type I = TyCtxt<'tcx>;
521+
impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
523522
const CLEAR_CROSS_CRATE: bool = false;
524523

525524
#[inline]
@@ -943,8 +942,7 @@ impl<'a, 'tcx> SpanEncoder for CacheEncoder<'a, 'tcx> {
943942
}
944943
}
945944

946-
impl<'a, 'tcx> TyEncoder for CacheEncoder<'a, 'tcx> {
947-
type I = TyCtxt<'tcx>;
945+
impl<'a, 'tcx> TyEncoder<'tcx> for CacheEncoder<'a, 'tcx> {
948946
const CLEAR_CROSS_CRATE: bool = false;
949947

950948
#[inline]

0 commit comments

Comments
 (0)