Skip to content

Commit 2886b36

Browse files
committed
Auto merge of #145077 - Zalathar:rollup-0k4194x, r=Zalathar
Rollup of 19 pull requests Successful merges: - #144400 (`tests/ui/issues/`: The Issues Strike Back [3/N]) - #144764 ([codegen] assume the tag, not the relative discriminant) - #144807 (Streamline config in bootstrap) - #144899 (Print CGU reuse statistics in `-Zprint-mono-items`) - #144909 (Add new `test::print_merged_doctests_times` used by rustdoc to display more detailed time information) - #144912 (Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution.) - #144914 (Add support for `ty::Instance` path shortening in diagnostics) - #144931 ([win][arm64ec] Fix msvc-wholearchive for Arm64EC) - #144999 (coverage: Remove all unstable support for MC/DC instrumentation) - #145009 (A couple small changes for rust-analyzer next-solver work) - #145030 (GVN: Do not flatten derefs with ProjectionElem::Index. ) - #145042 (stdarch subtree update) - #145047 (move `type_check` out of `compute_regions`) - #145051 (Prevent name collisions with internal implementation details) - #145053 (Add a lot of NLL `known-bug` tests) - #145055 (Move metadata symbol export from exported_non_generic_symbols to exported_symbols) - #145057 (Clean up some resolved test regressions of const trait removals in std) - #145068 (Readd myself to review queue) - #145070 (Add minimal `armv7a-vex-v5` tier three target) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67d45f4 + f6283ae commit 2886b36

File tree

265 files changed

+8659
-9715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+8659
-9715
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::borrow::Cow;
1919
use std::cell::{OnceCell, RefCell};
2020
use std::marker::PhantomData;
2121
use std::ops::{ControlFlow, Deref};
22+
use std::rc::Rc;
2223

2324
use borrow_set::LocalsStateAtExit;
2425
use root_cx::BorrowCheckRootCtxt;
@@ -44,6 +45,7 @@ use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}
4445
use rustc_mir_dataflow::move_paths::{
4546
InitIndex, InitLocation, LookupResult, MoveData, MovePathIndex,
4647
};
48+
use rustc_mir_dataflow::points::DenseLocationMap;
4749
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor, visit_results};
4850
use rustc_session::lint::builtin::{TAIL_EXPR_DROP_ORDER, UNUSED_MUT};
4951
use rustc_span::{ErrorGuaranteed, Span, Symbol};
@@ -60,11 +62,14 @@ use crate::path_utils::*;
6062
use crate::place_ext::PlaceExt;
6163
use crate::places_conflict::{PlaceConflictBias, places_conflict};
6264
use crate::polonius::PoloniusDiagnosticsContext;
63-
use crate::polonius::legacy::{PoloniusLocationTable, PoloniusOutput};
65+
use crate::polonius::legacy::{
66+
PoloniusFacts, PoloniusFactsExt, PoloniusLocationTable, PoloniusOutput,
67+
};
6468
use crate::prefixes::PrefixSet;
6569
use crate::region_infer::RegionInferenceContext;
6670
use crate::renumber::RegionCtxt;
6771
use crate::session_diagnostics::VarNeedNotMut;
72+
use crate::type_check::MirTypeckResults;
6873

6974
mod borrow_set;
7075
mod borrowck_errors;
@@ -321,7 +326,34 @@ fn do_mir_borrowck<'tcx>(
321326
let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
322327
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
323328

324-
// Compute non-lexical lifetimes.
329+
let location_map = Rc::new(DenseLocationMap::new(body));
330+
331+
let polonius_input = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_input())
332+
|| infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
333+
let mut polonius_facts =
334+
(polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());
335+
336+
// Run the MIR type-checker.
337+
let MirTypeckResults {
338+
constraints,
339+
universal_region_relations,
340+
opaque_type_values,
341+
polonius_context,
342+
} = type_check::type_check(
343+
root_cx,
344+
&infcx,
345+
body,
346+
&promoted,
347+
universal_regions,
348+
&location_table,
349+
&borrow_set,
350+
&mut polonius_facts,
351+
&move_data,
352+
Rc::clone(&location_map),
353+
);
354+
355+
// Compute non-lexical lifetimes using the constraints computed
356+
// by typechecking the MIR body.
325357
let nll::NllOutput {
326358
regioncx,
327359
polonius_input,
@@ -332,14 +364,19 @@ fn do_mir_borrowck<'tcx>(
332364
} = nll::compute_regions(
333365
root_cx,
334366
&infcx,
335-
universal_regions,
336367
body,
337-
&promoted,
338368
&location_table,
339369
&move_data,
340370
&borrow_set,
371+
location_map,
372+
universal_region_relations,
373+
constraints,
374+
polonius_facts,
375+
polonius_context,
341376
);
342377

