Skip to content

Commit

Permalink
Clean up opaque type obligations in query results
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 3, 2022
1 parent d9bb93f commit d526a8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
15 changes: 7 additions & 8 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Expand Up @@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, BoundVar, Const, OpaqueTypeKey, ToPredicate, Ty, TyCtxt};
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
use rustc_span::Span;
use std::fmt::Debug;
use std::iter;
Expand Down Expand Up @@ -146,13 +146,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
})
}

fn take_opaque_types_for_query_response(&self) -> Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
self.inner
.borrow_mut()
.opaque_type_storage
.take_opaque_types()
.into_iter()
.map(|(k, v)| (k, v.hidden_type.ty))
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id, k.substs), v.hidden_type.ty))
.collect()
}

Expand Down Expand Up @@ -497,11 +497,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
let mut obligations = vec![];

// Carry all newly resolved opaque types to the caller's scope
for &(key, ty) in &query_response.value.opaque_types {
let substs = substitute_value(self.tcx, &result_subst, key.substs);
let opaque = self.tcx.mk_opaque(key.def_id, substs);
let ty = substitute_value(self.tcx, &result_subst, ty);
obligations.extend(self.handle_opaque_type(opaque, ty, cause, param_env)?.obligations);
for &(a, b) in &query_response.value.opaque_types {
let a = substitute_value(self.tcx, &result_subst, a);
let b = substitute_value(self.tcx, &result_subst, b);
obligations.extend(self.handle_opaque_type(a, b, cause, param_env)?.obligations);
}

Ok(InferOk { value: result_subst, obligations })
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/infer/canonical.rs
Expand Up @@ -23,7 +23,7 @@

use crate::infer::MemberConstraint;
use crate::ty::subst::GenericArg;
use crate::ty::{self, BoundVar, List, OpaqueTypeKey, Region, Ty, TyCtxt};
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
use rustc_index::vec::IndexVec;
use rustc_macros::HashStable;
use smallvec::SmallVec;
Expand Down Expand Up @@ -178,9 +178,12 @@ pub struct QueryResponse<'tcx, R> {
pub var_values: CanonicalVarValues<'tcx>,
pub region_constraints: QueryRegionConstraints<'tcx>,
pub certainty: Certainty,
/// List of opaque types for which we figured out a hidden type
/// during the evaluation of the query.
pub opaque_types: Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)>,
/// List of opaque types which we tried to compare to another type.
/// Inside the query we don't know yet whether the opaque type actually
/// should get its hidden type inferred. So we bubble the opaque type
/// and the type it was compared against upwards and let the query caller
/// handle it.
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
pub value: R,
}

Expand Down

0 comments on commit d526a8d

Please sign in to comment.