Skip to content

Commit 8e1ae56

Browse files
committed
rustc_metadata: Privatize everything in schema and schema/table
1 parent 8590b16 commit 8e1ae56

File tree

2 files changed

+80
-82
lines changed

2 files changed

+80
-82
lines changed

src/librustc_metadata/schema.rs

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use decoder::Metadata;
12
use table::PerDefTable;
23

34
use rustc::hir;
@@ -22,7 +23,6 @@ use syntax_pos::{self, Span};
2223
use std::marker::PhantomData;
2324
use std::num::NonZeroUsize;
2425

25-
crate use decoder::Metadata;
2626
crate use encoder::encode_metadata;
2727

2828
mod decoder;
@@ -110,13 +110,13 @@ crate struct Lazy<T, Meta = <T as LazyMeta>::Meta>
110110
where T: ?Sized + LazyMeta<Meta = Meta>,
111111
Meta: 'static + Copy,
112112
{
113-
pub position: NonZeroUsize,
114-
pub meta: Meta,
113+
position: NonZeroUsize,
114+
meta: Meta,
115115
_marker: PhantomData<T>,
116116
}
117117

118118
impl<T: ?Sized + LazyMeta> Lazy<T> {
119-
crate fn from_position_and_meta(position: NonZeroUsize, meta: T::Meta) -> Lazy<T> {
119+
fn from_position_and_meta(position: NonZeroUsize, meta: T::Meta) -> Lazy<T> {
120120
Lazy {
121121
position,
122122
meta,
@@ -126,13 +126,13 @@ impl<T: ?Sized + LazyMeta> Lazy<T> {
126126
}
127127

128128
impl<T: Encodable> Lazy<T> {
129-
crate fn from_position(position: NonZeroUsize) -> Lazy<T> {
129+
fn from_position(position: NonZeroUsize) -> Lazy<T> {
130130
Lazy::from_position_and_meta(position, ())
131131
}
132132
}
133133

134134
impl<T: Encodable> Lazy<[T]> {
135-
crate fn empty() -> Lazy<[T]> {
135+
fn empty() -> Lazy<[T]> {
136136
Lazy::from_position_and_meta(NonZeroUsize::new(1).unwrap(), 0)
137137
}
138138
}
@@ -149,7 +149,7 @@ impl<T: ?Sized + LazyMeta> rustc_serialize::UseSpecializedDecodable for Lazy<T>
149149

150150
/// Encoding / decoding state for `Lazy`.
151151
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
152-
crate enum LazyState {
152+
enum LazyState {
153153
/// Outside of a metadata node.
154154
NoNode,
155155

@@ -187,23 +187,23 @@ crate struct CrateRoot<'tcx> {
187187
pub has_default_lib_allocator: bool,
188188
pub plugin_registrar_fn: Option<DefIndex>,
189189
pub proc_macro_decls_static: Option<DefIndex>,
190-
pub proc_macro_stability: Option<attr::Stability>,
190+
proc_macro_stability: Option<attr::Stability>,
191191

192192
pub crate_deps: Lazy<[CrateDep]>,
193-
pub dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
194-
pub lib_features: Lazy<[(Symbol, Option<Symbol>)]>,
195-
pub lang_items: Lazy<[(DefIndex, usize)]>,
196-
pub lang_items_missing: Lazy<[lang_items::LangItem]>,
197-
pub diagnostic_items: Lazy<[(Symbol, DefIndex)]>,
198-
pub native_libraries: Lazy<[NativeLibrary]>,
199-
pub foreign_modules: Lazy<[ForeignModule]>,
200-
pub source_map: Lazy<[syntax_pos::SourceFile]>,
193+
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
194+
lib_features: Lazy<[(Symbol, Option<Symbol>)]>,
195+
lang_items: Lazy<[(DefIndex, usize)]>,
196+
lang_items_missing: Lazy<[lang_items::LangItem]>,
197+
diagnostic_items: Lazy<[(Symbol, DefIndex)]>,
198+
native_libraries: Lazy<[NativeLibrary]>,
199+
foreign_modules: Lazy<[ForeignModule]>,
200+
source_map: Lazy<[syntax_pos::SourceFile]>,
201201
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
202202
pub impls: Lazy<[TraitImpls]>,
203-
pub exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]),
203+
exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]),
204204
pub interpret_alloc_index: Lazy<[u32]>,
205205

206-
pub per_def: LazyPerDefTables<'tcx>,
206+
per_def: LazyPerDefTables<'tcx>,
207207

208208
/// The DefIndex's of any proc macros delcared by
209209
/// this crate
@@ -236,35 +236,33 @@ crate struct TraitImpls {
236236

237237
#[derive(RustcEncodable, RustcDecodable)]
238238
crate struct LazyPerDefTables<'tcx> {
239-
pub kind: Lazy!(PerDefTable<Lazy!(EntryKind<'tcx>)>),
240-
pub visibility: Lazy!(PerDefTable<Lazy<ty::Visibility>>),
241-
pub span: Lazy!(PerDefTable<Lazy<Span>>),
242-
pub attributes: Lazy!(PerDefTable<Lazy<[ast::Attribute]>>),
243-
pub children: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
244-
pub stability: Lazy!(PerDefTable<Lazy<attr::Stability>>),
245-
pub deprecation: Lazy!(PerDefTable<Lazy<attr::Deprecation>>),
246-
247-
pub ty: Lazy!(PerDefTable<Lazy!(Ty<'tcx>)>),
248-
pub fn_sig: Lazy!(PerDefTable<Lazy!(ty::PolyFnSig<'tcx>)>),
249-
pub impl_trait_ref: Lazy!(PerDefTable<Lazy!(ty::TraitRef<'tcx>)>),
250-
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
251-
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
252-
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
253-
pub explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
239+
kind: Lazy!(PerDefTable<Lazy!(EntryKind<'tcx>)>),
240+
visibility: Lazy!(PerDefTable<Lazy<ty::Visibility>>),
241+
span: Lazy!(PerDefTable<Lazy<Span>>),
242+
attributes: Lazy!(PerDefTable<Lazy<[ast::Attribute]>>),
243+
children: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
244+
stability: Lazy!(PerDefTable<Lazy<attr::Stability>>),
245+
deprecation: Lazy!(PerDefTable<Lazy<attr::Deprecation>>),
246+
ty: Lazy!(PerDefTable<Lazy!(Ty<'tcx>)>),
247+
fn_sig: Lazy!(PerDefTable<Lazy!(ty::PolyFnSig<'tcx>)>),
248+
impl_trait_ref: Lazy!(PerDefTable<Lazy!(ty::TraitRef<'tcx>)>),
249+
inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
250+
variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
251+
generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
252+
explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
254253
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
255254
// doesn't handle shorthands in its own (de)serialization impls,
256255
// as it's an `enum` for which we want to derive (de)serialization,
257256
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
258257
// Also, as an optimization, a missing entry indicates an empty `&[]`.
259-
pub inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
260-
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
261-
262-
pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
263-
pub promoted_mir: Lazy!(PerDefTable<Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>),
258+
inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
259+
super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
260+
mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
261+
promoted_mir: Lazy!(PerDefTable<Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>),
264262
}
265263

266264
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
267-
crate enum EntryKind<'tcx> {
265+
enum EntryKind<'tcx> {
268266
Const(ConstQualif, Lazy<RenderedConst>),
269267
ImmStatic,
270268
MutStatic,
@@ -299,18 +297,18 @@ crate enum EntryKind<'tcx> {
299297

300298
/// Additional data for EntryKind::Const and EntryKind::AssocConst
301299
#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
302-
crate struct ConstQualif {
303-
pub mir: u8,
300+
struct ConstQualif {
301+
mir: u8,
304302
}
305303

306304
/// Contains a constant which has been rendered to a String.
307305
/// Used by rustdoc.
308306
#[derive(RustcEncodable, RustcDecodable)]
309-
crate struct RenderedConst(pub String);
307+
struct RenderedConst(String);
310308

311309
#[derive(RustcEncodable, RustcDecodable)]
312-
crate struct ModData {
313-
pub reexports: Lazy<[def::Export<hir::HirId>]>,
310+
struct ModData {
311+
reexports: Lazy<[def::Export<hir::HirId>]>,
314312
}
315313

316314
#[derive(RustcEncodable, RustcDecodable)]
@@ -320,53 +318,53 @@ crate struct MacroDef {
320318
}
321319

322320
#[derive(RustcEncodable, RustcDecodable)]
323-
crate struct FnData {
324-
pub asyncness: hir::IsAsync,
325-
pub constness: hir::Constness,
326-
pub param_names: Lazy<[ast::Name]>,
321+
struct FnData {
322+
asyncness: hir::IsAsync,
323+
constness: hir::Constness,
324+
param_names: Lazy<[ast::Name]>,
327325
}
328326

329327
#[derive(RustcEncodable, RustcDecodable)]
330-
crate struct VariantData {
331-
pub ctor_kind: CtorKind,
332-
pub discr: ty::VariantDiscr,
328+
struct VariantData {
329+
ctor_kind: CtorKind,
330+
discr: ty::VariantDiscr,
333331
/// If this is unit or tuple-variant/struct, then this is the index of the ctor id.
334-
pub ctor: Option<DefIndex>,
332+
ctor: Option<DefIndex>,
335333
}
336334

337335
#[derive(RustcEncodable, RustcDecodable)]
338-
crate struct TraitData {
339-
pub unsafety: hir::Unsafety,
340-
pub paren_sugar: bool,
341-
pub has_auto_impl: bool,
342-
pub is_marker: bool,
336+
struct TraitData {
337+
unsafety: hir::Unsafety,
338+
paren_sugar: bool,
339+
has_auto_impl: bool,
340+
is_marker: bool,
343341
}
344342

345343
#[derive(RustcEncodable, RustcDecodable)]
346-
crate struct ImplData {
347-
pub polarity: ty::ImplPolarity,
348-
pub defaultness: hir::Defaultness,
349-
pub parent_impl: Option<DefId>,
344+
struct ImplData {
345+
polarity: ty::ImplPolarity,
346+
defaultness: hir::Defaultness,
347+
parent_impl: Option<DefId>,
350348

351349
/// This is `Some` only for impls of `CoerceUnsized`.
352350
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
353-
pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
351+
coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
354352
}
355353

356354

357355
/// Describes whether the container of an associated item
358356
/// is a trait or an impl and whether, in a trait, it has
359357
/// a default, or an in impl, whether it's marked "default".
360358
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
361-
crate enum AssocContainer {
359+
enum AssocContainer {
362360
TraitRequired,
363361
TraitWithDefault,
364362
ImplDefault,
365363
ImplFinal,
366364
}
367365

368366
impl AssocContainer {
369-
crate fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer {
367+
fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer {
370368
match *self {
371369
AssocContainer::TraitRequired |
372370
AssocContainer::TraitWithDefault => ty::TraitContainer(def_id),
@@ -376,7 +374,7 @@ impl AssocContainer {
376374
}
377375
}
378376

379-
crate fn defaultness(&self) -> hir::Defaultness {
377+
fn defaultness(&self) -> hir::Defaultness {
380378
match *self {
381379
AssocContainer::TraitRequired => hir::Defaultness::Default {
382380
has_value: false,
@@ -393,17 +391,17 @@ impl AssocContainer {
393391
}
394392

395393
#[derive(RustcEncodable, RustcDecodable)]
396-
crate struct MethodData {
397-
pub fn_data: FnData,
398-
pub container: AssocContainer,
399-
pub has_self: bool,
394+
struct MethodData {
395+
fn_data: FnData,
396+
container: AssocContainer,
397+
has_self: bool,
400398
}
401399

402400
#[derive(RustcEncodable, RustcDecodable)]
403-
crate struct GeneratorData<'tcx> {
404-
pub layout: mir::GeneratorLayout<'tcx>,
401+
struct GeneratorData<'tcx> {
402+
layout: mir::GeneratorLayout<'tcx>,
405403
}
406404

407405
// Tags used for encoding Spans:
408-
crate const TAG_VALID_SPAN: u8 = 0;
409-
crate const TAG_INVALID_SPAN: u8 = 1;
406+
const TAG_VALID_SPAN: u8 = 0;
407+
const TAG_INVALID_SPAN: u8 = 1;

src/librustc_metadata/schema/table.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use log::debug;
1111
/// Used mainly for Lazy positions and lengths.
1212
/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
1313
/// but this has no impact on safety.
14-
crate trait FixedSizeEncoding: Default {
14+
pub(super) trait FixedSizeEncoding: Default {
1515
const BYTE_LEN: usize;
1616

1717
// FIXME(eddyb) convert to and from `[u8; Self::BYTE_LEN]` instead,
@@ -125,7 +125,7 @@ impl<T: Encodable> FixedSizeEncoding for Option<Lazy<[T]>> {
125125
// FIXME(eddyb) replace `Vec` with `[_]` here, such that `Box<Table<T>>` would be used
126126
// when building it, and `Lazy<Table<T>>` or `&Table<T>` when reading it.
127127
// (not sure if that is possible given that the `Vec` is being resized now)
128-
crate struct Table<T> where Option<T>: FixedSizeEncoding {
128+
pub(super) struct Table<T> where Option<T>: FixedSizeEncoding {
129129
// FIXME(eddyb) store `[u8; <Option<T>>::BYTE_LEN]` instead of `u8` in `Vec`,
130130
// once that starts being allowed by the compiler (i.e. lazy normalization).
131131
bytes: Vec<u8>,
@@ -142,7 +142,7 @@ impl<T> Default for Table<T> where Option<T>: FixedSizeEncoding {
142142
}
143143

144144
impl<T> Table<T> where Option<T>: FixedSizeEncoding {
145-
crate fn set(&mut self, i: usize, value: T) {
145+
fn set(&mut self, i: usize, value: T) {
146146
// FIXME(eddyb) investigate more compact encodings for sparse tables.
147147
// On the PR @michaelwoerister mentioned:
148148
// > Space requirements could perhaps be optimized by using the HAMT `popcnt`
@@ -156,7 +156,7 @@ impl<T> Table<T> where Option<T>: FixedSizeEncoding {
156156
Some(value).write_to_bytes_at(&mut self.bytes, i);
157157
}
158158

159-
crate fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
159+
fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
160160
let pos = buf.position();
161161
buf.emit_raw_bytes(&self.bytes);
162162
Lazy::from_position_and_meta(
@@ -177,7 +177,7 @@ impl<T> LazyMeta for Table<T> where Option<T>: FixedSizeEncoding {
177177
impl<T> Lazy<Table<T>> where Option<T>: FixedSizeEncoding {
178178
/// Given the metadata, extract out the value at a particular index (if any).
179179
#[inline(never)]
180-
crate fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
180+
fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
181181
&self,
182182
metadata: M,
183183
i: usize,
@@ -193,7 +193,7 @@ impl<T> Lazy<Table<T>> where Option<T>: FixedSizeEncoding {
193193
/// Like a `Table` but using `DefIndex` instead of `usize` as keys.
194194
// FIXME(eddyb) replace by making `Table` behave like `IndexVec`,
195195
// and by using `newtype_index!` to define `DefIndex`.
196-
crate struct PerDefTable<T>(Table<T>) where Option<T>: FixedSizeEncoding;
196+
pub(super) struct PerDefTable<T>(Table<T>) where Option<T>: FixedSizeEncoding;
197197

198198
impl<T> Default for PerDefTable<T> where Option<T>: FixedSizeEncoding {
199199
fn default() -> Self {
@@ -202,12 +202,12 @@ impl<T> Default for PerDefTable<T> where Option<T>: FixedSizeEncoding {
202202
}
203203

204204
impl<T> PerDefTable<T> where Option<T>: FixedSizeEncoding {
205-
crate fn set(&mut self, def_id: DefId, value: T) {
205+
pub(super) fn set(&mut self, def_id: DefId, value: T) {
206206
assert!(def_id.is_local());
207207
self.0.set(def_id.index.index(), value);
208208
}
209209

210-
crate fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
210+
pub(super) fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
211211
let lazy = self.0.encode(buf);
212212
Lazy::from_position_and_meta(lazy.position, lazy.meta)
213213
}
@@ -228,7 +228,7 @@ impl<T> Lazy<PerDefTable<T>> where Option<T>: FixedSizeEncoding {
228228

229229
/// Given the metadata, extract out the value at a particular DefIndex (if any).
230230
#[inline(never)]
231-
crate fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
231+
pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
232232
&self,
233233
metadata: M,
234234
def_index: DefIndex,

0 commit comments

Comments
 (0)