378+
regioncx.infer_opaque_types(root_cx, &infcx, opaque_type_values);
379+
343380
// Dump MIR results into a file, if that is enabled. This lets us
344381
// write unit-tests, as well as helping with debugging.
345382
nll::dump_nll_mir(&infcx, body, &regioncx, &opt_closure_req, &borrow_set);

compiler/rustc_borrowck/src/nll.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::path::PathBuf;
55
use std::rc::Rc;
66
use std::str::FromStr;
77

8-
use polonius_engine::{Algorithm, Output};
8+
use polonius_engine::{Algorithm, AllFacts, Output};
9+
use rustc_data_structures::frozen::Frozen;
910
use rustc_index::IndexSlice;
1011
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
1112
use rustc_middle::mir::{Body, PassWhere, Promoted, create_dump_file, dump_enabled, dump_mir};
@@ -18,14 +19,16 @@ use rustc_span::sym;
1819
use tracing::{debug, instrument};
1920

2021
use crate::borrow_set::BorrowSet;
22+
use crate::consumers::RustcFacts;
2123
use crate::diagnostics::RegionErrors;
2224
use crate::handle_placeholders::compute_sccs_applying_placeholder_outlives_constraints;
23-
use crate::polonius::PoloniusDiagnosticsContext;
2425
use crate::polonius::legacy::{
2526
PoloniusFacts, PoloniusFactsExt, PoloniusLocationTable, PoloniusOutput,
2627
};
28+
use crate::polonius::{PoloniusContext, PoloniusDiagnosticsContext};
2729
use crate::region_infer::RegionInferenceContext;
28-
use crate::type_check::{self, MirTypeckResults};
30+
use crate::type_check::MirTypeckRegionConstraints;
31+
use crate::type_check::free_region_relations::UniversalRegionRelations;
2932
use crate::universal_regions::UniversalRegions;
3033
use crate::{
3134
BorrowCheckRootCtxt, BorrowckInferCtxt, ClosureOutlivesSubject, ClosureRegionRequirements,
@@ -76,41 +79,18 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
7679
pub(crate) fn compute_regions<'tcx>(
7780
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
7881
infcx: &BorrowckInferCtxt<'tcx>,
79-
universal_regions: UniversalRegions<'tcx>,
8082
body: &Body<'tcx>,
81-
promoted: &IndexSlice<Promoted, Body<'tcx>>,
8283
location_table: &PoloniusLocationTable,
8384
move_data: &MoveData<'tcx>,
8485
borrow_set: &BorrowSet<'tcx>,
86+
location_map: Rc<DenseLocationMap>,
87+
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
88+
constraints: MirTypeckRegionConstraints<'tcx>,
89+
mut polonius_facts: Option<AllFacts<RustcFacts>>,
90+
polonius_context: Option<PoloniusContext>,
8591
) -> NllOutput<'tcx> {
86-
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
87-
let polonius_input = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_input())
88-
|| is_polonius_legacy_enabled;
8992
let polonius_output = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_output())
90-
|| is_polonius_legacy_enabled;
91-
let mut polonius_facts =
92-
(polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());
93-
94-
let location_map = Rc::new(DenseLocationMap::new(body));
95-
96-
// Run the MIR type-checker.
97-
let MirTypeckResults {
98-
constraints,
99-
universal_region_relations,
100-
opaque_type_values,
101-
polonius_context,
102-
} = type_check::type_check(
103-
root_cx,
104-
infcx,
105-
body,
106-
promoted,
107-
universal_regions,
108-
location_table,
109-
borrow_set,
110-
&mut polonius_facts,
111-
move_data,
112-
Rc::clone(&location_map),
113-
);
93+
|| infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
11494

11595
let lowered_constraints = compute_sccs_applying_placeholder_outlives_constraints(
11696
constraints,
@@ -173,8 +153,6 @@ pub(crate) fn compute_regions<'tcx>(
173153
infcx.set_tainted_by_errors(guar);
174154
}
175155

