Skip to content

Commit 460e92b

Browse files
committed
Auto merge of rust-lang#3007 - rust-lang:rustup-2023-08-03, r=oli-obk
Automatic sync from rustc
2 parents 042cfd8 + 9bb8b66 commit 460e92b

File tree

204 files changed

+1271
-1121
lines changed

Some content is hidden

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

204 files changed

+1271
-1121
lines changed

compiler/rustc_ast/src/format.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ pub struct FormatArguments {
6767
names: FxHashMap<Symbol, usize>,
6868
}
6969

70-
// FIXME: Rustdoc has trouble proving Send/Sync for this. See #106930.
71-
#[cfg(parallel_compiler)]
72-
unsafe impl Sync for FormatArguments {}
73-
#[cfg(parallel_compiler)]
74-
unsafe impl Send for FormatArguments {}
75-
7670
impl FormatArguments {
7771
pub fn new() -> Self {
7872
Self {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
886886
.universal_regions()
887887
.defining_ty
888888
.upvar_tys()
889+
.iter()
889890
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
890891
{
891892
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(

compiler/rustc_borrowck/src/diagnostics/var_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4343
fr: RegionVid,
4444
) -> Option<usize> {
4545
let upvar_index =
46-
self.universal_regions().defining_ty.upvar_tys().position(|upvar_ty| {
46+
self.universal_regions().defining_ty.upvar_tys().iter().position(|upvar_ty| {
4747
debug!("get_upvar_index_for_region: upvar_ty={upvar_ty:?}");
4848
tcx.any_free_region_meets(&upvar_ty, |r| {
4949
let r = r.as_var();
@@ -52,7 +52,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5252
})
5353
})?;
5454

55-
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().nth(upvar_index);
55+
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().get(upvar_index);
5656

5757
debug!(
5858
"get_upvar_index_for_region: found {fr:?} in upvar {upvar_index} which has type {upvar_ty:?}",

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9090
) {
9191
self.prove_predicate(
9292
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
93-
ty::TraitPredicate {
94-
trait_ref,
95-
constness: ty::BoundConstness::NotConst,
96-
polarity: ty::ImplPolarity::Positive,
97-
},
93+
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive },
9894
))),
9995
locations,
10096
category,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,20 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
791791
(adt_def.variant(FIRST_VARIANT), args)
792792
}
793793
ty::Closure(_, args) => {
794-
return match args
795-
.as_closure()
796-
.tupled_upvars_ty()
797-
.tuple_fields()
798-
.get(field.index())
799-
{
794+
return match args.as_closure().upvar_tys().get(field.index()) {
800795
Some(&ty) => Ok(ty),
801796
None => Err(FieldAccessError::OutOfRange {
802-
field_count: args.as_closure().upvar_tys().count(),
797+
field_count: args.as_closure().upvar_tys().len(),
803798
}),
804799
};
805800
}
806801
ty::Generator(_, args, _) => {
807802
// Only prefix fields (upvars and current state) are
808803
// accessible without a variant index.
809-
return match args.as_generator().prefix_tys().nth(field.index()) {
810-
Some(ty) => Ok(ty),
804+
return match args.as_generator().prefix_tys().get(field.index()) {
805+
Some(ty) => Ok(*ty),
811806
None => Err(FieldAccessError::OutOfRange {
812-
field_count: args.as_generator().prefix_tys().count(),
807+
field_count: args.as_generator().prefix_tys().len(),
813808
}),
814809
};
815810
}
@@ -1772,21 +1767,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17721767
}
17731768
}
17741769
AggregateKind::Closure(_, args) => {
1775-
match args.as_closure().upvar_tys().nth(field_index.as_usize()) {
1776-
Some(ty) => Ok(ty),
1770+
match args.as_closure().upvar_tys().get(field_index.as_usize()) {
1771+
Some(ty) => Ok(*ty),
17771772
None => Err(FieldAccessError::OutOfRange {
1778-
field_count: args.as_closure().upvar_tys().count(),
1773+
field_count: args.as_closure().upvar_tys().len(),
17791774
}),
17801775
}
17811776
}
17821777
AggregateKind::Generator(_, args, _) => {
17831778
// It doesn't make sense to look at a field beyond the prefix;
17841779
// these require a variant index, and are not initialized in
17851780
// aggregate rvalues.
1786-
match args.as_generator().prefix_tys().nth(field_index.as_usize()) {
1787-
Some(ty) => Ok(ty),
1781+
match args.as_generator().prefix_tys().get(field_index.as_usize()) {
1782+
Some(ty) => Ok(*ty),
17881783
None => Err(FieldAccessError::OutOfRange {
1789-
field_count: args.as_generator().prefix_tys().count(),
1784+
field_count: args.as_generator().prefix_tys().len(),
17901785
}),
17911786
}
17921787
}

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! The code in this file doesn't *do anything* with those results; it
1313
//! just returns them for other code to use.
1414
15-
use either::Either;
1615
use rustc_data_structures::fx::FxHashMap;
1716
use rustc_errors::Diagnostic;
1817
use rustc_hir as hir;
@@ -115,14 +114,12 @@ impl<'tcx> DefiningTy<'tcx> {
115114
/// not a closure or generator, there are no upvars, and hence it
116115
/// will be an empty list. The order of types in this list will
117116
/// match up with the upvar order in the HIR, typesystem, and MIR.
118-
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
117+
pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> {
119118
match self {
120-
DefiningTy::Closure(_, args) => Either::Left(args.as_closure().upvar_tys()),
121-
DefiningTy::Generator(_, args, _) => {
122-
Either::Right(Either::Left(args.as_generator().upvar_tys()))
123-
}
119+
DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(),
120+
DefiningTy::Generator(_, args, _) => args.as_generator().upvar_tys(),
124121
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
125-
Either::Right(Either::Right(iter::empty()))
122+
ty::List::empty()
126123
}
127124
}
128125
}

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,197 @@ impl CounterExpression {
8585
Self { kind, lhs, rhs }
8686
}
8787
}
88+
89+
/// Corresponds to enum `llvm::coverage::CounterMappingRegion::RegionKind`.
90+
///
91+
/// Must match the layout of `LLVMRustCounterMappingRegionKind`.
92+
#[derive(Copy, Clone, Debug)]
93+
#[repr(C)]
94+
pub enum RegionKind {
95+
/// A CodeRegion associates some code with a counter
96+
CodeRegion = 0,
97+
98+
/// An ExpansionRegion represents a file expansion region that associates
99+
/// a source range with the expansion of a virtual source file, such as
100+
/// for a macro instantiation or #include file.
101+
ExpansionRegion = 1,
102+
103+
/// A SkippedRegion represents a source range with code that was skipped
104+
/// by a preprocessor or similar means.
105+
SkippedRegion = 2,
106+
107+
/// A GapRegion is like a CodeRegion, but its count is only set as the
108+
/// line execution count when its the only region in the line.
109+
GapRegion = 3,
110+
111+
/// A BranchRegion represents leaf-level boolean expressions and is
112+
/// associated with two counters, each representing the number of times the
113+
/// expression evaluates to true or false.
114+
BranchRegion = 4,
115+
}
116+
117+
/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
118+
/// coverage map, in accordance with the
119+
/// [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).
120+
/// The struct composes fields representing the `Counter` type and value(s) (injected counter
121+
/// ID, or expression type and operands), the source file (an indirect index into a "filenames
122+
/// array", encoded separately), and source location (start and end positions of the represented
123+
/// code region).
124+
///
125+
/// Corresponds to struct `llvm::coverage::CounterMappingRegion`.
126+
///
127+
/// Must match the layout of `LLVMRustCounterMappingRegion`.
128+
#[derive(Copy, Clone, Debug)]
129+
#[repr(C)]
130+
pub struct CounterMappingRegion {
131+
/// The counter type and type-dependent counter data, if any.
132+
counter: Counter,
133+
134+
/// If the `RegionKind` is a `BranchRegion`, this represents the counter
135+
/// for the false branch of the region.
136+
false_counter: Counter,
137+
138+
/// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the
139+
/// file_id is an index into a function-specific `virtual_file_mapping` array of indexes
140+
/// that, in turn, are used to look up the filename for this region.
141+
file_id: u32,
142+
143+
/// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find
144+
/// the mapping regions created as a result of macro expansion, by checking if their file id
145+
/// matches the expanded file id.
146+
expanded_file_id: u32,
147+
148+
/// 1-based starting line of the mapping region.
149+
start_line: u32,
150+
151+
/// 1-based starting column of the mapping region.
152+
start_col: u32,
153+
154+
/// 1-based ending line of the mapping region.
155+
end_line: u32,
156+
157+
/// 1-based ending column of the mapping region. If the high bit is set, the current
158+
/// mapping region is a gap area.
159+
end_col: u32,
160+
161+
kind: RegionKind,
162+
}
163+
164+
impl CounterMappingRegion {
165+
pub(crate) fn code_region(
166+
counter: Counter,
167+
file_id: u32,
168+
start_line: u32,
169+
start_col: u32,
170+
end_line: u32,
171+
end_col: u32,
172+
) -> Self {
173+
Self {
174+
counter,
175+
false_counter: Counter::zero(),
176+
file_id,
177+
expanded_file_id: 0,
178+
start_line,
179+
start_col,
180+
end_line,
181+
end_col,
182+
kind: RegionKind::CodeRegion,
183+
}
184+
}
185+
186+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
187+
// support.
188+
#[allow(dead_code)]
189+
pub(crate) fn branch_region(
190+
counter: Counter,
191+
false_counter: Counter,
192+
file_id: u32,
193+
start_line: u32,
194+
start_col: u32,
195+
end_line: u32,
196+
end_col: u32,
197+
) -> Self {
198+
Self {
199+
counter,
200+
false_counter,
201+
file_id,
202+
expanded_file_id: 0,
203+
start_line,
204+
start_col,
205+
end_line,
206+
end_col,
207+
kind: RegionKind::BranchRegion,
208+
}
209+
}
210+
211+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
212+
// support.
213+
#[allow(dead_code)]
214+
pub(crate) fn expansion_region(
215+
file_id: u32,
216+
expanded_file_id: u32,
217+
start_line: u32,
218+
start_col: u32,
219+
end_line: u32,
220+
end_col: u32,
221+
) -> Self {
222+
Self {
223+
counter: Counter::zero(),
224+
false_counter: Counter::zero(),
225+
file_id,
226+
expanded_file_id,
227+
start_line,
228+
start_col,
229+
end_line,
230+
end_col,
231+
kind: RegionKind::ExpansionRegion,
232+
}
233+
}
234+
235+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
236+
// support.
237+
#[allow(dead_code)]
238+
pub(crate) fn skipped_region(
239+
file_id: u32,
240+
start_line: u32,
241+
start_col: u32,
242+
end_line: u32,
243+
end_col: u32,
244+
) -> Self {
245+
Self {
246+
counter: Counter::zero(),
247+
false_counter: Counter::zero(),
248+
file_id,
249+
expanded_file_id: 0,
250+
start_line,
251+
start_col,
252+
end_line,
253+
end_col,
254+
kind: RegionKind::SkippedRegion,
255+
}
256+
}
257+
258+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
259+
// support.
260+
#[allow(dead_code)]
261+
pub(crate) fn gap_region(
262+
counter: Counter,
263+
file_id: u32,
264+
start_line: u32,
265+
start_col: u32,
266+
end_line: u32,
267+
end_col: u32,
268+
) -> Self {
269+
Self {
270+
counter,
271+
false_counter: Counter::zero(),
272+
file_id,
273+
expanded_file_id: 0,
274+
start_line,
275+
start_col,
276+
end_line,
277+
end_col: (1_u32 << 31) | end_col,
278+
kind: RegionKind::GapRegion,
279+
}
280+
}
281+
}

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use super::ffi::*;
1+
use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
22

33
use rustc_index::{IndexSlice, IndexVec};
44
use rustc_middle::bug;

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::common::CodegenCx;
22
use crate::coverageinfo;
3-
use crate::coverageinfo::map_data::{Counter, CounterExpression};
3+
use crate::coverageinfo::ffi::{Counter, CounterExpression, CounterMappingRegion};
44
use crate::llvm;
55

6-
use llvm::coverageinfo::CounterMappingRegion;
76
use rustc_codegen_ssa::traits::ConstMethods;
87
use rustc_data_structures::fx::FxIndexSet;
98
use rustc_hir::def::DefKind;

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::llvm;
33
use crate::abi::Abi;
44
use crate::builder::Builder;
55
use crate::common::CodegenCx;
6-
use crate::coverageinfo::map_data::{CounterExpression, FunctionCoverage};
6+
use crate::coverageinfo::ffi::{CounterExpression, CounterMappingRegion};
7+
use crate::coverageinfo::map_data::FunctionCoverage;
78

89
use libc::c_uint;
9-
use llvm::coverageinfo::CounterMappingRegion;
1010
use rustc_codegen_ssa::traits::{
1111
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, MiscMethods,
1212
StaticMethods,
@@ -27,7 +27,7 @@ use rustc_middle::ty::Ty;
2727
use std::cell::RefCell;
2828
use std::ffi::CString;
2929

30-
mod ffi;
30+
pub(crate) mod ffi;
3131
pub(crate) mod map_data;
3232
pub mod mapgen;
3333

0 commit comments

Comments
 (0)