1
Fork 0

Minimize pub usage in hygiene.rs.

And remove dead functions revealed by this.
This commit is contained in:
Nicholas Nethercote 2023-11-01 14:00:42 +11:00
parent 16e9713e60
commit 222c22356b
2 changed files with 16 additions and 35 deletions

View file

@ -127,7 +127,7 @@ impl ExpnHash {
/// Returns the crate-local part of the [ExpnHash]. /// Returns the crate-local part of the [ExpnHash].
/// ///
/// Used for tests. /// Used for assertions.
#[inline] #[inline]
pub fn local_hash(self) -> Hash64 { pub fn local_hash(self) -> Hash64 {
self.0.split().1 self.0.split().1
@ -170,7 +170,7 @@ impl LocalExpnId {
pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0); pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0);
#[inline] #[inline]
pub fn from_raw(idx: ExpnIndex) -> LocalExpnId { fn from_raw(idx: ExpnIndex) -> LocalExpnId {
LocalExpnId::from_u32(idx.as_u32()) LocalExpnId::from_u32(idx.as_u32())
} }
@ -201,11 +201,6 @@ impl LocalExpnId {
}) })
} }
#[inline]
pub fn expn_hash(self) -> ExpnHash {
HygieneData::with(|data| data.local_expn_hash(self))
}
#[inline] #[inline]
pub fn expn_data(self) -> ExpnData { pub fn expn_data(self) -> ExpnData {
HygieneData::with(|data| data.local_expn_data(self).clone()) HygieneData::with(|data| data.local_expn_data(self).clone())
@ -236,13 +231,6 @@ impl LocalExpnId {
self.to_expn_id().is_descendant_of(ancestor.to_expn_id()) self.to_expn_id().is_descendant_of(ancestor.to_expn_id())
} }
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
#[inline]
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
self.to_expn_id().outer_expn_is_descendant_of(ctxt)
}
/// Returns span for the macro which originally caused this expansion to happen. /// Returns span for the macro which originally caused this expansion to happen.
/// ///
/// Stops backtracing at include! boundary. /// Stops backtracing at include! boundary.
@ -250,12 +238,6 @@ impl LocalExpnId {
pub fn expansion_cause(self) -> Option<Span> { pub fn expansion_cause(self) -> Option<Span> {
self.to_expn_id().expansion_cause() self.to_expn_id().expansion_cause()
} }
#[inline]
#[track_caller]
pub fn parent(self) -> LocalExpnId {
self.expn_data().parent.as_local().unwrap()
}
} }
impl ExpnId { impl ExpnId {
@ -330,7 +312,7 @@ impl ExpnId {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct HygieneData { pub(crate) struct HygieneData {
/// Each expansion should have an associated expansion data, but sometimes there's a delay /// Each expansion should have an associated expansion data, but sometimes there's a delay
/// between creation of an expansion ID and obtaining its data (e.g. macros are collected /// between creation of an expansion ID and obtaining its data (e.g. macros are collected
/// first and then resolved later), so we use an `Option` here. /// first and then resolved later), so we use an `Option` here.
@ -381,15 +363,10 @@ impl HygieneData {
} }
} }
pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T { fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut())) with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
} }
#[inline]
fn local_expn_hash(&self, expn_id: LocalExpnId) -> ExpnHash {
self.local_expn_hashes[expn_id]
}
#[inline] #[inline]
fn expn_hash(&self, expn_id: ExpnId) -> ExpnHash { fn expn_hash(&self, expn_id: ExpnId) -> ExpnHash {
match expn_id.as_local() { match expn_id.as_local() {
@ -743,7 +720,7 @@ impl SyntaxContext {
} }
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0. /// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> { pub(crate) fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
HygieneData::with(|data| { HygieneData::with(|data| {
*self = data.normalize_to_macros_2_0(*self); *self = data.normalize_to_macros_2_0(*self);
data.adjust(self, expn_id) data.adjust(self, expn_id)
@ -776,7 +753,11 @@ impl SyntaxContext {
/// ``` /// ```
/// This returns `None` if the context cannot be glob-adjusted. /// This returns `None` if the context cannot be glob-adjusted.
/// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details). /// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details).
pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> { pub(crate) fn glob_adjust(
&mut self,
expn_id: ExpnId,
glob_span: Span,
) -> Option<Option<ExpnId>> {
HygieneData::with(|data| { HygieneData::with(|data| {
let mut scope = None; let mut scope = None;
let mut glob_ctxt = data.normalize_to_macros_2_0(glob_span.ctxt()); let mut glob_ctxt = data.normalize_to_macros_2_0(glob_span.ctxt());
@ -800,7 +781,7 @@ impl SyntaxContext {
/// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope)); /// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
/// } /// }
/// ``` /// ```
pub fn reverse_glob_adjust( pub(crate) fn reverse_glob_adjust(
&mut self, &mut self,
expn_id: ExpnId, expn_id: ExpnId,
glob_span: Span, glob_span: Span,
@ -855,11 +836,11 @@ impl SyntaxContext {
} }
#[inline] #[inline]
pub fn outer_mark(self) -> (ExpnId, Transparency) { fn outer_mark(self) -> (ExpnId, Transparency) {
HygieneData::with(|data| data.outer_mark(self)) HygieneData::with(|data| data.outer_mark(self))
} }
pub fn dollar_crate_name(self) -> Symbol { pub(crate) fn dollar_crate_name(self) -> Symbol {
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name) HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
} }
@ -958,12 +939,12 @@ pub struct ExpnData {
/// The normal module (`mod`) in which the expanded macro was defined. /// The normal module (`mod`) in which the expanded macro was defined.
pub parent_module: Option<DefId>, pub parent_module: Option<DefId>,
/// Suppresses the `unsafe_code` lint for code produced by this macro. /// Suppresses the `unsafe_code` lint for code produced by this macro.
pub allow_internal_unsafe: bool, pub(crate) allow_internal_unsafe: bool,
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro. /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
pub local_inner_macros: bool, pub local_inner_macros: bool,
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other /// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)? /// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
pub collapse_debuginfo: bool, pub(crate) collapse_debuginfo: bool,
} }
impl !PartialEq for ExpnData {} impl !PartialEq for ExpnData {}

View file

@ -954,7 +954,7 @@ impl Span {
/// Produces a span with the same location as `self` and context produced by a macro with the /// Produces a span with the same location as `self` and context produced by a macro with the
/// given ID and transparency, assuming that macro was defined directly and not produced by /// given ID and transparency, assuming that macro was defined directly and not produced by
/// some other macro (which is the case for built-in and procedural macros). /// some other macro (which is the case for built-in and procedural macros).
pub fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span { fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
self.with_ctxt(SyntaxContext::root().apply_mark(expn_id, transparency)) self.with_ctxt(SyntaxContext::root().apply_mark(expn_id, transparency))
} }