Skip to content

Commit 6924e3c

Browse files
committed
Make untracked.source_span lockable so that resolution can still write to it when using TyCtxt
1 parent ade3dce commit 6924e3c

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ impl<'tcx> TyCtxt<'tcx> {
10261026
/// system if the result is otherwise tracked through queries
10271027
#[inline]
10281028
pub fn source_span_untracked(self, def_id: LocalDefId) -> Span {
1029-
self.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP)
1029+
self.untracked.source_span.read().get(def_id).copied().unwrap_or(DUMMY_SP)
10301030
}
10311031

10321032
#[inline(always)]
@@ -2518,5 +2518,5 @@ pub fn provide(providers: &mut ty::query::Providers) {
25182518
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
25192519
};
25202520
providers.source_span =
2521-
|tcx, def_id| tcx.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
2521+
|tcx, def_id| tcx.untracked.source_span.read().get(def_id).copied().unwrap_or(DUMMY_SP);
25222522
}

compiler/rustc_query_system/src/ich/hcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
146146

147147
#[inline]
148148
fn def_span(&self, def_id: LocalDefId) -> Span {
149-
*self.untracked.source_span.get(def_id).unwrap_or(&DUMMY_SP)
149+
*self.untracked.source_span.read().get(def_id).unwrap_or(&DUMMY_SP)
150150
}
151151

152152
#[inline]

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
155155
if !candidates.is_empty() {
156156
show_candidates(
157157
&self.tcx.sess,
158-
&self.untracked.source_span,
158+
&self.untracked.source_span.read(),
159159
&mut err,
160160
span,
161161
&candidates,
@@ -688,7 +688,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
688688
}
689689
show_candidates(
690690
&self.tcx.sess,
691-
&self.untracked.source_span,
691+
&self.untracked.source_span.read(),
692692
&mut err,
693693
Some(span),
694694
&import_suggestions,
@@ -1353,7 +1353,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13531353
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
13541354
show_candidates(
13551355
&self.tcx.sess,
1356-
&self.untracked.source_span,
1356+
&self.untracked.source_span.read(),
13571357
err,
13581358
None,
13591359
&import_suggestions,

compiler/rustc_resolve/src/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
549549
match &import.kind {
550550
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
551551
self.r.tcx.sess,
552-
&self.r.untracked.source_span,
552+
&self.r.untracked.source_span.read(),
553553
&mut diag,
554554
Some(err.span),
555555
&candidates,
@@ -562,7 +562,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
562562
ImportKind::Single { nested: true, source, target, .. } => {
563563
import_candidates(
564564
self.r.tcx.sess,
565-
&self.r.untracked.source_span,
565+
&self.r.untracked.source_span.read(),
566566
&mut diag,
567567
None,
568568
&candidates,

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
11801180

11811181
// A relative span's parent must be an absolute span.
11821182
debug_assert_eq!(span.data_untracked().parent, None);
1183-
let _id = self.untracked.source_span.push(span);
1183+
let _id = self.untracked.source_span.write().push(span);
11841184
debug_assert_eq!(_id, def_id);
11851185

11861186
// Some things for which we allocate `LocalDefId`s don't correspond to
@@ -1329,7 +1329,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13291329
used_extern_options: Default::default(),
13301330
untracked: Untracked {
13311331
cstore: RwLock::new(Box::new(CStore::new(session))),
1332-
source_span,
1332+
source_span: RwLock::new(source_span),
13331333
definitions: RwLock::new(definitions),
13341334
},
13351335
macro_names: FxHashSet::default(),
@@ -1932,7 +1932,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19321932
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
19331933
#[inline]
19341934
fn opt_span(&self, def_id: DefId) -> Option<Span> {
1935-
def_id.as_local().map(|def_id| self.untracked.source_span[def_id])
1935+
def_id.as_local().map(|def_id| self.untracked.source_span.read()[def_id])
19361936
}
19371937

19381938
/// Retrieves the name of the given `DefId`.

compiler/rustc_session/src/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,6 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync + sync::Send;
256256
pub struct Untracked {
257257
pub cstore: RwLock<Box<CrateStoreDyn>>,
258258
/// Reference span for definitions.
259-
pub source_span: IndexVec<LocalDefId, Span>,
259+
pub source_span: RwLock<IndexVec<LocalDefId, Span>>,
260260
pub definitions: RwLock<Definitions>,
261261
}

0 commit comments

Comments
 (0)