Skip to content

Commit ef72d25

Browse files
committed
Auto merge of #120068 - matthiaskrgr:rollup-vxugut5, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #115291 (Save liveness results for DestinationPropagation) - #119855 (Enable Static Builds for FreeBSD) - #119975 (Don't ICE if TAIT-defining fn contains a closure with `_` in return type) - #120001 (Consistently unset RUSTC_BOOTSTRAP when compiling bootstrap) - #120020 (Gracefully handle missing typeck information if typeck errored) - #120031 (Construct closure type eagerly) - #120032 (Fix `rustc_abi` build on stable) - #120039 (pat_analysis: Don't rely on contiguous `VariantId`s outside of rustc) - #120044 (Fix typo in comments (in_place_collect)) - #120056 (Use FnOnceOutput instead of FnOnce where expected) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6ae4cfb + 99a8b6a commit ef72d25

File tree

34 files changed

+567
-271
lines changed

34 files changed

+567
-271
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4355,6 +4355,7 @@ name = "rustc_pattern_analysis"
43554355
version = "0.0.0"
43564356
dependencies = [
43574357
"derivative",
4358+
"rustc-hash",
43584359
"rustc_apfloat",
43594360
"rustc_arena",
43604361
"rustc_data_structures",

compiler/rustc_abi/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ bitflags! {
4949
| ReprFlags::IS_LINEAR.bits();
5050
}
5151
}
52-
rustc_data_structures::external_bitflags_debug! { ReprFlags }
52+
53+
// This is the same as `rustc_data_structures::external_bitflags_debug` but without the
54+
// `rustc_data_structures` to make it build on stable.
55+
impl std::fmt::Debug for ReprFlags {
56+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57+
bitflags::parser::to_writer(self, f)
58+
}
59+
}
5360

5461
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5562
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]

compiler/rustc_borrowck/src/nll.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1212
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
1313
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1414
use rustc_mir_dataflow::move_paths::MoveData;
15+
use rustc_mir_dataflow::points::DenseLocationMap;
1516
use rustc_mir_dataflow::ResultsCursor;
1617
use rustc_span::symbol::sym;
1718
use std::env;
@@ -27,7 +28,7 @@ use crate::{
2728
facts::{AllFacts, AllFactsExt, RustcFacts},
2829
location::LocationTable,
2930
polonius,
30-
region_infer::{values::RegionValueElements, RegionInferenceContext},
31+
region_infer::RegionInferenceContext,
3132
renumber,
3233
type_check::{self, MirTypeckRegionConstraints, MirTypeckResults},
3334
universal_regions::UniversalRegions,
@@ -98,7 +99,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
9899

99100
let universal_regions = Rc::new(universal_regions);
100101

101-
let elements = &Rc::new(RegionValueElements::new(body));
102+
let elements = &Rc::new(DenseLocationMap::new(body));
102103

103104
// Run the MIR type-checker.
104105
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::mir::{
1919
use rustc_middle::traits::ObligationCause;
2020
use rustc_middle::traits::ObligationCauseCode;
2121
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
22+
use rustc_mir_dataflow::points::DenseLocationMap;
2223
use rustc_span::Span;
2324

2425
use crate::constraints::graph::{self, NormalConstraintGraph, RegionGraph};
@@ -30,8 +31,7 @@ use crate::{
3031
nll::PoloniusOutput,
3132
region_infer::reverse_sccs::ReverseSccGraph,
3233
region_infer::values::{
33-
LivenessValues, PlaceholderIndices, RegionElement, RegionValueElements, RegionValues,
34-
ToElementIndex,
34+
LivenessValues, PlaceholderIndices, RegionElement, RegionValues, ToElementIndex,
3535
},
3636
type_check::{free_region_relations::UniversalRegionRelations, Locations},
3737
universal_regions::UniversalRegions,
@@ -330,7 +330,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
330330
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
331331
type_tests: Vec<TypeTest<'tcx>>,
332332
liveness_constraints: LivenessValues,
333-
elements: &Rc<RegionValueElements>,
333+
elements: &Rc<DenseLocationMap>,
334334
) -> Self {
335335
debug!("universal_regions: {:#?}", universal_regions);
336336
debug!("outlives constraints: {:#?}", outlives_constraints);

compiler/rustc_borrowck/src/region_infer/values.rs

+10-94
Original file line numberDiff line numberDiff line change
@@ -5,97 +5,13 @@ use rustc_index::bit_set::SparseBitMatrix;
55
use rustc_index::interval::IntervalSet;
66
use rustc_index::interval::SparseIntervalMatrix;
77
use rustc_index::Idx;
8-
use rustc_index::IndexVec;
9-
use rustc_middle::mir::{BasicBlock, Body, Location};
8+
use rustc_middle::mir::{BasicBlock, Location};
109
use rustc_middle::ty::{self, RegionVid};
10+
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1111
use std::fmt::Debug;
1212
use std::rc::Rc;
1313

14-
use crate::dataflow::BorrowIndex;
15-
16-
/// Maps between a `Location` and a `PointIndex` (and vice versa).
17-
pub(crate) struct RegionValueElements {
18-
/// For each basic block, how many points are contained within?
19-
statements_before_block: IndexVec<BasicBlock, usize>,
20-
21-
/// Map backward from each point to the basic block that it
22-
/// belongs to.
23-
basic_blocks: IndexVec<PointIndex, BasicBlock>,
24-
25-
num_points: usize,
26-
}
27-
28-
impl RegionValueElements {
29-
pub(crate) fn new(body: &Body<'_>) -> Self {
30-
let mut num_points = 0;
31-
let statements_before_block: IndexVec<BasicBlock, usize> = body
32-
.basic_blocks
33-
.iter()
34-
.map(|block_data| {
35-
let v = num_points;
36-
num_points += block_data.statements.len() + 1;
37-
v
38-
})
39-
.collect();
40-
debug!("RegionValueElements: statements_before_block={:#?}", statements_before_block);
41-
debug!("RegionValueElements: num_points={:#?}", num_points);
42-
43-
let mut basic_blocks = IndexVec::with_capacity(num_points);
44-
for (bb, bb_data) in body.basic_blocks.iter_enumerated() {
45-
basic_blocks.extend((0..=bb_data.statements.len()).map(|_| bb));
46-
}
47-
48-
Self { statements_before_block, basic_blocks, num_points }
49-
}
50-
51-
/// Total number of point indices
52-
pub(crate) fn num_points(&self) -> usize {
53-
self.num_points
54-
}
55-
56-
/// Converts a `Location` into a `PointIndex`. O(1).
57-
pub(crate) fn point_from_location(&self, location: Location) -> PointIndex {
58-
let Location { block, statement_index } = location;
59-
let start_index = self.statements_before_block[block];
60-
PointIndex::new(start_index + statement_index)
61-
}
62-
63-
/// Converts a `Location` into a `PointIndex`. O(1).
64-
pub(crate) fn entry_point(&self, block: BasicBlock) -> PointIndex {
65-
let start_index = self.statements_before_block[block];
66-
PointIndex::new(start_index)
67-
}
68-
69-
/// Return the PointIndex for the block start of this index.
70-
pub(crate) fn to_block_start(&self, index: PointIndex) -> PointIndex {
71-
PointIndex::new(self.statements_before_block[self.basic_blocks[index]])
72-
}
73-
74-
/// Converts a `PointIndex` back to a location. O(1).
75-
pub(crate) fn to_location(&self, index: PointIndex) -> Location {
76-
assert!(index.index() < self.num_points);
77-
let block = self.basic_blocks[index];
78-
let start_index = self.statements_before_block[block];
79-
let statement_index = index.index() - start_index;
80-
Location { block, statement_index }
81-
}
82-
83-
/// Sometimes we get point-indices back from bitsets that may be
84-
/// out of range (because they round up to the nearest 2^N number
85-
/// of bits). Use this function to filter such points out if you
86-
/// like.
87-
pub(crate) fn point_in_range(&self, index: PointIndex) -> bool {
88-
index.index() < self.num_points
89-
}
90-
}
91-
92-
rustc_index::newtype_index! {
93-
/// A single integer representing a `Location` in the MIR control-flow
94-
/// graph. Constructed efficiently from `RegionValueElements`.
95-
#[orderable]
96-
#[debug_format = "PointIndex({})"]
97-
pub struct PointIndex {}
98-
}
14+
use crate::BorrowIndex;
9915

10016
rustc_index::newtype_index! {
10117
/// A single integer representing a `ty::Placeholder`.
@@ -123,7 +39,7 @@ pub(crate) enum RegionElement {
12339
/// an interval matrix storing liveness ranges for each region-vid.
12440
pub(crate) struct LivenessValues {
12541
/// The map from locations to points.
126-
elements: Rc<RegionValueElements>,
42+
elements: Rc<DenseLocationMap>,
12743

12844
/// For each region: the points where it is live.
12945
points: SparseIntervalMatrix<RegionVid, PointIndex>,
@@ -155,9 +71,9 @@ impl LiveLoans {
15571

15672
impl LivenessValues {
15773
/// Create an empty map of regions to locations where they're live.
158-
pub(crate) fn new(elements: Rc<RegionValueElements>) -> Self {
74+
pub(crate) fn new(elements: Rc<DenseLocationMap>) -> Self {
15975
LivenessValues {
160-
points: SparseIntervalMatrix::new(elements.num_points),
76+
points: SparseIntervalMatrix::new(elements.num_points()),
16177
elements,
16278
loans: None,
16379
}
@@ -298,7 +214,7 @@ impl PlaceholderIndices {
298214
/// it would also contain various points from within the function.
299215
#[derive(Clone)]
300216
pub(crate) struct RegionValues<N: Idx> {
301-
elements: Rc<RegionValueElements>,
217+
elements: Rc<DenseLocationMap>,
302218
placeholder_indices: Rc<PlaceholderIndices>,
303219
points: SparseIntervalMatrix<N, PointIndex>,
304220
free_regions: SparseBitMatrix<N, RegionVid>,
@@ -313,14 +229,14 @@ impl<N: Idx> RegionValues<N> {
313229
/// Each of the regions in num_region_variables will be initialized with an
314230
/// empty set of points and no causal information.
315231
pub(crate) fn new(
316-
elements: &Rc<RegionValueElements>,
232+
elements: &Rc<DenseLocationMap>,
317233
num_universal_regions: usize,
318234
placeholder_indices: &Rc<PlaceholderIndices>,
319235
) -> Self {
320236
let num_placeholders = placeholder_indices.len();
321237
Self {
322238
elements: elements.clone(),
323-
points: SparseIntervalMatrix::new(elements.num_points),
239+
points: SparseIntervalMatrix::new(elements.num_points()),
324240
placeholder_indices: placeholder_indices.clone(),
325241
free_regions: SparseBitMatrix::new(num_universal_regions),
326242
placeholders: SparseBitMatrix::new(num_placeholders),
@@ -486,7 +402,7 @@ impl ToElementIndex for ty::PlaceholderRegion {
486402

487403
/// For debugging purposes, returns a pretty-printed string of the given points.
488404
pub(crate) fn pretty_print_points(
489-
elements: &RegionValueElements,
405+
elements: &DenseLocationMap,
490406
points: impl IntoIterator<Item = PointIndex>,
491407
) -> String {
492408
pretty_print_region_elements(

compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use rustc_data_structures::vec_linked_list as vll;
22
use rustc_index::IndexVec;
33
use rustc_middle::mir::visit::{PlaceContext, Visitor};
44
use rustc_middle::mir::{Body, Local, Location};
5+
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
56

67
use crate::def_use::{self, DefUse};
7-
use crate::region_infer::values::{PointIndex, RegionValueElements};
88

99
/// A map that cross references each local with the locations where it
1010
/// is defined (assigned), used, or dropped. Used during liveness
@@ -60,7 +60,7 @@ impl vll::LinkElem for Appearance {
6060
impl LocalUseMap {
6161
pub(crate) fn build(
6262
live_locals: &[Local],
63-
elements: &RegionValueElements,
63+
elements: &DenseLocationMap,
6464
body: &Body<'_>,
6565
) -> Self {
6666
let nones = IndexVec::from_elem(None, &body.local_decls);
@@ -103,7 +103,7 @@ impl LocalUseMap {
103103

104104
struct LocalUseMapBuild<'me> {
105105
local_use_map: &'me mut LocalUseMap,
106-
elements: &'me RegionValueElements,
106+
elements: &'me DenseLocationMap,
107107

108108
// Vector used in `visit_local` to signal which `Local`s do we need
109109
// def/use/drop information on, constructed from `live_locals` (that
@@ -144,7 +144,7 @@ impl LocalUseMapBuild<'_> {
144144
}
145145

146146
fn insert(
147-
elements: &RegionValueElements,
147+
elements: &DenseLocationMap,
148148
first_appearance: &mut Option<AppearanceIndex>,
149149
appearances: &mut IndexVec<AppearanceIndex, Appearance>,
150150
location: Location,

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use rustc_middle::ty::visit::TypeVisitable;
66
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
77
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
88
use rustc_mir_dataflow::move_paths::MoveData;
9+
use rustc_mir_dataflow::points::DenseLocationMap;
910
use rustc_mir_dataflow::ResultsCursor;
1011
use std::rc::Rc;
1112

1213
use crate::{
1314
constraints::OutlivesConstraintSet,
1415
facts::{AllFacts, AllFactsExt},
1516
location::LocationTable,
16-
region_infer::values::{LivenessValues, RegionValueElements},
17+
region_infer::values::LivenessValues,
1718
universal_regions::UniversalRegions,
1819
};
1920

@@ -34,7 +35,7 @@ mod trace;
3435
pub(super) fn generate<'mir, 'tcx>(
3536
typeck: &mut TypeChecker<'_, 'tcx>,
3637
body: &Body<'tcx>,
37-
elements: &Rc<RegionValueElements>,
38+
elements: &Rc<DenseLocationMap>,
3839
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
3940
move_data: &MoveData<'tcx>,
4041
location_table: &LocationTable,

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_infer::infer::outlives::for_liveness;
77
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
88
use rustc_middle::traits::query::DropckOutlivesResult;
99
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
10+
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1011
use rustc_span::DUMMY_SP;
1112
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
1213
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
@@ -17,7 +18,7 @@ use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
1718
use rustc_mir_dataflow::ResultsCursor;
1819

1920
use crate::{
20-
region_infer::values::{self, LiveLoans, PointIndex, RegionValueElements},
21+
region_infer::values::{self, LiveLoans},
2122
type_check::liveness::local_use_map::LocalUseMap,
2223
type_check::liveness::polonius,
2324
type_check::NormalizeLocation,
@@ -41,7 +42,7 @@ use crate::{
4142
pub(super) fn trace<'mir, 'tcx>(
4243
typeck: &mut TypeChecker<'_, 'tcx>,
4344
body: &Body<'tcx>,
44-
elements: &Rc<RegionValueElements>,
45+
elements: &Rc<DenseLocationMap>,
4546
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
4647
move_data: &MoveData<'tcx>,
4748
relevant_live_locals: Vec<Local>,
@@ -105,7 +106,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
105106
typeck: &'me mut TypeChecker<'typeck, 'tcx>,
106107

107108
/// Defines the `PointIndex` mapping
108-
elements: &'me RegionValueElements,
109+
elements: &'me DenseLocationMap,
109110

110111
/// MIR we are analyzing.
111112
body: &'me Body<'tcx>,
@@ -570,7 +571,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
570571
}
571572

572573
fn make_all_regions_live(
573-
elements: &RegionValueElements,
574+
elements: &DenseLocationMap,
574575
typeck: &mut TypeChecker<'_, 'tcx>,
575576
value: impl TypeVisitable<TyCtxt<'tcx>>,
576577
live_at: &IntervalSet<PointIndex>,

compiler/rustc_borrowck/src/type_check/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_middle::ty::{
3535
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3636
};
3737
use rustc_middle::ty::{GenericArgsRef, UserArgs};
38+
use rustc_mir_dataflow::points::DenseLocationMap;
3839
use rustc_span::def_id::CRATE_DEF_ID;
3940
use rustc_span::source_map::Spanned;
4041
use rustc_span::symbol::sym;
@@ -59,9 +60,7 @@ use crate::{
5960
location::LocationTable,
6061
member_constraints::MemberConstraintSet,
6162
path_utils,
62-
region_infer::values::{
63-
LivenessValues, PlaceholderIndex, PlaceholderIndices, RegionValueElements,
64-
},
63+
region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices},
6564
region_infer::TypeTest,
6665
type_check::free_region_relations::{CreateResult, UniversalRegionRelations},
6766
universal_regions::{DefiningTy, UniversalRegions},
@@ -134,7 +133,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
134133
all_facts: &mut Option<AllFacts>,
135134
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
136135
move_data: &MoveData<'tcx>,
137-
elements: &Rc<RegionValueElements>,
136+
elements: &Rc<DenseLocationMap>,
138137
upvars: &[&ty::CapturedPlace<'tcx>],
139138
use_polonius: bool,
140139
) -> MirTypeckResults<'tcx> {
@@ -556,7 +555,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
556555
let all_facts = &mut None;
557556
let mut constraints = Default::default();
558557
let mut liveness_constraints =
559-
LivenessValues::new(Rc::new(RegionValueElements::new(promoted_body)));
558+
LivenessValues::new(Rc::new(DenseLocationMap::new(promoted_body)));
560559
// Don't try to add borrow_region facts for the promoted MIR
561560

562561
let mut swap_constraints = |this: &mut Self| {

0 commit comments

Comments
 (0)