1
Fork 0

Remove crate visibility usage in compiler

This commit is contained in:
Jacob Pratt 2022-05-20 19:51:09 -04:00
parent 536020c5f9
commit 49c82f31a8
No known key found for this signature in database
GPG key ID: B80E19E4662B5AA4
186 changed files with 865 additions and 800 deletions

View file

@ -70,7 +70,7 @@ pub enum LoadedMacro {
ProcMacro(SyntaxExtension),
}
crate struct Library {
pub(crate) struct Library {
pub source: CrateSource,
pub metadata: MetadataBlob,
}
@ -82,7 +82,7 @@ enum LoadResult {
/// A reference to `CrateMetadata` that can also give access to whole crate store when necessary.
#[derive(Clone, Copy)]
crate struct CrateMetadataRef<'a> {
pub(crate) struct CrateMetadataRef<'a> {
pub cdata: &'a CrateMetadata,
pub cstore: &'a CStore,
}
@ -133,7 +133,7 @@ impl CStore {
CrateNum::new(self.metas.len() - 1)
}
crate fn get_crate_data(&self, cnum: CrateNum) -> CrateMetadataRef<'_> {
pub(crate) fn get_crate_data(&self, cnum: CrateNum) -> CrateMetadataRef<'_> {
let cdata = self.metas[cnum]
.as_ref()
.unwrap_or_else(|| panic!("Failed to get crate data for {:?}", cnum));
@ -145,7 +145,7 @@ impl CStore {
self.metas[cnum] = Some(Lrc::new(data));
}
crate fn iter_crate_data(&self) -> impl Iterator<Item = (CrateNum, &CrateMetadata)> {
pub(crate) fn iter_crate_data(&self) -> impl Iterator<Item = (CrateNum, &CrateMetadata)> {
self.metas
.iter_enumerated()
.filter_map(|(cnum, data)| data.as_ref().map(|data| (cnum, &**data)))
@ -164,7 +164,7 @@ impl CStore {
}
}
crate fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
pub(crate) fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
let mut deps = Vec::new();
if cnum == LOCAL_CRATE {
for (cnum, _) in self.iter_crate_data() {
@ -182,15 +182,15 @@ impl CStore {
deps
}
crate fn injected_panic_runtime(&self) -> Option<CrateNum> {
pub(crate) fn injected_panic_runtime(&self) -> Option<CrateNum> {
self.injected_panic_runtime
}
crate fn allocator_kind(&self) -> Option<AllocatorKind> {
pub(crate) fn allocator_kind(&self) -> Option<AllocatorKind> {
self.allocator_kind
}
crate fn has_global_allocator(&self) -> bool {
pub(crate) fn has_global_allocator(&self) -> bool {
self.has_global_allocator
}

View file

@ -62,7 +62,7 @@ use rustc_session::cstore::CrateDepKind;
use rustc_session::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};
use rustc_target::spec::PanicStrategy;
crate fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
pub(crate) fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
tcx.sess
.crate_types()
.iter()

View file

@ -3,7 +3,7 @@ use rustc_hir::def::DefKind;
use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::ForeignModule;
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
let mut modules = Vec::new();
for id in tcx.hir().items() {
if !matches!(tcx.def_kind(id.def_id), DefKind::ForeignMod) {

View file

@ -1,5 +1,4 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(drain_filter)]
#![feature(generators)]

View file

@ -239,7 +239,7 @@ use std::{cmp, fmt, fs};
use tracing::{debug, info};
#[derive(Clone)]
crate struct CrateLocator<'a> {
pub(crate) struct CrateLocator<'a> {
// Immutable per-session configuration.
only_needs_metadata: bool,
sysroot: &'a Path,
@ -260,19 +260,19 @@ crate struct CrateLocator<'a> {
}
#[derive(Clone)]
crate struct CratePaths {
pub(crate) struct CratePaths {
name: Symbol,
source: CrateSource,
}
impl CratePaths {
crate fn new(name: Symbol, source: CrateSource) -> CratePaths {
pub(crate) fn new(name: Symbol, source: CrateSource) -> CratePaths {
CratePaths { name, source }
}
}
#[derive(Copy, Clone, PartialEq)]
crate enum CrateFlavor {
pub(crate) enum CrateFlavor {
Rlib,
Rmeta,
Dylib,
@ -289,7 +289,7 @@ impl fmt::Display for CrateFlavor {
}
impl<'a> CrateLocator<'a> {
crate fn new(
pub(crate) fn new(
sess: &'a Session,
metadata_loader: &'a dyn MetadataLoader,
crate_name: Symbol,
@ -344,7 +344,7 @@ impl<'a> CrateLocator<'a> {
}
}
crate fn reset(&mut self) {
pub(crate) fn reset(&mut self) {
self.crate_rejections.via_hash.clear();
self.crate_rejections.via_triple.clear();
self.crate_rejections.via_kind.clear();
@ -353,7 +353,7 @@ impl<'a> CrateLocator<'a> {
self.crate_rejections.via_invalid.clear();
}
crate fn maybe_load_library_crate(&mut self) -> Result<Option<Library>, CrateError> {
pub(crate) fn maybe_load_library_crate(&mut self) -> Result<Option<Library>, CrateError> {
if !self.exact_paths.is_empty() {
return self.find_commandline_library();
}
@ -728,7 +728,7 @@ impl<'a> CrateLocator<'a> {
Ok(self.extract_lib(rlibs, rmetas, dylibs)?.map(|(_, lib)| lib))
}
crate fn into_error(self, root: Option<CratePaths>) -> CrateError {
pub(crate) fn into_error(self, root: Option<CratePaths>) -> CrateError {
CrateError::LocatorCombined(CombinedLocatorError {
crate_name: self.crate_name,
root,
@ -894,7 +894,7 @@ struct CrateRejections {
/// Candidate rejection reasons collected during crate search.
/// If no candidate is accepted, then these reasons are presented to the user,
/// otherwise they are ignored.
crate struct CombinedLocatorError {
pub(crate) struct CombinedLocatorError {
crate_name: Symbol,
root: Option<CratePaths>,
triple: TargetTriple,
@ -903,7 +903,7 @@ crate struct CombinedLocatorError {
crate_rejections: CrateRejections,
}
crate enum CrateError {
pub(crate) enum CrateError {
NonAsciiName(Symbol),
ExternLocationNotExist(Symbol, PathBuf),
ExternLocationNotFile(Symbol, PathBuf),
@ -937,7 +937,7 @@ impl fmt::Display for MetadataError<'_> {
}
impl CrateError {
crate fn report(self, sess: &Session, span: Span, missing_core: bool) {
pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
let mut diag = match self {
CrateError::NonAsciiName(crate_name) => sess.struct_span_err(
span,

View file

@ -12,7 +12,7 @@ use rustc_session::Session;
use rustc_span::symbol::{sym, Symbol};
use rustc_target::spec::abi::Abi;
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
let mut collector = Collector { tcx, libs: Vec::new() };
for id in tcx.hir().items() {
collector.process_item(id);
@ -21,7 +21,7 @@ crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
collector.libs
}
crate fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
pub(crate) fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
match lib.cfg {
Some(ref cfg) => attr::cfg_matches(cfg, &sess.parse_sess, CRATE_NODE_ID, None),
None => true,

View file

@ -57,7 +57,7 @@ mod cstore_impl;
/// A `MetadataBlob` internally is just a reference counted pointer to
/// the actual data, so cloning it is cheap.
#[derive(Clone)]
crate struct MetadataBlob(Lrc<MetadataRef>);
pub(crate) struct MetadataBlob(Lrc<MetadataRef>);
// This is needed so we can create an OwningRef into the blob.
// The data behind a `MetadataBlob` has a stable address because it is
@ -78,9 +78,9 @@ impl std::ops::Deref for MetadataBlob {
// local crate numbers (as generated during this session). Each external
// crate may refer to types in other external crates, and each has their
// own crate numbers.
crate type CrateNumMap = IndexVec<CrateNum, CrateNum>;
pub(crate) type CrateNumMap = IndexVec<CrateNum, CrateNum>;
crate struct CrateMetadata {
pub(crate) struct CrateMetadata {
/// The primary crate data - binary metadata blob.
blob: MetadataBlob,
@ -744,20 +744,20 @@ where
implement_ty_decoder!(DecodeContext<'a, 'tcx>);
impl<'tcx> MetadataBlob {
crate fn new(metadata_ref: MetadataRef) -> MetadataBlob {
pub(crate) fn new(metadata_ref: MetadataRef) -> MetadataBlob {
MetadataBlob(Lrc::new(metadata_ref))
}
crate fn is_compatible(&self) -> bool {
pub(crate) fn is_compatible(&self) -> bool {
self.blob().starts_with(METADATA_HEADER)
}
crate fn get_rustc_version(&self) -> String {
pub(crate) fn get_rustc_version(&self) -> String {
Lazy::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 4).unwrap())
.decode(self)
}
crate fn get_root(&self) -> CrateRoot<'tcx> {
pub(crate) fn get_root(&self) -> CrateRoot<'tcx> {
let slice = &self.blob()[..];
let offset = METADATA_HEADER.len();
let pos = (((slice[offset + 0] as u32) << 24)
@ -767,7 +767,7 @@ impl<'tcx> MetadataBlob {
Lazy::<CrateRoot<'tcx>>::from_position(NonZeroUsize::new(pos).unwrap()).decode(self)
}
crate fn list_crate_metadata(&self, out: &mut dyn io::Write) -> io::Result<()> {
pub(crate) fn list_crate_metadata(&self, out: &mut dyn io::Write) -> io::Result<()> {
let root = self.get_root();
writeln!(out, "Crate info:")?;
writeln!(out, "name {}{}", root.name, root.extra_filename)?;
@ -792,27 +792,27 @@ impl<'tcx> MetadataBlob {
}
impl CrateRoot<'_> {
crate fn is_proc_macro_crate(&self) -> bool {
pub(crate) fn is_proc_macro_crate(&self) -> bool {
self.proc_macro_data.is_some()
}
crate fn name(&self) -> Symbol {
pub(crate) fn name(&self) -> Symbol {
self.name
}
crate fn hash(&self) -> Svh {
pub(crate) fn hash(&self) -> Svh {
self.hash
}
crate fn stable_crate_id(&self) -> StableCrateId {
pub(crate) fn stable_crate_id(&self) -> StableCrateId {
self.stable_crate_id
}
crate fn triple(&self) -> &TargetTriple {
pub(crate) fn triple(&self) -> &TargetTriple {
&self.triple
}
crate fn decode_crate_deps<'a>(
pub(crate) fn decode_crate_deps<'a>(
&self,
metadata: &'a MetadataBlob,
) -> impl ExactSizeIterator<Item = CrateDep> + Captures<'a> {
@ -1759,7 +1759,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
impl CrateMetadata {
crate fn new(
pub(crate) fn new(
sess: &Session,
cstore: &CStore,
blob: MetadataBlob,
@ -1819,15 +1819,15 @@ impl CrateMetadata {
cdata
}
crate fn dependencies(&self) -> LockGuard<'_, Vec<CrateNum>> {
pub(crate) fn dependencies(&self) -> LockGuard<'_, Vec<CrateNum>> {
self.dependencies.borrow()
}
crate fn add_dependency(&self, cnum: CrateNum) {
pub(crate) fn add_dependency(&self, cnum: CrateNum) {
self.dependencies.borrow_mut().push(cnum);
}
crate fn update_extern_crate(&self, new_extern_crate: ExternCrate) -> bool {
pub(crate) fn update_extern_crate(&self, new_extern_crate: ExternCrate) -> bool {
let mut extern_crate = self.extern_crate.borrow_mut();
let update = Some(new_extern_crate.rank()) > extern_crate.as_ref().map(ExternCrate::rank);
if update {
@ -1836,59 +1836,59 @@ impl CrateMetadata {
update
}
crate fn source(&self) -> &CrateSource {
pub(crate) fn source(&self) -> &CrateSource {
&*self.source
}
crate fn dep_kind(&self) -> CrateDepKind {
pub(crate) fn dep_kind(&self) -> CrateDepKind {
*self.dep_kind.lock()
}
crate fn update_dep_kind(&self, f: impl FnOnce(CrateDepKind) -> CrateDepKind) {
pub(crate) fn update_dep_kind(&self, f: impl FnOnce(CrateDepKind) -> CrateDepKind) {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
}
crate fn panic_strategy(&self) -> PanicStrategy {
pub(crate) fn panic_strategy(&self) -> PanicStrategy {
self.root.panic_strategy
}
crate fn needs_panic_runtime(&self) -> bool {
pub(crate) fn needs_panic_runtime(&self) -> bool {
self.root.needs_panic_runtime
}
crate fn is_panic_runtime(&self) -> bool {
pub(crate) fn is_panic_runtime(&self) -> bool {
self.root.panic_runtime
}
crate fn is_profiler_runtime(&self) -> bool {
pub(crate) fn is_profiler_runtime(&self) -> bool {
self.root.profiler_runtime
}
crate fn needs_allocator(&self) -> bool {
pub(crate) fn needs_allocator(&self) -> bool {
self.root.needs_allocator
}
crate fn has_global_allocator(&self) -> bool {
pub(crate) fn has_global_allocator(&self) -> bool {
self.root.has_global_allocator
}
crate fn has_default_lib_allocator(&self) -> bool {
pub(crate) fn has_default_lib_allocator(&self) -> bool {
self.root.has_default_lib_allocator
}
crate fn is_proc_macro_crate(&self) -> bool {
pub(crate) fn is_proc_macro_crate(&self) -> bool {
self.root.is_proc_macro_crate()
}
crate fn name(&self) -> Symbol {
pub(crate) fn name(&self) -> Symbol {
self.root.name
}
crate fn stable_crate_id(&self) -> StableCrateId {
pub(crate) fn stable_crate_id(&self) -> StableCrateId {
self.root.stable_crate_id
}
crate fn hash(&self) -> Svh {
pub(crate) fn hash(&self) -> Svh {
self.root.hash
}

View file

@ -6,7 +6,7 @@ use rustc_hir::def_path_hash_map::{Config as HashMapConfig, DefPathHashMap};
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
use rustc_span::def_id::{DefIndex, DefPathHash};
crate enum DefPathHashMapRef<'tcx> {
pub(crate) enum DefPathHashMapRef<'tcx> {
OwnedFromMetadata(odht::HashTable<HashMapConfig, OwningRef<MetadataBlob, [u8]>>),
BorrowedFromTcx(&'tcx DefPathHashMap),
}

View file

@ -36,7 +36,7 @@ use std::num::NonZeroUsize;
pub use decoder::provide_extern;
use decoder::DecodeContext;
crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob};
use encoder::EncodeContext;
pub use encoder::{encode_metadata, EncodedMetadata};
use rustc_span::hygiene::SyntaxContextData;
@ -46,7 +46,7 @@ mod def_path_hash_map;
mod encoder;
mod table;
crate fn rustc_version() -> String {
pub(crate) fn rustc_version() -> String {
format!("rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version"))
}
@ -169,7 +169,7 @@ type ExpnDataTable = Lazy<Table<ExpnIndex, Lazy<ExpnData>>>;
type ExpnHashTable = Lazy<Table<ExpnIndex, Lazy<ExpnHash>>>;
#[derive(MetadataEncodable, MetadataDecodable)]
crate struct ProcMacroData {
pub(crate) struct ProcMacroData {
proc_macro_decls_static: DefIndex,
stability: Option<attr::Stability>,
macros: Lazy<[DefIndex]>,
@ -192,7 +192,7 @@ crate struct ProcMacroData {
/// a normal crate, much of what we serialized would be unusable in addition
/// to being unused.
#[derive(MetadataEncodable, MetadataDecodable)]
crate struct CrateRoot<'tcx> {
pub(crate) struct CrateRoot<'tcx> {
name: Symbol,
triple: TargetTriple,
extra_filename: String,
@ -245,7 +245,7 @@ crate struct CrateRoot<'tcx> {
/// This creates a type-safe way to enforce that we remap the CrateNum between the on-disk
/// representation and the compilation session.
#[derive(Copy, Clone)]
crate struct RawDefId {
pub(crate) struct RawDefId {
krate: u32,
index: u32,
}
@ -265,7 +265,7 @@ impl RawDefId {
}
#[derive(Encodable, Decodable)]
crate struct CrateDep {
pub(crate) struct CrateDep {
pub name: Symbol,
pub hash: Svh,
pub host_hash: Option<Svh>,
@ -274,13 +274,13 @@ crate struct CrateDep {
}
#[derive(MetadataEncodable, MetadataDecodable)]
crate struct TraitImpls {
pub(crate) struct TraitImpls {
trait_id: (u32, DefIndex),
impls: Lazy<[(DefIndex, Option<SimplifiedType>)]>,
}
#[derive(MetadataEncodable, MetadataDecodable)]
crate struct IncoherentImpls {
pub(crate) struct IncoherentImpls {
self_ty: SimplifiedType,
impls: Lazy<[DefIndex]>,
}
@ -289,7 +289,7 @@ crate struct IncoherentImpls {
macro_rules! define_tables {
($($name:ident: Table<$IDX:ty, $T:ty>),+ $(,)?) => {
#[derive(MetadataEncodable, MetadataDecodable)]
crate struct LazyTables<'tcx> {
pub(crate) struct LazyTables<'tcx> {
$($name: Lazy!(Table<$IDX, $T>)),+
}