Skip to content

Commit 1acd65c

Browse files
committed
predefined opaques use List
1 parent 5b9007b commit 1acd65c

File tree

8 files changed

+16
-77
lines changed

8 files changed

+16
-77
lines changed

compiler/rustc_middle/src/arena.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ macro_rules! arena_types {
109109
rustc_middle::ty::EarlyBinder<'tcx, rustc_middle::ty::Ty<'tcx>>
110110
>,
111111
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<rustc_middle::ty::TyCtxt<'tcx>>,
112-
[] predefined_opaques_in_body: rustc_middle::traits::solve::PredefinedOpaquesData<rustc_middle::ty::TyCtxt<'tcx>>,
113112
[decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,
114113
[] stripped_cfg_items: rustc_hir::attrs::StrippedCfgItem,
115114
[] mod_child: rustc_middle::metadata::ModChild,

compiler/rustc_middle/src/traits/solve.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_type_ir as ir;
44
pub use rustc_type_ir::solve::*;
55

66
use crate::ty::{
7-
self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
7+
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
88
try_visit,
99
};
1010

@@ -15,16 +15,7 @@ pub type CandidateSource<'tcx> = ir::solve::CandidateSource<TyCtxt<'tcx>>;
1515
pub type CanonicalInput<'tcx, P = ty::Predicate<'tcx>> = ir::solve::CanonicalInput<TyCtxt<'tcx>, P>;
1616
pub type CanonicalResponse<'tcx> = ir::solve::CanonicalResponse<TyCtxt<'tcx>>;
1717

18-
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
19-
pub struct PredefinedOpaques<'tcx>(pub(crate) Interned<'tcx, PredefinedOpaquesData<TyCtxt<'tcx>>>);
20-
21-
impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
22-
type Target = PredefinedOpaquesData<TyCtxt<'tcx>>;
23-
24-
fn deref(&self) -> &Self::Target {
25-
&self.0
26-
}
27-
}
18+
pub type PredefinedOpaques<'tcx> = &'tcx ty::List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>;
2819

2920
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
3021
pub struct ExternalConstraints<'tcx>(
@@ -93,35 +84,3 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
9384
self.normalization_nested_goals.visit_with(visitor)
9485
}
9586
}
96-
97-
// FIXME: Having to clone `region_constraints` for folding feels bad and
98-
// probably isn't great wrt performance.
99-
//
100-
// Not sure how to fix this, maybe we should also intern `opaque_types` and
101-
// `region_constraints` here or something.
102-
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
103-
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
104-
self,
105-
folder: &mut F,
106-
) -> Result<Self, F::Error> {
107-
Ok(FallibleTypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData {
108-
opaque_types: self
109-
.opaque_types
110-
.iter()
111-
.map(|opaque| opaque.try_fold_with(folder))
112-
.collect::<Result<_, F::Error>>()?,
113-
}))
114-
}
115-
116-
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
117-
TypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData {
118-
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
119-
})
120-
}
121-
}
122-
123-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
124-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
125-
self.opaque_types.visit_with(visitor)
126-
}
127-
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ use crate::query::{IntoQueryParam, LocalCrate, Providers, TyCtxtAt};
7474
use crate::thir::Thir;
7575
use crate::traits;
7676
use crate::traits::solve::{
77-
self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, PredefinedOpaques,
78-
PredefinedOpaquesData, QueryResult, inspect,
77+
self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, QueryResult, inspect,
7978
};
8079
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
8180
use crate::ty::{
@@ -116,7 +115,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
116115

117116
fn mk_predefined_opaques_in_body(
118117
self,
119-
data: PredefinedOpaquesData<Self>,
118+
data: &[(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)],
120119
) -> Self::PredefinedOpaques {
121120
self.mk_predefined_opaques_in_body(data)
122121
}
@@ -941,7 +940,7 @@ pub struct CtxtInterners<'tcx> {
941940
layout: InternedSet<'tcx, LayoutData<FieldIdx, VariantIdx>>,
942941
adt_def: InternedSet<'tcx, AdtDefData>,
943942
external_constraints: InternedSet<'tcx, ExternalConstraintsData<TyCtxt<'tcx>>>,
944-
predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<TyCtxt<'tcx>>>,
943+
predefined_opaques_in_body: InternedSet<'tcx, List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>>,
945944
fields: InternedSet<'tcx, List<FieldIdx>>,
946945
local_def_ids: InternedSet<'tcx, List<LocalDefId>>,
947946
captures: InternedSet<'tcx, List<&'tcx ty::CapturedPlace<'tcx>>>,
@@ -2748,8 +2747,6 @@ direct_interners! {
27482747
adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>,
27492748
external_constraints: pub mk_external_constraints(ExternalConstraintsData<TyCtxt<'tcx>>):
27502749
ExternalConstraints -> ExternalConstraints<'tcx>,
2751-
predefined_opaques_in_body: pub mk_predefined_opaques_in_body(PredefinedOpaquesData<TyCtxt<'tcx>>):
2752-
PredefinedOpaques -> PredefinedOpaques<'tcx>,
27532750
}
27542751

27552752
macro_rules! slice_interners {
@@ -2786,6 +2783,7 @@ slice_interners!(
27862783
offset_of: pub mk_offset_of((VariantIdx, FieldIdx)),
27872784
patterns: pub mk_patterns(Pattern<'tcx>),
27882785
outlives: pub mk_outlives(ty::ArgOutlivesPredicate<'tcx>),
2786+
predefined_opaques_in_body: pub mk_predefined_opaques_in_body((ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)),
27892787
);
27902788

27912789
impl<'tcx> TyCtxt<'tcx> {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ macro_rules! list_fold {
796796

797797
list_fold! {
798798
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> : mk_poly_existential_predicates,
799+
&'tcx ty::List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>: mk_predefined_opaques_in_body,
799800
&'tcx ty::List<PlaceElem<'tcx>> : mk_place_elems,
800801
&'tcx ty::List<ty::Pattern<'tcx>> : mk_patterns,
801802
&'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>> : mk_outlives,

compiler/rustc_next_trait_solver/src/canonical/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::delegate::SolverDelegate;
2525
use crate::resolve::eager_resolve_vars;
2626
use crate::solve::{
2727
CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, Goal,
28-
NestedNormalizationGoals, PredefinedOpaquesData, QueryInput, Response, inspect,
28+
NestedNormalizationGoals, QueryInput, Response, inspect,
2929
};
3030

3131
pub mod canonicalizer;
@@ -53,7 +53,7 @@ impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
5353
pub(super) fn canonicalize_goal<D, I>(
5454
delegate: &D,
5555
goal: Goal<I, I::Predicate>,
56-
opaque_types: Vec<(ty::OpaqueTypeKey<I>, I::Ty)>,
56+
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
5757
) -> (Vec<I::GenericArg>, CanonicalInput<I, I::Predicate>)
5858
where
5959
D: SolverDelegate<Interner = I>,
@@ -65,9 +65,7 @@ where
6565
&mut orig_values,
6666
QueryInput {
6767
goal,
68-
predefined_opaques_in_body: delegate
69-
.cx()
70-
.mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types }),
68+
predefined_opaques_in_body: delegate.cx().mk_predefined_opaques_in_body(opaque_types),
7169
},
7270
);
7371
let query_input = ty::CanonicalQueryInput { canonical, typing_mode: delegate.typing_mode() };

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
f: impl FnOnce(&mut EvalCtxt<'_, D>, Goal<I, I::Predicate>) -> R,
358358
) -> R {
359359
let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
360-
for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {
360+
for (key, ty) in input.predefined_opaques_in_body.iter() {
361361
let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
362362
// It may be possible that two entries in the opaque type storage end up
363363
// with the same key after resolving contained inference variables.
@@ -467,7 +467,7 @@ where
467467
let opaque_types = self.delegate.clone_opaque_types_lookup_table();
468468
let (goal, opaque_types) = eager_resolve_vars(self.delegate, (goal, opaque_types));
469469

470-
let (orig_values, canonical_goal) = canonicalize_goal(self.delegate, goal, opaque_types);
470+
let (orig_values, canonical_goal) = canonicalize_goal(self.delegate, goal, &opaque_types);
471471
let canonical_result = self.search_graph.evaluate_goal(
472472
self.cx(),
473473
canonical_goal,
@@ -548,7 +548,6 @@ where
548548
.canonical
549549
.value
550550
.predefined_opaques_in_body
551-
.opaque_types
552551
.len(),
553552
stalled_vars,
554553
sub_roots,
@@ -1557,7 +1556,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
15571556
let opaque_types = delegate.clone_opaque_types_lookup_table();
15581557
let (goal, opaque_types) = eager_resolve_vars(delegate, (goal, opaque_types));
15591558

1560-
let (orig_values, canonical_goal) = canonicalize_goal(delegate, goal, opaque_types);
1559+
let (orig_values, canonical_goal) = canonicalize_goal(delegate, goal, &opaque_types);
15611560

15621561
let (canonical_result, final_revision) =
15631562
delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal);

compiler/rustc_type_ir/src/interner.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use crate::inherent::*;
1111
use crate::ir_print::IrPrint;
1212
use crate::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
1313
use crate::relate::Relate;
14-
use crate::solve::{
15-
CanonicalInput, ExternalConstraintsData, PredefinedOpaquesData, QueryResult, inspect,
16-
};
14+
use crate::solve::{CanonicalInput, ExternalConstraintsData, QueryResult, inspect};
1715
use crate::visit::{Flags, TypeVisitable};
1816
use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph};
1917

@@ -70,10 +68,10 @@ pub trait Interner:
7068
+ Hash
7169
+ Eq
7270
+ TypeFoldable<Self>
73-
+ Deref<Target = PredefinedOpaquesData<Self>>;
71+
+ SliceLike<Item = (ty::OpaqueTypeKey<Self>, Self::Ty)>;
7472
fn mk_predefined_opaques_in_body(
7573
self,
76-
data: PredefinedOpaquesData<Self>,
74+
data: &[(ty::OpaqueTypeKey<Self>, Self::Ty)],
7775
) -> Self::PredefinedOpaques;
7876

7977
type LocalDefIds: Copy

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,6 @@ pub struct QueryInput<I: Interner, P> {
109109

110110
impl<I: Interner, P: Eq> Eq for QueryInput<I, P> {}
111111

112-
/// Opaques that are defined in the inference context before a query is called.
113-
#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)]
114-
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
115-
#[cfg_attr(
116-
feature = "nightly",
117-
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
118-
)]
119-
pub struct PredefinedOpaquesData<I: Interner> {
120-
pub opaque_types: Vec<(ty::OpaqueTypeKey<I>, I::Ty)>,
121-
}
122-
123-
impl<I: Interner> Eq for PredefinedOpaquesData<I> {}
124-
125112
/// Possible ways the given goal can be proven.
126113
#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
127114
pub enum CandidateSource<I: Interner> {

0 commit comments

Comments
 (0)