176-
regioncx.infer_opaque_types(root_cx, infcx, opaque_type_values);
177-
178156
NllOutput {
179157
regioncx,
180158
polonius_input: polonius_facts.map(Box::new),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ fn data_id_for_static(
310310
// `extern_with_linkage_foo` will instead be initialized to
311311
// zero.
312312

313-
let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name);
313+
let ref_name = format!(
314+
"_rust_extern_with_linkage_{:016x}_{symbol_name}",
315+
tcx.stable_crate_id(LOCAL_CRATE)
316+
);
314317
let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap();
315318
let mut data = DataDescription::new();
316319
data.set_align(align);

compiler/rustc_codegen_gcc/src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_codegen_ssa::traits::{
66
BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods,
77
};
88
use rustc_hir::def::DefKind;
9+
use rustc_hir::def_id::LOCAL_CRATE;
910
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1011
use rustc_middle::mir::interpret::{
1112
self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint,
@@ -384,8 +385,8 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
384385
// linkage and there are no definitions), then
385386
// `extern_with_linkage_foo` will instead be initialized to
386387
// zero.
387-
let mut real_name = "_rust_extern_with_linkage_".to_string();
388-
real_name.push_str(sym);
388+
let real_name =
389+
format!("_rust_extern_with_linkage_{:016x}_{sym}", cx.tcx.stable_crate_id(LOCAL_CRATE));
389390
let global2 = cx.define_global(&real_name, gcc_type, is_tls, attrs.link_section);
390391
// TODO(antoyo): set linkage.
391392
let value = cx.const_ptrcast(global1.get_address(None), gcc_type);

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,48 +1886,4 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18861886
) {
18871887
self.call_intrinsic("llvm.instrprof.increment", &[], &[fn_name, hash, num_counters, index]);
18881888
}
1889-
1890-
/// Emits a call to `llvm.instrprof.mcdc.parameters`.
1891-
///
1892-
/// This doesn't produce any code directly, but is used as input by
1893-
/// the LLVM pass that handles coverage instrumentation.
1894-
///
1895-
/// (See clang's [`CodeGenPGO::emitMCDCParameters`] for comparison.)
1896-
///
1897-
/// [`CodeGenPGO::emitMCDCParameters`]:
1898-
/// https://github.com/rust-lang/llvm-project/blob/5399a24/clang/lib/CodeGen/CodeGenPGO.cpp#L1124
1899-
#[instrument(level = "debug", skip(self))]
1900-
pub(crate) fn mcdc_parameters(
1901-
&mut self,
1902-
fn_name: &'ll Value,
1903-
hash: &'ll Value,
1904-
bitmap_bits: &'ll Value,
1905-
) {
1906-
self.call_intrinsic("llvm.instrprof.mcdc.parameters", &[], &[fn_name, hash, bitmap_bits]);
1907-
}
1908-
1909-
#[instrument(level = "debug", skip(self))]
1910-
pub(crate) fn mcdc_tvbitmap_update(
1911-
&mut self,
1912-
fn_name: &'ll Value,
1913-
hash: &'ll Value,
1914-
bitmap_index: &'ll Value,
1915-
mcdc_temp: &'ll Value,
1916-
) {
1917-
let args = &[fn_name, hash, bitmap_index, mcdc_temp];
1918-
self.call_intrinsic("llvm.instrprof.mcdc.tvbitmap.update", &[], args);
1919-
}
1920-
1921-
#[instrument(level = "debug", skip(self))]
1922-
pub(crate) fn mcdc_condbitmap_reset(&mut self, mcdc_temp: &'ll Value) {
1923-
self.store(self.const_i32(0), mcdc_temp, self.tcx.data_layout.i32_align.abi);
1924-
}
1925-
1926-
#[instrument(level = "debug", skip(self))]
1927-
pub(crate) fn mcdc_condbitmap_update(&mut self, cond_index: &'ll Value, mcdc_temp: &'ll Value) {
1928-
let align = self.tcx.data_layout.i32_align.abi;
1929-
let current_tv_index = self.load(self.cx.type_i32(), mcdc_temp, align);
1930-
let new_tv_index = self.add(current_tv_index, cond_index);
1931-
self.store(new_tv_index, mcdc_temp, align);
1932-
}
19331889
}

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_codegen_ssa::common;
55
use rustc_codegen_ssa::traits::*;
66
use rustc_hir::LangItem;
77
use rustc_hir::def::DefKind;
8-
use rustc_hir::def_id::DefId;
8+
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
99
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1010
use rustc_middle::mir::interpret::{
1111
Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar,
@@ -191,8 +191,8 @@ fn check_and_apply_linkage<'ll, 'tcx>(
191191
// linkage and there are no definitions), then
192192
// `extern_with_linkage_foo` will instead be initialized to
193193
// zero.
194-
let mut real_name = "_rust_extern_with_linkage_".to_string();
195-
real_name.push_str(sym);
194+
let real_name =
195+
format!("_rust_extern_with_linkage_{:016x}_{sym}", cx.tcx.stable_crate_id(LOCAL_CRATE));
196196
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
197197
cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
198198
span: cx.tcx.def_span(def_id),

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,6 @@ pub(crate) struct CounterExpression {
7373
pub(crate) rhs: Counter,
7474
}
7575

76-
pub(crate) mod mcdc {
77-
use rustc_middle::mir::coverage::{ConditionId, ConditionInfo, DecisionInfo};
78-
79-
/// Must match the layout of `LLVMRustMCDCDecisionParameters`.
80-
#[repr(C)]
81-
#[derive(Clone, Copy, Debug, Default)]
82-
pub(crate) struct DecisionParameters {
83-
bitmap_idx: u32,
84-
num_conditions: u16,
85-
}
86-
87-
type LLVMConditionId = i16;
88-
89-
/// Must match the layout of `LLVMRustMCDCBranchParameters`.
90-
#[repr(C)]
91-
#[derive(Clone, Copy, Debug, Default)]
92-
pub(crate) struct BranchParameters {
93-
condition_id: LLVMConditionId,
94-
condition_ids: [LLVMConditionId; 2],
95-
}
96-
97-
impl From<ConditionInfo> for BranchParameters {
98-
fn from(value: ConditionInfo) -> Self {
99-
let to_llvm_cond_id = |cond_id: Option<ConditionId>| {
100-
cond_id.and_then(|id| LLVMConditionId::try_from(id.as_usize()).ok()).unwrap_or(-1)
101-
};
102-
let ConditionInfo { condition_id, true_next_id, false_next_id } = value;
103-
Self {
104-
condition_id: to_llvm_cond_id(Some(condition_id)),
105-
condition_ids: [to_llvm_cond_id(false_next_id), to_llvm_cond_id(true_next_id)],
106-
}
107-
}
108-
}
109-
110-
impl From<DecisionInfo> for DecisionParameters {
111-
fn from(info: DecisionInfo) -> Self {
112-
let DecisionInfo { bitmap_idx, num_conditions } = info;
113-
Self { bitmap_idx, num_conditions }
114-
}
115-
}
116-
}
117-
11876
/// A span of source code coordinates to be embedded in coverage metadata.
11977
///
12078
/// Must match the layout of `LLVMRustCoverageSpan`.
@@ -148,26 +106,14 @@ pub(crate) struct Regions {
148106
pub(crate) code_regions: Vec<CodeRegion>,
149107
pub(crate) expansion_regions: Vec<ExpansionRegion>,
150108
pub(crate) branch_regions: Vec<BranchRegion>,
151-
pub(crate) mcdc_branch_regions: Vec<MCDCBranchRegion>,
152-
pub(crate) mcdc_decision_regions: Vec<MCDCDecisionRegion>,
153109
}
154110

155111
impl Regions {
156112
/// Returns true if none of this structure's tables contain any regions.
157113
pub(crate) fn has_no_regions(&self) -> bool {
158-
let Self {
159-
code_regions,
160-
expansion_regions,
161-
branch_regions,
162-
mcdc_branch_regions,
163-
mcdc_decision_regions,
164-
} = self;
165-
166-
code_regions.is_empty()
167-
&& expansion_regions.is_empty()
168-
&& branch_regions.is_empty()
169-
&& mcdc_branch_regions.is_empty()
170-
&& mcdc_decision_regions.is_empty()
114+
let Self { code_regions, expansion_regions, branch_regions } = self;
115+
116+
code_regions.is_empty() && expansion_regions.is_empty() && branch_regions.is_empty()
171117
}
172118
}
173119

@@ -195,21 +141,3 @@ pub(crate) struct BranchRegion {
195141
pub(crate) true_counter: Counter,
196142
pub(crate) false_counter: Counter,
197143
}
198-
199-
/// Must match the layout of `LLVMRustCoverageMCDCBranchRegion`.
200-
#[derive(Clone, Debug)]
201-
#[repr(C)]
202-
pub(crate) struct MCDCBranchRegion {
203-
pub(crate) cov_span: CoverageSpan,
204-
pub(crate) true_counter: Counter,
205-
pub(crate) false_counter: Counter,
206-
pub(crate) mcdc_branch_params: mcdc::BranchParameters,
207-
}
208-
209-
/// Must match the layout of `LLVMRustCoverageMCDCDecisionRegion`.
210-
#[derive(Clone, Debug)]
211-
#[repr(C)]
212-
pub(crate) struct MCDCDecisionRegion {
213-
pub(crate) cov_span: CoverageSpan,
214-
pub(crate) mcdc_decision_params: mcdc::DecisionParameters,
215-
}

0 commit comments

Comments
 (0)