Initial work for doing minimum capture analysis for RFC-2229
Co-authored-by: Chris Pardy <chrispardy36@gmail.com> Co-authored-by: Logan Mosier <logmosier@gmail.com>
This commit is contained in:
parent
145312075f
commit
8f0c0d656d
5 changed files with 374 additions and 115 deletions
|
@ -415,9 +415,10 @@ pub struct TypeckResults<'tcx> {
|
|||
/// entire variable.
|
||||
pub closure_captures: ty::UpvarListMap,
|
||||
|
||||
/// Given the closure ID this map provides the list of
|
||||
/// `Place`s and how/why are they captured by the closure.
|
||||
pub closure_capture_information: ty::CaptureInformationMap<'tcx>,
|
||||
/// Given the closure DefId this map provides a map of
|
||||
/// root variables to minimum set of `Place`s (and how) that need to be tracked
|
||||
/// to support all captures of that closure.
|
||||
pub closure_min_captures: ty::MinCaptureInformationMap<'tcx>,
|
||||
|
||||
/// Stores the type, expression, span and optional scope span of all types
|
||||
/// that are live across the yield of this generator (if a generator).
|
||||
|
@ -446,7 +447,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||
tainted_by_errors: None,
|
||||
concrete_opaque_types: Default::default(),
|
||||
closure_captures: Default::default(),
|
||||
closure_capture_information: Default::default(),
|
||||
closure_min_captures: Default::default(),
|
||||
generator_interior_types: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -681,7 +682,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> {
|
|||
tainted_by_errors,
|
||||
ref concrete_opaque_types,
|
||||
ref closure_captures,
|
||||
ref closure_capture_information,
|
||||
ref closure_min_captures,
|
||||
ref generator_interior_types,
|
||||
} = *self;
|
||||
|
||||
|
@ -715,7 +716,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> {
|
|||
tainted_by_errors.hash_stable(hcx, hasher);
|
||||
concrete_opaque_types.hash_stable(hcx, hasher);
|
||||
closure_captures.hash_stable(hcx, hasher);
|
||||
closure_capture_information.hash_stable(hcx, hasher);
|
||||
closure_min_captures.hash_stable(hcx, hasher);
|
||||
generator_interior_types.hash_stable(hcx, hasher);
|
||||
})
|
||||
}
|
||||
|
|
|
@ -788,30 +788,18 @@ pub struct CaptureInfo<'tcx> {
|
|||
pub capture_kind: UpvarCapture<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
pub struct CapturedPlace<'tcx> {
|
||||
pub place: HirPlace<'tcx>,
|
||||
pub info: CaptureInfo<'tcx>,
|
||||
}
|
||||
|
||||
pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
|
||||
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
|
||||
|
||||
/// Consider closure where s.str1 is captured via an ImmutableBorrow and s.str2 via a MutableBorrow
|
||||
///
|
||||
/// ```rust
|
||||
/// // Assume that thte HirId for the variable definition is `V1`
|
||||
/// let mut s = SomeStruct { str1: format!("s1"), str2: format!("s2") }
|
||||
///
|
||||
/// let fix_s = |new_s2| {
|
||||
/// // Assume that the HirId for the expression `s.str1` is `E1`
|
||||
/// println!("Updating SomeStruct with str1=", s.str1);
|
||||
/// // Assume that the HirId for the expression `*s.str2` is `E2`
|
||||
/// s.str2 = new_s2;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// For closure `fix_s`, (at a high level) the IndexMap will contain:
|
||||
///
|
||||
/// Place { V1, [ProjectionKind::Field(Index=0, Variant=0)] } : CaptureKind { E1, ImmutableBorrow }
|
||||
/// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow }
|
||||
///
|
||||
pub type CaptureInformationMap<'tcx> =
|
||||
FxHashMap<DefId, FxIndexMap<HirPlace<'tcx>, CaptureInfo<'tcx>>>;
|
||||
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
|
||||
pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureList<'tcx>>;
|
||||
pub type MinCaptureInformationMap<'tcx> = FxHashMap<DefId, RootVariableMinCaptureList<'tcx>>;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum IntVarValue {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue