Move opaque type cache into InferCtxt
This commit is contained in:
parent
1f94abcda6
commit
d99805982b
7 changed files with 102 additions and 107 deletions
|
@ -2,11 +2,11 @@ use crate::infer::InferCtxtExt as _;
|
|||
use crate::traits::{self, ObligationCause, PredicateObligation};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
|
||||
use rustc_infer::infer::free_regions::FreeRegionRelations;
|
||||
use rustc_infer::infer::opaque_types::{OpaqueTypeDecl, OpaqueTypeMap};
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_infer::infer::{self, InferCtxt, InferOk};
|
||||
use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
||||
|
@ -16,72 +16,6 @@ use rustc_span::Span;
|
|||
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
pub type OpaqueTypeMap<'tcx> = VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
|
||||
|
||||
/// Information about the opaque types whose values we
|
||||
/// are inferring in this function (these are the `impl Trait` that
|
||||
/// appear in the return type).
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct OpaqueTypeDecl<'tcx> {
|
||||
/// The opaque type (`ty::Opaque`) for this declaration.
|
||||
pub opaque_type: Ty<'tcx>,
|
||||
|
||||
/// The span of this particular definition of the opaque type. So
|
||||
/// for example:
|
||||
///
|
||||
/// ```ignore (incomplete snippet)
|
||||
/// type Foo = impl Baz;
|
||||
/// fn bar() -> Foo {
|
||||
/// // ^^^ This is the span we are looking for!
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// In cases where the fn returns `(impl Trait, impl Trait)` or
|
||||
/// other such combinations, the result is currently
|
||||
/// over-approximated, but better than nothing.
|
||||
pub definition_span: Span,
|
||||
|
||||
/// The type variable that represents the value of the opaque type
|
||||
/// that we require. In other words, after we compile this function,
|
||||
/// we will be created a constraint like:
|
||||
///
|
||||
/// Foo<'a, T> = ?C
|
||||
///
|
||||
/// where `?C` is the value of this type variable. =) It may
|
||||
/// naturally refer to the type and lifetime parameters in scope
|
||||
/// in this function, though ultimately it should only reference
|
||||
/// those that are arguments to `Foo` in the constraint above. (In
|
||||
/// other words, `?C` should not include `'b`, even though it's a
|
||||
/// lifetime parameter on `foo`.)
|
||||
pub concrete_ty: Ty<'tcx>,
|
||||
|
||||
/// Returns `true` if the `impl Trait` bounds include region bounds.
|
||||
/// For example, this would be true for:
|
||||
///
|
||||
/// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
|
||||
///
|
||||
/// but false for:
|
||||
///
|
||||
/// fn foo<'c>() -> impl Trait<'c>
|
||||
///
|
||||
/// unless `Trait` was declared like:
|
||||
///
|
||||
/// trait Trait<'c>: 'c
|
||||
///
|
||||
/// in which case it would be true.
|
||||
///
|
||||
/// This is used during regionck to decide whether we need to
|
||||
/// impose any additional constraints to ensure that region
|
||||
/// variables in `concrete_ty` wind up being constrained to
|
||||
/// something from `substs` (or, at minimum, things that outlive
|
||||
/// the fn body). (Ultimately, writeback is responsible for this
|
||||
/// check.)
|
||||
pub has_required_region_bounds: bool,
|
||||
|
||||
/// The origin of the opaque type.
|
||||
pub origin: hir::OpaqueTyOrigin,
|
||||
}
|
||||
|
||||
/// Whether member constraints should be generated for all opaque types
|
||||
#[derive(Debug)]
|
||||
pub enum GenerateMemberConstraints {
|
||||
|
@ -105,11 +39,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
value_span: Span,
|
||||
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>;
|
||||
|
||||
fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(
|
||||
&self,
|
||||
opaque_types: &OpaqueTypeMap<'tcx>,
|
||||
free_region_relations: &FRR,
|
||||
);
|
||||
fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(&self, free_region_relations: &FRR);
|
||||
|
||||
fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
|
||||
&self,
|
||||
|
@ -350,12 +280,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
/// - `opaque_types` -- the map produced by `instantiate_opaque_types`
|
||||
/// - `free_region_relations` -- something that can be used to relate
|
||||
/// the free regions (`'a`) that appear in the impl trait.
|
||||
fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(
|
||||
&self,
|
||||
opaque_types: &OpaqueTypeMap<'tcx>,
|
||||
free_region_relations: &FRR,
|
||||
) {
|
||||
for &(opaque_type_key, opaque_defn) in opaque_types {
|
||||
fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(&self, free_region_relations: &FRR) {
|
||||
let opaque_types = self.inner.borrow().opaque_types.clone();
|
||||
for (opaque_type_key, opaque_defn) in opaque_types {
|
||||
self.constrain_opaque_type(
|
||||
opaque_type_key,
|
||||
&opaque_defn,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue