Make untracked.source_span lockable so that resolution can still write to it when using TyCtxt

This commit is contained in:
Oli Scherer 2022-12-08 11:02:47 +00:00
parent ade3dceb38
commit 6924e3c374
6 changed files with 12 additions and 12 deletions

View file

@ -1026,7 +1026,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// system if the result is otherwise tracked through queries /// system if the result is otherwise tracked through queries
#[inline] #[inline]
pub fn source_span_untracked(self, def_id: LocalDefId) -> Span { pub fn source_span_untracked(self, def_id: LocalDefId) -> Span {
self.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP) self.untracked.source_span.read().get(def_id).copied().unwrap_or(DUMMY_SP)
} }
#[inline(always)] #[inline(always)]
@ -2518,5 +2518,5 @@ pub fn provide(providers: &mut ty::query::Providers) {
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local()) tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
}; };
providers.source_span = providers.source_span =
|tcx, def_id| tcx.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP); |tcx, def_id| tcx.untracked.source_span.read().get(def_id).copied().unwrap_or(DUMMY_SP);
} }

View file

@ -146,7 +146,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
#[inline] #[inline]
fn def_span(&self, def_id: LocalDefId) -> Span { fn def_span(&self, def_id: LocalDefId) -> Span {
*self.untracked.source_span.get(def_id).unwrap_or(&DUMMY_SP) *self.untracked.source_span.read().get(def_id).unwrap_or(&DUMMY_SP)
} }
#[inline] #[inline]

View file

@ -155,7 +155,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if !candidates.is_empty() { if !candidates.is_empty() {
show_candidates( show_candidates(
&self.tcx.sess, &self.tcx.sess,
&self.untracked.source_span, &self.untracked.source_span.read(),
&mut err, &mut err,
span, span,
&candidates, &candidates,
@ -688,7 +688,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} }
show_candidates( show_candidates(
&self.tcx.sess, &self.tcx.sess,
&self.untracked.source_span, &self.untracked.source_span.read(),
&mut err, &mut err,
Some(span), Some(span),
&import_suggestions, &import_suggestions,
@ -1353,7 +1353,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected); self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
show_candidates( show_candidates(
&self.tcx.sess, &self.tcx.sess,
&self.untracked.source_span, &self.untracked.source_span.read(),
err, err,
None, None,
&import_suggestions, &import_suggestions,

View file

@ -549,7 +549,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
match &import.kind { match &import.kind {
ImportKind::Single { nested: false, source, target, .. } => import_candidates( ImportKind::Single { nested: false, source, target, .. } => import_candidates(
self.r.tcx.sess, self.r.tcx.sess,
&self.r.untracked.source_span, &self.r.untracked.source_span.read(),
&mut diag, &mut diag,
Some(err.span), Some(err.span),
&candidates, &candidates,
@ -562,7 +562,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
ImportKind::Single { nested: true, source, target, .. } => { ImportKind::Single { nested: true, source, target, .. } => {
import_candidates( import_candidates(
self.r.tcx.sess, self.r.tcx.sess,
&self.r.untracked.source_span, &self.r.untracked.source_span.read(),
&mut diag, &mut diag,
None, None,
&candidates, &candidates,

View file

@ -1180,7 +1180,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
// A relative span's parent must be an absolute span. // A relative span's parent must be an absolute span.
debug_assert_eq!(span.data_untracked().parent, None); debug_assert_eq!(span.data_untracked().parent, None);
let _id = self.untracked.source_span.push(span); let _id = self.untracked.source_span.write().push(span);
debug_assert_eq!(_id, def_id); debug_assert_eq!(_id, def_id);
// Some things for which we allocate `LocalDefId`s don't correspond to // Some things for which we allocate `LocalDefId`s don't correspond to
@ -1329,7 +1329,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
used_extern_options: Default::default(), used_extern_options: Default::default(),
untracked: Untracked { untracked: Untracked {
cstore: RwLock::new(Box::new(CStore::new(session))), cstore: RwLock::new(Box::new(CStore::new(session))),
source_span, source_span: RwLock::new(source_span),
definitions: RwLock::new(definitions), definitions: RwLock::new(definitions),
}, },
macro_names: FxHashSet::default(), macro_names: FxHashSet::default(),
@ -1932,7 +1932,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate. /// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
#[inline] #[inline]
fn opt_span(&self, def_id: DefId) -> Option<Span> { fn opt_span(&self, def_id: DefId) -> Option<Span> {
def_id.as_local().map(|def_id| self.untracked.source_span[def_id]) def_id.as_local().map(|def_id| self.untracked.source_span.read()[def_id])
} }
/// Retrieves the name of the given `DefId`. /// Retrieves the name of the given `DefId`.

View file

@ -256,6 +256,6 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync + sync::Send;
pub struct Untracked { pub struct Untracked {
pub cstore: RwLock<Box<CrateStoreDyn>>, pub cstore: RwLock<Box<CrateStoreDyn>>,
/// Reference span for definitions. /// Reference span for definitions.
pub source_span: IndexVec<LocalDefId, Span>, pub source_span: RwLock<IndexVec<LocalDefId, Span>>,
pub definitions: RwLock<Definitions>, pub definitions: RwLock<Definitions>,
} }