Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #108027

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7824528
std: use id-based thread parking on SOLID
joboet Dec 31, 2022
837c1af
rework min_choice algorithm of member constraints
aliemjay Jan 15, 2023
8df27d0
Remove some superfluous type parameters from layout.rs.
mikebenfield Jan 21, 2023
e813132
--wip-- [skip ci]
SpanishPear Oct 23, 2022
5287004
Apply automatic suggestions from code review
SpanishPear Dec 1, 2022
655beb4
Attempt to address review comments via github web...
SpanishPear Dec 1, 2022
4447949
revert to previous span
SpanishPear Jan 22, 2023
8292d07
move tests to new rust-lang location
SpanishPear Jan 22, 2023
70bfcc2
move to multipart spans
SpanishPear Jan 31, 2023
a3d32bb
fix formatting + test syntax
SpanishPear Feb 1, 2023
0d59b8c
Remove redundant test.
cjgillot Jan 21, 2023
cd3649b
Only exclude locals if the place is not indirect.
cjgillot Jan 21, 2023
9a6c04f
Handle discriminants in dataflow-const-prop.
cjgillot Jan 21, 2023
c48756c
Limit creation of tracked place directly.
cjgillot Jan 28, 2023
9af191f
Improve value_analysis API.
cjgillot Jan 29, 2023
67a8c16
Complete for_each_aliasing_place.
cjgillot Jan 30, 2023
df889c9
Rename assign_idx methods.
cjgillot Feb 3, 2023
5925400
Fix unintentional UB in ui tests
saethlin Feb 12, 2023
09797a4
Typo.
cjgillot Feb 13, 2023
3180f1c
Fix #107998, avoid ICE when the generic_span is empty
chenyukang Feb 13, 2023
826abcc
Shrink size of array benchmarks
JulianKnodt Feb 14, 2023
765f703
Rollup merge of #103478 - SpanishPear:spanishpear/issue_103366_fix, r…
Dylan-DPC Feb 14, 2023
86368ae
Rollup merge of #105300 - aliemjay:member-lower, r=oli-obk
Dylan-DPC Feb 14, 2023
6f88493
Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-se
Dylan-DPC Feb 14, 2023
6bfabbe
Rollup merge of #107163 - mikebenfield:parameters-pr, r=TaKO8Ki
Dylan-DPC Feb 14, 2023
1756653
Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk
Dylan-DPC Feb 14, 2023
81e6e3a
Rollup merge of #107972 - saethlin:fix-test-ub, r=michaelwoerister
Dylan-DPC Feb 14, 2023
d34957d
Rollup merge of #108003 - chenyukang:yukang/fix-107998, r=compiler-er…
Dylan-DPC Feb 14, 2023
b8d1547
Rollup merge of #108023 - JulianKnodt:smaller_benchmark, r=workingjub…
Dylan-DPC Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 71 additions & 75 deletions compiler/rustc_abi/src/layout.rs

Large diffs are not rendered by default.

71 changes: 59 additions & 12 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
use std::str::FromStr;

