Skip to content

Commit e3a8c85

Browse files
committed
simplify Interner opaque types API
1 parent 04635b0 commit e3a8c85

File tree

7 files changed

+26
-47
lines changed

7 files changed

+26
-47
lines changed

compiler/rustc_borrowck/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
497497
)
498498
});
499499

500-
self.inject_new_hidden_type_unchecked(key, hidden_ty);
500+
let prev = self.register_hidden_type_in_storage(key, hidden_ty);
501+
assert_eq!(prev, None);
501502
}
502503
}
503504
}

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,12 @@ impl<'tcx> InferCtxt<'tcx> {
198198
/// it hasn't previously been defined. This does not emit any
199199
/// constraints and it's the responsibility of the caller to make
200200
/// sure that the item bounds of the opaque are checked.
201-
pub fn inject_new_hidden_type_unchecked(
201+
pub fn register_hidden_type_in_storage(
202202
&self,
203203
opaque_type_key: OpaqueTypeKey<'tcx>,
204204
hidden_ty: OpaqueHiddenType<'tcx>,
205-
) {
206-
let prev = self.inner.borrow_mut().opaque_types().register(opaque_type_key, hidden_ty);
207-
assert_eq!(prev, None);
205+
) -> Option<Ty<'tcx>> {
206+
self.inner.borrow_mut().opaque_types().register(opaque_type_key, hidden_ty)
208207
}
209208

210209
/// Insert a hidden type into the opaque type storage, equating it

compiler/rustc_next_trait_solver/src/delegate.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
6262
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
6363
) -> <Self::Interner as Interner>::GenericArg;
6464

65-
// FIXME: Can we implement this in terms of `add` and `inject`?
66-
fn insert_hidden_type(
65+
fn register_hidden_type_in_storage(
6766
&self,
6867
opaque_type_key: ty::OpaqueTypeKey<Self::Interner>,
69-
param_env: <Self::Interner as Interner>::ParamEnv,
7068
hidden_ty: <Self::Interner as Interner>::Ty,
71-
goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
72-
) -> Result<(), NoSolution>;
69+
span: <Self::Interner as Interner>::Span,
70+
) -> Option<<Self::Interner as Interner>::Ty>;
7371

7472
fn add_item_bounds_for_hidden_type(
7573
&self,
@@ -79,14 +77,6 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
7977
hidden_ty: <Self::Interner as Interner>::Ty,
8078
goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
8179
);
82-
83-
fn inject_new_hidden_type_unchecked(
84-
&self,
85-
key: ty::OpaqueTypeKey<Self::Interner>,
86-
hidden_ty: <Self::Interner as Interner>::Ty,
87-
span: <Self::Interner as Interner>::Span,
88-
);
89-
9080
fn reset_opaque_types(&self);
9181

9282
fn fetch_eligible_assoc_item(

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ where
425425

426426
fn register_new_opaque_types(&mut self, opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)]) {
427427
for &(key, ty) in opaque_types {
428-
self.delegate.inject_new_hidden_type_unchecked(key, ty, self.origin_span);
428+
let prev = self.delegate.register_hidden_type_in_storage(key, ty, self.origin_span);
429+
assert_eq!(prev, None);
429430
}
430431
}
431432
}

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ where
387387
};
388388

389389
for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {
390-
ecx.delegate.inject_new_hidden_type_unchecked(key, ty, ecx.origin_span);
390+
let prev = ecx.delegate.register_hidden_type_in_storage(key, ty, ecx.origin_span);
391+
assert_eq!(prev, None);
391392
}
392393

393394
if !ecx.nested_goals.is_empty() {
@@ -1070,16 +1071,12 @@ where
10701071
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
10711072
}
10721073

1073-
pub(super) fn insert_hidden_type(
1074+
pub(super) fn register_hidden_type_in_storage(
10741075
&mut self,
10751076
opaque_type_key: ty::OpaqueTypeKey<I>,
1076-
param_env: I::ParamEnv,
10771077
hidden_ty: I::Ty,
1078-
) -> Result<(), NoSolution> {
1079-
let mut goals = Vec::new();
1080-
self.delegate.insert_hidden_type(opaque_type_key, param_env, hidden_ty, &mut goals)?;
1081-
self.add_goals(GoalSource::Misc, goals);
1082-
Ok(())
1078+
) -> Option<I::Ty> {
1079+
self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span)
10831080
}
10841081

10851082
pub(super) fn add_item_bounds_for_hidden_type(

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ where
8686
}
8787

8888
// Otherwise, define a new opaque type
89-
// FIXME: should we use `inject_hidden_type_unchecked` here?
90-
self.insert_hidden_type(opaque_type_key, goal.param_env, expected)?;
89+
let prev = self.register_hidden_type_in_storage(opaque_type_key, expected);
90+
assert_eq!(prev, None);
9191
self.add_item_bounds_for_hidden_type(
9292
def_id.into(),
9393
opaque_ty.args,

compiler/rustc_trait_selection/src/solve/delegate.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,16 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
149149
self.0.instantiate_canonical_var(span, cv_info, universe_map)
150150
}
151151

152-
fn insert_hidden_type(
152+
fn register_hidden_type_in_storage(
153153
&self,
154-
opaque_type_key: ty::OpaqueTypeKey<'tcx>,
155-
param_env: ty::ParamEnv<'tcx>,
156-
hidden_ty: Ty<'tcx>,
157-
goals: &mut Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
158-
) -> Result<(), NoSolution> {
159-
self.0
160-
.insert_hidden_type(opaque_type_key, DUMMY_SP, param_env, hidden_ty, goals)
161-
.map_err(|_| NoSolution)
154+
opaque_type_key: rustc_type_ir::OpaqueTypeKey<Self::Interner>,
155+
hidden_ty: <Self::Interner as ty::Interner>::Ty,
156+
span: <Self::Interner as ty::Interner>::Span,
157+
) -> Option<<Self::Interner as ty::Interner>::Ty> {
158+
self.0.register_hidden_type_in_storage(
159+
opaque_type_key,
160+
ty::OpaqueHiddenType { span, ty: hidden_ty },
161+
)
162162
}
163163

164164
fn add_item_bounds_for_hidden_type(
@@ -172,15 +172,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
172172
self.0.add_item_bounds_for_hidden_type(def_id, args, param_env, hidden_ty, goals);
173173
}
174174

175-
fn inject_new_hidden_type_unchecked(
176-
&self,
177-
key: ty::OpaqueTypeKey<'tcx>,
178-
hidden_ty: Ty<'tcx>,
179-
span: Span,
180-
) {
181-
self.0.inject_new_hidden_type_unchecked(key, ty::OpaqueHiddenType { ty: hidden_ty, span })
182-
}
183-
184175
fn reset_opaque_types(&self) {
185176
let _ = self.take_opaque_types();
186177
}

0 commit comments

Comments
 (0)