Skip to content

Commit

Permalink
Remove unnecessary DefineOpaqueTypes from lub
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 7, 2024
1 parent da71dfb commit 5d62afd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 44 deletions.
26 changes: 7 additions & 19 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let at = self.at(&self.cause, self.fcx.param_env);

let res = if self.use_lub {
at.lub(DefineOpaqueTypes::Yes, b, a)
at.lub(b, a)
} else {
at.sup(DefineOpaqueTypes::Yes, b, a)
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
Expand Down Expand Up @@ -1190,13 +1190,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(ty::FnDef(..), ty::FnDef(..)) => {
// Don't reify if the function types have a LUB, i.e., they
// are the same function and their parameters have a LUB.
match self.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(
DefineOpaqueTypes::Yes,
prev_ty,
new_ty,
)
}) {
match self
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
{
// We have a LUB of prev_ty and new_ty, just return it.
Ok(ok) => return Ok(self.register_infer_ok_obligations(ok)),
Err(_) => {
Expand Down Expand Up @@ -1239,7 +1235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
let sig = self
.at(cause, self.param_env)
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
.lub(a_sig, b_sig)
.map(|ok| self.register_infer_ok_obligations(ok))?;

// Reify both sides and return the reified fn pointer type.
Expand Down Expand Up @@ -1330,9 +1326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);

return Err(self
.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(DefineOpaqueTypes::Yes, prev_ty, new_ty)
})
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
.unwrap_err());
}
}
Expand All @@ -1344,13 +1338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(e)
} else {
Err(self
.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(
DefineOpaqueTypes::Yes,
prev_ty,
new_ty,
)
})
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
.unwrap_err())
}
}
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
/// this can result in an error (e.g., if asked to compute LUB of
/// u32 and i32), it is meaningful to call one of them the
/// "expected type".
pub fn lub<T>(
self,
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, T>
pub fn lub<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
where
T: ToTrace<'tcx>,
{
let mut op = LatticeOp::new(
self.infcx,
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
LatticeOpKind::Lub,
);
let value = op.relate(expected, actual)?;
Expand All @@ -303,20 +297,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
/// Computes the greatest-lower-bound, or mutual subtype, of two
/// values. As with `lub` order doesn't matter, except for error
/// cases.
pub fn glb<T>(
self,
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, T>
pub fn glb<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
where
T: ToTrace<'tcx>,
{
let mut op = LatticeOp::new(
self.infcx,
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
LatticeOpKind::Glb,
);
let value = op.relate(expected, actual)?;
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_infer/src/infer/relate/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) struct LatticeOp<'infcx, 'tcx> {
// Immutable fields
trace: TypeTrace<'tcx>,
param_env: ty::ParamEnv<'tcx>,
define_opaque_types: DefineOpaqueTypes,
// Mutable fields
kind: LatticeOpKind,
obligations: Vec<PredicateObligation<'tcx>>,
Expand All @@ -60,10 +59,9 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
infcx: &'infcx InferCtxt<'tcx>,
trace: TypeTrace<'tcx>,
param_env: ty::ParamEnv<'tcx>,
define_opaque_types: DefineOpaqueTypes,
kind: LatticeOpKind,
) -> LatticeOp<'infcx, 'tcx> {
LatticeOp { infcx, trace, param_env, define_opaque_types, kind, obligations: vec![] }
LatticeOp { infcx, trace, param_env, kind, obligations: vec![] }
}

pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
Expand All @@ -88,7 +86,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
self.obligations.extend(
self.infcx
.at(&self.trace.cause, self.param_env)
.eq_trace(self.define_opaque_types, self.trace.clone(), a, b)?
.eq_trace(DefineOpaqueTypes::Yes, self.trace.clone(), a, b)?
.into_obligations(),
);
Ok(a)
Expand Down Expand Up @@ -154,9 +152,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {

(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
if self.define_opaque_types == DefineOpaqueTypes::Yes
&& def_id.is_local()
&& !infcx.next_trait_solver() =>
if def_id.is_local() && !infcx.next_trait_solver() =>
{
self.register_goals(infcx.handle_opaque_type(
a,
Expand Down Expand Up @@ -235,12 +231,12 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
let at = self.infcx.at(&self.trace.cause, self.param_env);
match self.kind {
LatticeOpKind::Glb => {
self.obligations.extend(at.sub(self.define_opaque_types, v, a)?.into_obligations());
self.obligations.extend(at.sub(self.define_opaque_types, v, b)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations());
}
LatticeOpKind::Lub => {
self.obligations.extend(at.sub(self.define_opaque_types, a, v)?.into_obligations());
self.obligations.extend(at.sub(self.define_opaque_types, b, v)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations());
}
}
Ok(())
Expand Down

0 comments on commit 5d62afd

Please sign in to comment.