Skip to content

Commit 18b7d9e

Browse files
Intern LocalDefId list from opaque query
1 parent 64368d0 commit 18b7d9e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ rustc_queries! {
339339

340340
query opaque_types_defined_by(
341341
key: LocalDefId
342-
) -> &'tcx [LocalDefId] {
342+
) -> &'tcx ty::List<LocalDefId> {
343343
desc {
344344
|tcx| "computing the opaque types defined by `{}`",
345345
tcx.def_path_str(key.to_def_id())

compiler/rustc_middle/src/ty/context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct CtxtInterners<'tcx> {
157157
external_constraints: InternedSet<'tcx, ExternalConstraintsData<'tcx>>,
158158
predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<'tcx>>,
159159
fields: InternedSet<'tcx, List<FieldIdx>>,
160+
local_def_ids: InternedSet<'tcx, List<LocalDefId>>,
160161
}
161162

162163
impl<'tcx> CtxtInterners<'tcx> {
@@ -182,6 +183,7 @@ impl<'tcx> CtxtInterners<'tcx> {
182183
external_constraints: Default::default(),
183184
predefined_opaques_in_body: Default::default(),
184185
fields: Default::default(),
186+
local_def_ids: Default::default(),
185187
}
186188
}
187189

@@ -1568,6 +1570,7 @@ slice_interners!(
15681570
place_elems: pub mk_place_elems(PlaceElem<'tcx>),
15691571
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind),
15701572
fields: pub mk_fields(FieldIdx),
1573+
local_def_ids: intern_local_def_ids(LocalDefId),
15711574
);
15721575

15731576
impl<'tcx> TyCtxt<'tcx> {
@@ -1798,6 +1801,13 @@ impl<'tcx> TyCtxt<'tcx> {
17981801
self.intern_clauses(clauses)
17991802
}
18001803

1804+
pub fn mk_local_def_ids(self, clauses: &[LocalDefId]) -> &'tcx List<LocalDefId> {
1805+
// FIXME consider asking the input slice to be sorted to avoid
1806+
// re-interning permutations, in which case that would be asserted
1807+
// here.
1808+
self.intern_local_def_ids(clauses)
1809+
}
1810+
18011811
pub fn mk_const_list_from_iter<I, T>(self, iter: I) -> T::Output
18021812
where
18031813
I: Iterator<Item = T>,

compiler/rustc_ty_utils/src/opaque_types.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
269269
}
270270
}
271271

272-
fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [LocalDefId] {
272+
fn opaque_types_defined_by<'tcx>(
273+
tcx: TyCtxt<'tcx>,
274+
item: LocalDefId,
275+
) -> &'tcx ty::List<LocalDefId> {
273276
let kind = tcx.def_kind(item);
274277
trace!(?kind);
275278
let mut collector = OpaqueTypeCollector::new(tcx, item);
@@ -327,7 +330,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
327330
return tcx.opaque_types_defined_by(tcx.local_parent(item));
328331
}
329332
}
330-
tcx.arena.alloc_from_iter(collector.opaques)
333+
tcx.mk_local_def_ids(&collector.opaques)
331334
}
332335

333336
pub(super) fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)