Skip to content

Commit

Permalink
Auto merge of rust-lang#3007 - rust-lang:rustup-2023-08-03, r=oli-obk
Browse files Browse the repository at this point in the history
Automatic sync from rustc
  • Loading branch information
bors committed Aug 3, 2023
2 parents 042cfd8 + 9bb8b66 commit 460e92b
Show file tree
Hide file tree
Showing 204 changed files with 1,271 additions and 1,121 deletions.
6 changes: 0 additions & 6 deletions compiler/rustc_ast/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ pub struct FormatArguments {
names: FxHashMap<Symbol, usize>,
}

// FIXME: Rustdoc has trouble proving Send/Sync for this. See #106930.
#[cfg(parallel_compiler)]
unsafe impl Sync for FormatArguments {}
#[cfg(parallel_compiler)]
unsafe impl Send for FormatArguments {}

impl FormatArguments {
pub fn new() -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
.universal_regions()
.defining_ty
.upvar_tys()
.iter()
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
{
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/var_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fr: RegionVid,
) -> Option<usize> {
let upvar_index =
self.universal_regions().defining_ty.upvar_tys().position(|upvar_ty| {
self.universal_regions().defining_ty.upvar_tys().iter().position(|upvar_ty| {
debug!("get_upvar_index_for_region: upvar_ty={upvar_ty:?}");
tcx.any_free_region_meets(&upvar_ty, |r| {
let r = r.as_var();
Expand All @@ -52,7 +52,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
})
})?;

let upvar_ty = self.universal_regions().defining_ty.upvar_tys().nth(upvar_index);
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().get(upvar_index);

debug!(
"get_upvar_index_for_region: found {fr:?} in upvar {upvar_index} which has type {upvar_ty:?}",
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
) {
self.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
},
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive },
))),
locations,
category,
Expand Down
27 changes: 11 additions & 16 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,25 +791,20 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
(adt_def.variant(FIRST_VARIANT), args)
}
ty::Closure(_, args) => {
return match args
.as_closure()
.tupled_upvars_ty()
.tuple_fields()
.get(field.index())
{
return match args.as_closure().upvar_tys().get(field.index()) {
Some(&ty) => Ok(ty),
None => Err(FieldAccessError::OutOfRange {
field_count: args.as_closure().upvar_tys().count(),
field_count: args.as_closure().upvar_tys().len(),
}),
};
}
ty::Generator(_, args, _) => {
// Only prefix fields (upvars and current state) are
// accessible without a variant index.
return match args.as_generator().prefix_tys().nth(field.index()) {
Some(ty) => Ok(ty),
return match args.as_generator().prefix_tys().get(field.index()) {
Some(ty) => Ok(*ty),
None => Err(FieldAccessError::OutOfRange {
field_count: args.as_generator().prefix_tys().count(),
field_count: args.as_generator().prefix_tys().len(),
}),
};
}
Expand Down Expand Up @@ -1772,21 +1767,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
AggregateKind::Closure(_, args) => {
match args.as_closure().upvar_tys().nth(field_index.as_usize()) {
Some(ty) => Ok(ty),
match args.as_closure().upvar_tys().get(field_index.as_usize()) {
Some(ty) => Ok(*ty),
None => Err(FieldAccessError::OutOfRange {
field_count: args.as_closure().upvar_tys().count(),
field_count: args.as_closure().upvar_tys().len(),
}),
}
}
AggregateKind::Generator(_, args, _) => {
// It doesn't make sense to look at a field beyond the prefix;
// these require a variant index, and are not initialized in
// aggregate rvalues.
match args.as_generator().prefix_tys().nth(field_index.as_usize()) {
Some(ty) => Ok(ty),
match args.as_generator().prefix_tys().get(field_index.as_usize()) {
Some(ty) => Ok(*ty),
None => Err(FieldAccessError::OutOfRange {
field_count: args.as_generator().prefix_tys().count(),
field_count: args.as_generator().prefix_tys().len(),
}),
}
}
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//! The code in this file doesn't *do anything* with those results; it
//! just returns them for other code to use.
use either::Either;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic;
use rustc_hir as hir;
Expand Down Expand Up @@ -115,14 +114,12 @@ impl<'tcx> DefiningTy<'tcx> {
/// not a closure or generator, there are no upvars, and hence it
/// will be an empty list. The order of types in this list will
/// match up with the upvar order in the HIR, typesystem, and MIR.
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> {
match self {
DefiningTy::Closure(_, args) => Either::Left(args.as_closure().upvar_tys()),
DefiningTy::Generator(_, args, _) => {
Either::Right(Either::Left(args.as_generator().upvar_tys()))
}
DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(),
DefiningTy::Generator(_, args, _) => args.as_generator().upvar_tys(),
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
Either::Right(Either::Right(iter::empty()))
ty::List::empty()
}
}
}
Expand Down
194 changes: 194 additions & 0 deletions compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,197 @@ impl CounterExpression {
Self { kind, lhs, rhs }
}
}

/// Corresponds to enum `llvm::coverage::CounterMappingRegion::RegionKind`.
///
/// Must match the layout of `LLVMRustCounterMappingRegionKind`.
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub enum RegionKind {
/// A CodeRegion associates some code with a counter
CodeRegion = 0,

/// An ExpansionRegion represents a file expansion region that associates
/// a source range with the expansion of a virtual source file, such as
/// for a macro instantiation or #include file.
ExpansionRegion = 1,

/// A SkippedRegion represents a source range with code that was skipped
/// by a preprocessor or similar means.
SkippedRegion = 2,

/// A GapRegion is like a CodeRegion, but its count is only set as the
/// line execution count when its the only region in the line.
GapRegion = 3,

/// A BranchRegion represents leaf-level boolean expressions and is
/// associated with two counters, each representing the number of times the
/// expression evaluates to true or false.
BranchRegion = 4,
}

/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
/// coverage map, in accordance with the
/// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
/// The struct composes fields representing the `Counter` type and value(s) (injected counter
/// ID, or expression type and operands), the source file (an indirect index into a "filenames
/// array", encoded separately), and source location (start and end positions of the represented
/// code region).
///
/// Corresponds to struct `llvm::coverage::CounterMappingRegion`.
///
/// Must match the layout of `LLVMRustCounterMappingRegion`.
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct CounterMappingRegion {
/// The counter type and type-dependent counter data, if any.
counter: Counter,

/// If the `RegionKind` is a `BranchRegion`, this represents the counter
/// for the false branch of the region.
false_counter: Counter,

/// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the
/// file_id is an index into a function-specific `virtual_file_mapping` array of indexes
/// that, in turn, are used to look up the filename for this region.
file_id: u32,

/// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find
/// the mapping regions created as a result of macro expansion, by checking if their file id
/// matches the expanded file id.
expanded_file_id: u32,

/// 1-based starting line of the mapping region.
start_line: u32,

/// 1-based starting column of the mapping region.
start_col: u32,

/// 1-based ending line of the mapping region.
end_line: u32,

/// 1-based ending column of the mapping region. If the high bit is set, the current
/// mapping region is a gap area.
end_col: u32,

kind: RegionKind,
}

impl CounterMappingRegion {
pub(crate) fn code_region(
counter: Counter,
file_id: u32,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self {
counter,
false_counter: Counter::zero(),
file_id,
expanded_file_id: 0,
start_line,
start_col,
end_line,
end_col,
kind: RegionKind::CodeRegion,
}
}

// This function might be used in the future; the LLVM API is still evolving, as is coverage
// support.
#[allow(dead_code)]
pub(crate) fn branch_region(
counter: Counter,
false_counter: Counter,
file_id: u32,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self {
counter,
false_counter,
file_id,
expanded_file_id: 0,
start_line,
start_col,
end_line,
end_col,
kind: RegionKind::BranchRegion,
}
}

// This function might be used in the future; the LLVM API is still evolving, as is coverage
// support.
#[allow(dead_code)]
pub(crate) fn expansion_region(
file_id: u32,
expanded_file_id: u32,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self {
counter: Counter::zero(),
false_counter: Counter::zero(),
file_id,
expanded_file_id,
start_line,
start_col,
end_line,
end_col,
kind: RegionKind::ExpansionRegion,
}
}

// This function might be used in the future; the LLVM API is still evolving, as is coverage
// support.
#[allow(dead_code)]
pub(crate) fn skipped_region(
file_id: u32,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self {
counter: Counter::zero(),
false_counter: Counter::zero(),
file_id,
expanded_file_id: 0,
start_line,
start_col,
end_line,
end_col,
kind: RegionKind::SkippedRegion,
}
}

// This function might be used in the future; the LLVM API is still evolving, as is coverage
// support.
#[allow(dead_code)]
pub(crate) fn gap_region(
counter: Counter,
file_id: u32,
start_line: u32,
start_col: u32,
end_line: u32,
end_col: u32,
) -> Self {
Self {
counter,
false_counter: Counter::zero(),
file_id,
expanded_file_id: 0,
start_line,
start_col,
end_line,
end_col: (1_u32 << 31) | end_col,
kind: RegionKind::GapRegion,
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use super::ffi::*;
use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};

use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::bug;
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::common::CodegenCx;
use crate::coverageinfo;
use crate::coverageinfo::map_data::{Counter, CounterExpression};
use crate::coverageinfo::ffi::{Counter, CounterExpression, CounterMappingRegion};
use crate::llvm;

use llvm::coverageinfo::CounterMappingRegion;
use rustc_codegen_ssa::traits::ConstMethods;
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def::DefKind;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::llvm;
use crate::abi::Abi;
use crate::builder::Builder;
use crate::common::CodegenCx;
use crate::coverageinfo::map_data::{CounterExpression, FunctionCoverage};
use crate::coverageinfo::ffi::{CounterExpression, CounterMappingRegion};
use crate::coverageinfo::map_data::FunctionCoverage;

use libc::c_uint;
use llvm::coverageinfo::CounterMappingRegion;
use rustc_codegen_ssa::traits::{
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, MiscMethods,
StaticMethods,
Expand All @@ -27,7 +27,7 @@ use rustc_middle::ty::Ty;
use std::cell::RefCell;
use std::ffi::CString;

mod ffi;
pub(crate) mod ffi;
pub(crate) mod map_data;
pub mod mapgen;

Expand Down
Loading

0 comments on commit 460e92b

Please sign in to comment.