1- // ignore-tidy-filelength
2-
31//! MIR datatypes and passes. See the [rustc guide] for more info.
42//!
53//! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/index.html
@@ -23,14 +21,12 @@ use polonius_engine::Atom;
2321use rustc_data_structures:: fx:: FxHashSet ;
2422use rustc_data_structures:: graph:: dominators:: Dominators ;
2523use rustc_data_structures:: graph:: { self , GraphSuccessors } ;
26- use rustc_data_structures:: sync:: Lrc ;
2724use rustc_index:: bit_set:: BitMatrix ;
2825use rustc_index:: vec:: { Idx , IndexVec } ;
2926use rustc_macros:: HashStable ;
3027use rustc_serialize:: { Decodable , Encodable } ;
3128use rustc_span:: symbol:: Symbol ;
3229use rustc_span:: { Span , DUMMY_SP } ;
33- use smallvec:: SmallVec ;
3430use std:: borrow:: Cow ;
3531use std:: fmt:: { self , Debug , Display , Formatter , Write } ;
3632use std:: ops:: Index ;
@@ -39,13 +35,15 @@ use std::{iter, mem, option, u32};
3935pub use syntax:: ast:: Mutability ;
4036use syntax:: ast:: Name ;
4137
42- pub use crate :: mir:: cache:: { BodyAndCache , ReadOnlyBodyAndCache } ;
43- pub use crate :: mir:: interpret:: AssertMessage ;
38+ pub use self :: cache:: { BodyAndCache , ReadOnlyBodyAndCache } ;
39+ pub use self :: interpret:: AssertMessage ;
40+ pub use self :: query:: * ;
4441pub use crate :: read_only;
4542
4643mod cache;
4744pub mod interpret;
4845pub mod mono;
46+ mod query;
4947pub mod tcx;
5048pub mod traversal;
5149pub mod visit;
@@ -2581,221 +2579,6 @@ impl Location {
25812579 }
25822580}
25832581
2584- #[ derive( Copy , Clone , PartialEq , RustcEncodable , RustcDecodable , HashStable ) ]
2585- pub enum UnsafetyViolationKind {
2586- General ,
2587- /// Permitted both in `const fn`s and regular `fn`s.
2588- GeneralAndConstFn ,
2589- BorrowPacked ( hir:: HirId ) ,
2590- }
2591-
2592- #[ derive( Copy , Clone , PartialEq , RustcEncodable , RustcDecodable , HashStable ) ]
2593- pub struct UnsafetyViolation {
2594- pub source_info : SourceInfo ,
2595- pub description : Symbol ,
2596- pub details : Symbol ,
2597- pub kind : UnsafetyViolationKind ,
2598- }
2599-
2600- #[ derive( Clone , RustcEncodable , RustcDecodable , HashStable ) ]
2601- pub struct UnsafetyCheckResult {
2602- /// Violations that are propagated *upwards* from this function.
2603- pub violations : Lrc < [ UnsafetyViolation ] > ,
2604- /// `unsafe` blocks in this function, along with whether they are used. This is
2605- /// used for the "unused_unsafe" lint.
2606- pub unsafe_blocks : Lrc < [ ( hir:: HirId , bool ) ] > ,
2607- }
2608-
2609- rustc_index:: newtype_index! {
2610- pub struct GeneratorSavedLocal {
2611- derive [ HashStable ]
2612- DEBUG_FORMAT = "_{}" ,
2613- }
2614- }
2615-
2616- /// The layout of generator state.
2617- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable , TypeFoldable ) ]
2618- pub struct GeneratorLayout < ' tcx > {
2619- /// The type of every local stored inside the generator.
2620- pub field_tys : IndexVec < GeneratorSavedLocal , Ty < ' tcx > > ,
2621-
2622- /// Which of the above fields are in each variant. Note that one field may
2623- /// be stored in multiple variants.
2624- pub variant_fields : IndexVec < VariantIdx , IndexVec < Field , GeneratorSavedLocal > > ,
2625-
2626- /// Which saved locals are storage-live at the same time. Locals that do not
2627- /// have conflicts with each other are allowed to overlap in the computed
2628- /// layout.
2629- pub storage_conflicts : BitMatrix < GeneratorSavedLocal , GeneratorSavedLocal > ,
2630- }
2631-
2632- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2633- pub struct BorrowCheckResult < ' tcx > {
2634- pub closure_requirements : Option < ClosureRegionRequirements < ' tcx > > ,
2635- pub used_mut_upvars : SmallVec < [ Field ; 8 ] > ,
2636- }
2637-
2638- /// The result of the `mir_const_qualif` query.
2639- ///
2640- /// Each field corresponds to an implementer of the `Qualif` trait in
2641- /// `librustc_mir/transform/check_consts/qualifs.rs`. See that file for more information on each
2642- /// `Qualif`.
2643- #[ derive( Clone , Copy , Debug , Default , RustcEncodable , RustcDecodable , HashStable ) ]
2644- pub struct ConstQualifs {
2645- pub has_mut_interior : bool ,
2646- pub needs_drop : bool ,
2647- }
2648-
2649- /// After we borrow check a closure, we are left with various
2650- /// requirements that we have inferred between the free regions that
2651- /// appear in the closure's signature or on its field types. These
2652- /// requirements are then verified and proved by the closure's
2653- /// creating function. This struct encodes those requirements.
2654- ///
2655- /// The requirements are listed as being between various
2656- /// `RegionVid`. The 0th region refers to `'static`; subsequent region
2657- /// vids refer to the free regions that appear in the closure (or
2658- /// generator's) type, in order of appearance. (This numbering is
2659- /// actually defined by the `UniversalRegions` struct in the NLL
2660- /// region checker. See for example
2661- /// `UniversalRegions::closure_mapping`.) Note that we treat the free
2662- /// regions in the closure's type "as if" they were erased, so their
2663- /// precise identity is not important, only their position.
2664- ///
2665- /// Example: If type check produces a closure with the closure substs:
2666- ///
2667- /// ```text
2668- /// ClosureSubsts = [
2669- /// i8, // the "closure kind"
2670- /// for<'x> fn(&'a &'x u32) -> &'x u32, // the "closure signature"
2671- /// &'a String, // some upvar
2672- /// ]
2673- /// ```
2674- ///
2675- /// here, there is one unique free region (`'a`) but it appears
2676- /// twice. We would "renumber" each occurrence to a unique vid, as follows:
2677- ///
2678- /// ```text
2679- /// ClosureSubsts = [
2680- /// i8, // the "closure kind"
2681- /// for<'x> fn(&'1 &'x u32) -> &'x u32, // the "closure signature"
2682- /// &'2 String, // some upvar
2683- /// ]
2684- /// ```
2685- ///
2686- /// Now the code might impose a requirement like `'1: '2`. When an
2687- /// instance of the closure is created, the corresponding free regions
2688- /// can be extracted from its type and constrained to have the given
2689- /// outlives relationship.
2690- ///
2691- /// In some cases, we have to record outlives requirements between
2692- /// types and regions as well. In that case, if those types include
2693- /// any regions, those regions are recorded as `ReClosureBound`
2694- /// instances assigned one of these same indices. Those regions will
2695- /// be substituted away by the creator. We use `ReClosureBound` in
2696- /// that case because the regions must be allocated in the global
2697- /// `TyCtxt`, and hence we cannot use `ReVar` (which is what we use
2698- /// internally within the rest of the NLL code).
2699- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2700- pub struct ClosureRegionRequirements < ' tcx > {
2701- /// The number of external regions defined on the closure. In our
2702- /// example above, it would be 3 -- one for `'static`, then `'1`
2703- /// and `'2`. This is just used for a sanity check later on, to
2704- /// make sure that the number of regions we see at the callsite
2705- /// matches.
2706- pub num_external_vids : usize ,
2707-
2708- /// Requirements between the various free regions defined in
2709- /// indices.
2710- pub outlives_requirements : Vec < ClosureOutlivesRequirement < ' tcx > > ,
2711- }
2712-
2713- /// Indicates an outlives-constraint between a type or between two
2714- /// free regions declared on the closure.
2715- #[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2716- pub struct ClosureOutlivesRequirement < ' tcx > {
2717- // This region or type ...
2718- pub subject : ClosureOutlivesSubject < ' tcx > ,
2719-
2720- // ... must outlive this one.
2721- pub outlived_free_region : ty:: RegionVid ,
2722-
2723- // If not, report an error here ...
2724- pub blame_span : Span ,
2725-
2726- // ... due to this reason.
2727- pub category : ConstraintCategory ,
2728- }
2729-
2730- /// Outlives-constraints can be categorized to determine whether and why they
2731- /// are interesting (for error reporting). Order of variants indicates sort
2732- /// order of the category, thereby influencing diagnostic output.
2733- ///
2734- /// See also [rustc_mir::borrow_check::nll::constraints].
2735- #[ derive(
2736- Copy ,
2737- Clone ,
2738- Debug ,
2739- Eq ,
2740- PartialEq ,
2741- PartialOrd ,
2742- Ord ,
2743- Hash ,
2744- RustcEncodable ,
2745- RustcDecodable ,
2746- HashStable
2747- ) ]
2748- pub enum ConstraintCategory {
2749- Return ,
2750- Yield ,
2751- UseAsConst ,
2752- UseAsStatic ,
2753- TypeAnnotation ,
2754- Cast ,
2755-
2756- /// A constraint that came from checking the body of a closure.
2757- ///
2758- /// We try to get the category that the closure used when reporting this.
2759- ClosureBounds ,
2760- CallArgument ,
2761- CopyBound ,
2762- SizedBound ,
2763- Assignment ,
2764- OpaqueType ,
2765-
2766- /// A "boring" constraint (caused by the given location) is one that
2767- /// the user probably doesn't want to see described in diagnostics,
2768- /// because it is kind of an artifact of the type system setup.
2769- /// Example: `x = Foo { field: y }` technically creates
2770- /// intermediate regions representing the "type of `Foo { field: y
2771- /// }`", and data flows from `y` into those variables, but they
2772- /// are not very interesting. The assignment into `x` on the other
2773- /// hand might be.
2774- Boring ,
2775- // Boring and applicable everywhere.
2776- BoringNoLocation ,
2777-
2778- /// A constraint that doesn't correspond to anything the user sees.
2779- Internal ,
2780- }
2781-
2782- /// The subject of a `ClosureOutlivesRequirement` -- that is, the thing
2783- /// that must outlive some region.
2784- #[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2785- pub enum ClosureOutlivesSubject < ' tcx > {
2786- /// Subject is a type, typically a type parameter, but could also
2787- /// be a projection. Indicates a requirement like `T: 'a` being
2788- /// passed to the caller, where the type here is `T`.
2789- ///
2790- /// The type here is guaranteed not to contain any free regions at
2791- /// present.
2792- Ty ( Ty < ' tcx > ) ,
2793-
2794- /// Subject is a free region from the closure. Indicates a requirement
2795- /// like `'a: 'b` being passed to the caller; the region here is `'a`.
2796- Region ( ty:: RegionVid ) ,
2797- }
2798-
27992582/*
28002583 * `TypeFoldable` implementations for MIR types
28012584*/
0 commit comments