use bitflags::bitflags;
use rustc_data_structures::intern::Interned;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::StableOrd;
use rustc_index::vec::{Idx, IndexVec};
Expand Down Expand Up @@ -1250,9 +1251,9 @@ impl Abi {

#[derive(PartialEq, Eq, Hash, Clone, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum Variants<V: Idx> {
pub enum Variants {
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
Single { index: V },
Single { index: VariantIdx },

/// Enum-likes with more than one inhabited variant: each variant comes with
/// a *discriminant* (usually the same as the variant index but the user can
Expand All @@ -1262,15 +1263,15 @@ pub enum Variants<V: Idx> {
/// For enums, the tag is the sole field of the layout.
Multiple {
tag: Scalar,
tag_encoding: TagEncoding<V>,
tag_encoding: TagEncoding,
tag_field: usize,
variants: IndexVec<V, LayoutS<V>>,
variants: IndexVec<VariantIdx, LayoutS>,
},
}

#[derive(PartialEq, Eq, Hash, Clone, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum TagEncoding<V: Idx> {
pub enum TagEncoding {
/// The tag directly stores the discriminant, but possibly with a smaller layout
/// (so converting the tag to the discriminant can require sign extension).
Direct,
Expand All @@ -1285,7 +1286,11 @@ pub enum TagEncoding<V: Idx> {
/// For example, `Option<(usize, &T)>` is represented such that
/// `None` has a null pointer for the second tuple field, and
/// `Some` is the identity function (with a non-null reference).
Niche { untagged_variant: V, niche_variants: RangeInclusive<V>, niche_start: u128 },
Niche {
untagged_variant: VariantIdx,
niche_variants: RangeInclusive<VariantIdx>,
niche_start: u128,
},
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
Expand Down Expand Up @@ -1372,9 +1377,14 @@ impl Niche {
}
}

rustc_index::newtype_index! {
#[derive(HashStable_Generic)]
pub struct VariantIdx {}
}

#[derive(PartialEq, Eq, Hash, Clone)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub struct LayoutS<V: Idx> {
pub struct LayoutS {
/// Says where the fields are located within the layout.
pub fields: FieldsShape,

Expand All @@ -1385,7 +1395,7 @@ pub struct LayoutS<V: Idx> {
///
/// To access all fields of this layout, both `fields` and the fields of the active variant
/// must be taken into account.
pub variants: Variants<V>,
pub variants: Variants,

/// The `abi` defines how this data is passed between functions, and it defines
/// value restrictions via `valid_range`.
Expand All @@ -1404,13 +1414,13 @@ pub struct LayoutS<V: Idx> {
pub size: Size,
}

impl<V: Idx> LayoutS<V> {
impl LayoutS {
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar);
let size = scalar.size(cx);
let align = scalar.align(cx);
LayoutS {
variants: Variants::Single { index: V::new(0) },
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Primitive,
abi: Abi::Scalar(scalar),
largest_niche,
Expand All @@ -1420,7 +1430,7 @@ impl<V: Idx> LayoutS<V> {
}
}

impl<V: Idx> fmt::Debug for LayoutS<V> {
impl fmt::Debug for LayoutS {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// This is how `Layout` used to print before it become
// `Interned<LayoutS>`. We print it like this to avoid having to update
Expand All @@ -1437,6 +1447,43 @@ impl<V: Idx> fmt::Debug for LayoutS<V> {
}
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
#[rustc_pass_by_value]
pub struct Layout<'a>(pub Interned<'a, LayoutS>);

impl<'a> fmt::Debug for Layout<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// See comment on `<LayoutS as Debug>::fmt` above.
self.0.0.fmt(f)
}
}

impl<'a> Layout<'a> {
pub fn fields(self) -> &'a FieldsShape {
&self.0.0.fields
}

pub fn variants(self) -> &'a Variants {
&self.0.0.variants
}

pub fn abi(self) -> Abi {
self.0.0.abi
}

pub fn largest_niche(self) -> Option<Niche> {
self.0.0.largest_niche
}

pub fn align(self) -> AbiAndPrefAlign {
self.0.0.align
}

pub fn size(self) -> Size {
self.0.0.size
}
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum PointerKind {
/// Shared reference. `frozen` indicates the absence of any `UnsafeCell`.
Expand Down Expand Up @@ -1464,7 +1511,7 @@ pub enum InitKind {
UninitMitigated0x01Fill,
}

impl<V: Idx> LayoutS<V> {
impl LayoutS {
/// Returns `true` if the layout corresponds to an unsized type.
pub fn is_unsized(&self) -> bool {
self.abi.is_unsized()
Expand Down
35 changes: 24 additions & 11 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,20 +746,33 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
debug!(?choice_regions, "after ub");

// If we ruled everything out, we're done.
if choice_regions.is_empty() {
return false;
}

// Otherwise, we need to find the minimum remaining choice, if
// any, and take that.
debug!("choice_regions remaining are {:#?}", choice_regions);
let Some(&min_choice) = choice_regions.iter().find(|&r1| {
// At this point we can pick any member of `choice_regions`, but to avoid potential
// non-determinism we will pick the *unique minimum* choice.
//
// Because universal regions are only partially ordered (i.e, not every two regions are
// comparable), we will ignore any region that doesn't compare to all others when picking
// the minimum choice.
// For example, consider `choice_regions = ['static, 'a, 'b, 'c, 'd, 'e]`, where
// `'static: 'a, 'static: 'b, 'a: 'c, 'b: 'c, 'c: 'd, 'c: 'e`.
// `['d, 'e]` are ignored because they do not compare - the same goes for `['a, 'b]`.
let totally_ordered_subset = choice_regions.iter().copied().filter(|&r1| {
choice_regions.iter().all(|&r2| {
self.universal_region_relations.outlives(r2, *r1)
self.universal_region_relations.outlives(r1, r2)
|| self.universal_region_relations.outlives(r2, r1)
})
});
// Now we're left with `['static, 'c]`. Pick `'c` as the minimum!
let Some(min_choice) = totally_ordered_subset.reduce(|r1, r2| {
let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2);
let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1);
match (r1_outlives_r2, r2_outlives_r1) {
(true, true) => r1.min(r2),
(true, false) => r2,
(false, true) => r1,
(false, false) => bug!("incomparable regions in total order"),
}
}) else {
debug!("no choice region outlived by all others");
debug!("no unique minimum choice");
return false;
};

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,17 @@ pub trait LintContext: Sized {
(use_span, "'_".to_owned())
};
debug!(?deletion_span, ?use_span);

// issue 107998 for the case such as a wrong function pointer type
// `deletion_span` is empty and there is no need to report lifetime uses here
let suggestions = if deletion_span.is_empty() {
vec![(use_span, replace_lt)]
} else {
vec![(deletion_span, String::new()), (use_span, replace_lt)]
};
db.multipart_suggestion(
msg,
vec![(deletion_span, String::new()), (use_span, replace_lt)],
suggestions,
Applicability::MachineApplicable,
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
macro_rules! arena_types {
($macro:path) => (
$macro!([
[] layout: rustc_target::abi::LayoutS<rustc_target::abi::VariantIdx>,
[] layout: rustc_target::abi::LayoutS,
[] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
// AdtDef are interned and compared by address
[decode] adt_def: rustc_middle::ty::AdtDefData,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,14 @@ impl<'tcx> PlaceRef<'tcx> {
}
}

/// Returns `true` if this `Place` contains a `Deref` projection.
///
/// If `Place::is_indirect` returns false, the caller knows that the `Place` refers to the
/// same region of memory as its base.
pub fn is_indirect(&self) -> bool {
self.projection.iter().any(|elem| elem.is_indirect())
}

/// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place
pub fn has_deref(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct CtxtInterners<'tcx> {
const_: InternedSet<'tcx, ConstData<'tcx>>,
const_allocation: InternedSet<'tcx, Allocation>,
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
layout: InternedSet<'tcx, LayoutS<VariantIdx>>,
layout: InternedSet<'tcx, LayoutS>,
adt_def: InternedSet<'tcx, AdtDefData>,
external_constraints: InternedSet<'tcx, ExternalConstraintsData<'tcx>>,
}
Expand Down Expand Up @@ -1520,7 +1520,7 @@ direct_interners! {
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>,
const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>,
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>,
layout: intern_layout(LayoutS): Layout -> Layout<'tcx>,
adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>,
external_constraints: intern_external_constraints(ExternalConstraintsData<'tcx>): ExternalConstraints -> ExternalConstraints<'tcx>,
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ where
// for now. See discussion on [#61069].
//
// [#61069]: https://github.com/rust-lang/rust/pull/61069
self.trans.gen(dropped_place.local);
if !dropped_place.is_indirect() {
self.trans.gen(dropped_place.local);
}
}

TerminatorKind::Abort
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_dataflow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(exact_size_is_empty)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(once_cell)]
#![feature(stmt_expr_attributes)]
Expand Down
Loading