Skip to content

Commit

Permalink
Reduce visibilities.
Browse files Browse the repository at this point in the history
Three of the modules don't need to be `pub`, and then
`warn(unreachable_pub)` identifies a bunch more things that also
shouldn't be `pub`, plus a couple of things that are unused.
  • Loading branch information
nnethercote committed Oct 6, 2024
1 parent 7a9bbd0 commit 5486d72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 52 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligat
pub mod at;
pub mod canonical;
mod context;
pub mod free_regions;
mod free_regions;
mod freshen;
mod lexical_region_resolve;
pub mod opaque_types;
mod opaque_types;
pub mod outlives;
mod projection;
pub mod region_constraints;
pub mod relate;
pub mod resolve;
pub(crate) mod snapshot;
pub mod type_variable;
mod type_variable;

#[must_use]
#[derive(Debug)]
Expand Down
24 changes: 5 additions & 19 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::traits::{self, Obligation};

mod table;

pub type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
pub use table::{OpaqueTypeStorage, OpaqueTypeTable};
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};

use super::DefineOpaqueTypes;

Expand Down Expand Up @@ -377,9 +377,9 @@ impl<'tcx> InferCtxt<'tcx> {
///
/// We ignore any type parameters because impl trait values are assumed to
/// capture all the in-scope type parameters.
pub struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
pub tcx: TyCtxt<'tcx>,
pub op: OP,
struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
tcx: TyCtxt<'tcx>,
op: OP,
}

impl<'tcx, OP> TypeVisitor<TyCtxt<'tcx>> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP>
Expand Down Expand Up @@ -455,20 +455,6 @@ where
}
}

pub enum UseKind {
DefiningUse,
OpaqueUse,
}

impl UseKind {
pub fn is_defining(self) -> bool {
match self {
UseKind::DefiningUse => true,
UseKind::OpaqueUse => false,
}
}
}

impl<'tcx> InferCtxt<'tcx> {
#[instrument(skip(self), level = "debug")]
fn register_hidden_type(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/opaque_types/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{OpaqueTypeDecl, OpaqueTypeMap};
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};

#[derive(Default, Debug, Clone)]
pub struct OpaqueTypeStorage<'tcx> {
pub(crate) struct OpaqueTypeStorage<'tcx> {
/// Opaque types found in explicit return types and their
/// associated fresh inference variable. Writeback resolves these
/// variables to get the concrete type, which can be used to
Expand Down
45 changes: 16 additions & 29 deletions compiler/rustc_infer/src/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariabl
}

#[derive(Clone)]
pub struct TypeVariableStorage<'tcx> {
pub(crate) struct TypeVariableStorage<'tcx> {
/// The origins of each type variable.
values: IndexVec<TyVid, TypeVariableData>,
/// Two variables are unified in `eq_relations` when we have a
Expand All @@ -29,7 +29,7 @@ pub struct TypeVariableStorage<'tcx> {
eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
}

pub struct TypeVariableTable<'a, 'tcx> {
pub(crate) struct TypeVariableTable<'a, 'tcx> {
storage: &'a mut TypeVariableStorage<'tcx>,

undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
Expand All @@ -50,22 +50,22 @@ pub(crate) struct TypeVariableData {
}

#[derive(Copy, Clone, Debug)]
pub enum TypeVariableValue<'tcx> {
pub(crate) enum TypeVariableValue<'tcx> {
Known { value: Ty<'tcx> },
Unknown { universe: ty::UniverseIndex },
}

impl<'tcx> TypeVariableValue<'tcx> {
/// If this value is known, returns the type it is known to be.
/// Otherwise, `None`.
pub fn known(&self) -> Option<Ty<'tcx>> {
pub(crate) fn known(&self) -> Option<Ty<'tcx>> {
match *self {
TypeVariableValue::Unknown { .. } => None,
TypeVariableValue::Known { value } => Some(value),
}
}

pub fn is_unknown(&self) -> bool {
pub(crate) fn is_unknown(&self) -> bool {
match *self {
TypeVariableValue::Unknown { .. } => true,
TypeVariableValue::Known { .. } => false,
Expand All @@ -74,7 +74,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
}

impl<'tcx> TypeVariableStorage<'tcx> {
pub fn new() -> TypeVariableStorage<'tcx> {
pub(crate) fn new() -> TypeVariableStorage<'tcx> {
TypeVariableStorage {
values: Default::default(),
eq_relations: ut::UnificationTableStorage::new(),
Expand Down Expand Up @@ -105,14 +105,14 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
///
/// Note that this function does not return care whether
/// `vid` has been unified with something else or not.
pub fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
pub(crate) fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
self.storage.values[vid].origin
}

/// Records that `a == b`, depending on `dir`.
///
/// Precondition: neither `a` nor `b` are known.
pub fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
pub(crate) fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
debug_assert!(self.probe(a).is_unknown());
debug_assert!(self.probe(b).is_unknown());
self.eq_relations().union(a, b);
Expand All @@ -121,7 +121,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
/// Instantiates `vid` with the type `ty`.
///
/// Precondition: `vid` must not have been previously instantiated.
pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
pub(crate) fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
let vid = self.root_var(vid);
debug_assert!(!ty.is_ty_var(), "instantiating ty var with var: {vid:?} {ty:?}");
debug_assert!(self.probe(vid).is_unknown());
Expand All @@ -143,7 +143,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
/// - `origin`: indicates *why* the type variable was created.
/// The code in this module doesn't care, but it can be useful
/// for improving error messages.
pub fn new_var(
pub(crate) fn new_var(
&mut self,
universe: ty::UniverseIndex,
origin: TypeVariableOrigin,
Expand All @@ -158,7 +158,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
}

/// Returns the number of type variables created thus far.
pub fn num_vars(&self) -> usize {
pub(crate) fn num_vars(&self) -> usize {
self.storage.values.len()
}

Expand All @@ -167,42 +167,29 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
/// will yield the same root variable (per the union-find
/// algorithm), so `root_var(a) == root_var(b)` implies that `a ==
/// b` (transitively).
pub fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
pub(crate) fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
self.eq_relations().find(vid).vid
}

/// Retrieves the type to which `vid` has been instantiated, if
/// any.
pub fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
pub(crate) fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
self.inlined_probe(vid)
}

/// An always-inlined variant of `probe`, for very hot call sites.
#[inline(always)]
pub fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
pub(crate) fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
self.eq_relations().inlined_probe_value(vid)
}

/// If `t` is a type-inference variable, and it has been
/// instantiated, then return the with which it was
/// instantiated. Otherwise, returns `t`.
pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
match *t.kind() {
ty::Infer(ty::TyVar(v)) => match self.probe(v) {
TypeVariableValue::Unknown { .. } => t,
TypeVariableValue::Known { value } => value,
},
_ => t,
}
}

#[inline]
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
self.storage.eq_relations.with_log(self.undo_log)
}

/// Returns a range of the type variables created during the snapshot.
pub fn vars_since_snapshot(
pub(crate) fn vars_since_snapshot(
&mut self,
value_count: usize,
) -> (Range<TyVid>, Vec<TypeVariableOrigin>) {
Expand All @@ -215,7 +202,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {

/// Returns indices of all variables that are not yet
/// instantiated.
pub fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
pub(crate) fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
(0..self.num_vars())
.filter_map(|i| {
let vid = ty::TyVid::from_usize(i);
Expand Down

0 comments on commit 5486d72

Please sign in to comment.