Skip to content

Commit 999ac5f

Browse files
committed
Auto merge of rust-lang#108070 - Dylan-DPC:rollup-v6xw7vk, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#105300 (rework min_choice algorithm of member constraints) - rust-lang#107163 (Remove some superfluous type parameters from layout.rs.) - rust-lang#107173 (Suggest the correct array length on mismatch) - rust-lang#107411 (Handle discriminant in DataflowConstProp) - rust-lang#107968 (Enable `#[thread_local]` on armv6k-nintendo-3ds) - rust-lang#108032 (Un📦ing the Resolver) - rust-lang#108060 (Revert to using `RtlGenRandom` as a fallback) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 068161e + ef6de70 commit 999ac5f

Some content is hidden

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

47 files changed

+1092
-556
lines changed

compiler/rustc_abi/src/layout.rs

+71-75
Large diffs are not rendered by default.

compiler/rustc_abi/src/lib.rs

+59-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
88
use std::str::FromStr;
99

1010
use bitflags::bitflags;
11+
use rustc_data_structures::intern::Interned;
1112
#[cfg(feature = "nightly")]
1213
use rustc_data_structures::stable_hasher::StableOrd;
1314
use rustc_index::vec::{Idx, IndexVec};
@@ -1250,9 +1251,9 @@ impl Abi {
12501251

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

12571258
/// Enum-likes with more than one inhabited variant: each variant comes with
12581259
/// a *discriminant* (usually the same as the variant index but the user can
@@ -1262,15 +1263,15 @@ pub enum Variants<V: Idx> {
12621263
/// For enums, the tag is the sole field of the layout.
12631264
Multiple {
12641265
tag: Scalar,
1265-
tag_encoding: TagEncoding<V>,
1266+
tag_encoding: TagEncoding,
12661267
tag_field: usize,
1267-
variants: IndexVec<V, LayoutS<V>>,
1268+
variants: IndexVec<VariantIdx, LayoutS>,
12681269
},
12691270
}
12701271

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

12911296
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
@@ -1372,9 +1377,14 @@ impl Niche {
13721377
}
13731378
}
13741379

1380+
rustc_index::newtype_index! {
1381+
#[derive(HashStable_Generic)]
1382+
pub struct VariantIdx {}
1383+
}
1384+
13751385
#[derive(PartialEq, Eq, Hash, Clone)]
13761386
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1377-
pub struct LayoutS<V: Idx> {
1387+
pub struct LayoutS {
13781388
/// Says where the fields are located within the layout.
13791389
pub fields: FieldsShape,
13801390

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

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

1407-
impl<V: Idx> LayoutS<V> {
1417+
impl LayoutS {
14081418
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
14091419
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar);
14101420
let size = scalar.size(cx);
14111421
let align = scalar.align(cx);
14121422
LayoutS {
1413-
variants: Variants::Single { index: V::new(0) },
1423+
variants: Variants::Single { index: VariantIdx::new(0) },
14141424
fields: FieldsShape::Primitive,
14151425
abi: Abi::Scalar(scalar),
14161426
largest_niche,
@@ -1420,7 +1430,7 @@ impl<V: Idx> LayoutS<V> {
14201430
}
14211431
}
14221432

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

1450+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
1451+
#[rustc_pass_by_value]
1452+
pub struct Layout<'a>(pub Interned<'a, LayoutS>);
1453+
1454+
impl<'a> fmt::Debug for Layout<'a> {
1455+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1456+
// See comment on `<LayoutS as Debug>::fmt` above.
1457+
self.0.0.fmt(f)
1458+
}
1459+
}
1460+
1461+
impl<'a> Layout<'a> {
1462+
pub fn fields(self) -> &'a FieldsShape {
1463+
&self.0.0.fields
1464+
}
1465+
1466+
pub fn variants(self) -> &'a Variants {
1467+
&self.0.0.variants
1468+
}
1469+
1470+
pub fn abi(self) -> Abi {
1471+
self.0.0.abi
1472+
}
1473+
1474+
pub fn largest_niche(self) -> Option<Niche> {
1475+
self.0.0.largest_niche
1476+
}
1477+
1478+
pub fn align(self) -> AbiAndPrefAlign {
1479+
self.0.0.align
1480+
}
1481+
1482+
pub fn size(self) -> Size {
1483+
self.0.0.size
1484+
}
1485+
}
1486+
14401487
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
14411488
pub enum PointerKind {
14421489
/// Shared reference. `frozen` indicates the absence of any `UnsafeCell`.
@@ -1464,7 +1511,7 @@ pub enum InitKind {
14641511
UninitMitigated0x01Fill,
14651512
}
14661513

1467-
impl<V: Idx> LayoutS<V> {
1514+
impl LayoutS {
14681515
/// Returns `true` if the layout corresponds to an unsized type.
14691516
pub fn is_unsized(&self) -> bool {
14701517
self.abi.is_unsized()

compiler/rustc_borrowck/src/region_infer/mod.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -746,20 +746,33 @@ impl<'tcx> RegionInferenceContext<'tcx> {
746746
}
747747
debug!(?choice_regions, "after ub");
748748

749-
// If we ruled everything out, we're done.
750-
if choice_regions.is_empty() {
751-
return false;
752-
}
753-
754-
// Otherwise, we need to find the minimum remaining choice, if
755-
// any, and take that.
756-
debug!("choice_regions remaining are {:#?}", choice_regions);
757-
let Some(&min_choice) = choice_regions.iter().find(|&r1| {
749+
// At this point we can pick any member of `choice_regions`, but to avoid potential
750+
// non-determinism we will pick the *unique minimum* choice.
751+
//
752+
// Because universal regions are only partially ordered (i.e, not every two regions are
753+
// comparable), we will ignore any region that doesn't compare to all others when picking
754+
// the minimum choice.
755+
// For example, consider `choice_regions = ['static, 'a, 'b, 'c, 'd, 'e]`, where
756+
// `'static: 'a, 'static: 'b, 'a: 'c, 'b: 'c, 'c: 'd, 'c: 'e`.
757+
// `['d, 'e]` are ignored because they do not compare - the same goes for `['a, 'b]`.
758+
let totally_ordered_subset = choice_regions.iter().copied().filter(|&r1| {
758759
choice_regions.iter().all(|&r2| {
759-
self.universal_region_relations.outlives(r2, *r1)
760+
self.universal_region_relations.outlives(r1, r2)
761+
|| self.universal_region_relations.outlives(r2, r1)
760762
})
763+
});
764+
// Now we're left with `['static, 'c]`. Pick `'c` as the minimum!
765+
let Some(min_choice) = totally_ordered_subset.reduce(|r1, r2| {
766+
let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2);
767+
let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1);
768+
match (r1_outlives_r2, r2_outlives_r1) {
769+
(true, true) => r1.min(r2),
770+
(true, false) => r2,
771+
(false, true) => r1,
772+
(false, false) => bug!("incomparable regions in total order"),
773+
}
761774
}) else {
762-
debug!("no choice region outlived by all others");
775+
debug!("no unique minimum choice");
763776
return false;
764777
};
765778

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+65
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6464
use rustc_hir as hir;
6565
use rustc_hir::def::DefKind;
6666
use rustc_hir::def_id::{DefId, LocalDefId};
67+
use rustc_hir::intravisit::Visitor;
6768
use rustc_hir::lang_items::LangItem;
6869
use rustc_hir::Node;
6970
use rustc_middle::dep_graph::DepContext;
@@ -1985,6 +1986,70 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19851986
(ty::Bool, ty::Tuple(list)) => if list.len() == 0 {
19861987
self.suggest_let_for_letchains(&mut err, &trace.cause, span);
19871988
}
1989+
(ty::Array(_, _), ty::Array(_, _)) => 'block: {
1990+
let hir = self.tcx.hir();
1991+
let TypeError::FixedArraySize(sz) = terr else {
1992+
break 'block;
1993+
};
1994+
let tykind = match hir.find_by_def_id(trace.cause.body_id) {
1995+
Some(hir::Node::Item(hir::Item {
1996+
kind: hir::ItemKind::Fn(_, _, body_id),
1997+
..
1998+
})) => {
1999+
let body = hir.body(*body_id);
2000+
struct LetVisitor<'v> {
2001+
span: Span,
2002+
result: Option<&'v hir::Ty<'v>>,
2003+
}
2004+
impl<'v> Visitor<'v> for LetVisitor<'v> {
2005+
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
2006+
if self.result.is_some() {
2007+
return;
2008+
}
2009+
// Find a local statement where the initializer has
2010+
// the same span as the error and the type is specified.
2011+
if let hir::Stmt {
2012+
kind: hir::StmtKind::Local(hir::Local {
2013+
init: Some(hir::Expr {
2014+
span: init_span,
2015+
..
2016+
}),
2017+
ty: Some(array_ty),
2018+
..
2019+
}),
2020+
..
2021+
} = s
2022+
&& init_span == &self.span {
2023+
self.result = Some(*array_ty);
2024+
}
2025+
}
2026+
}
2027+
let mut visitor = LetVisitor {span, result: None};
2028+
visitor.visit_body(body);
2029+
visitor.result.map(|r| &r.peel_refs().kind)
2030+
}
2031+
Some(hir::Node::Item(hir::Item {
2032+
kind: hir::ItemKind::Const(ty, _),
2033+
..
2034+
})) => {
2035+
Some(&ty.peel_refs().kind)
2036+
}
2037+
_ => None
2038+
};
2039+
2040+
if let Some(tykind) = tykind
2041+
&& let hir::TyKind::Array(_, length) = tykind
2042+
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
2043+
&& let Some(span) = self.tcx.hir().opt_span(*hir_id)
2044+
{
2045+
err.span_suggestion(
2046+
span,
2047+
"consider specifying the actual array length",
2048+
sz.found,
2049+
Applicability::MaybeIncorrect,
2050+
);
2051+
}
2052+
}
19882053
_ => {}
19892054
}
19902055
}

compiler/rustc_interface/src/interface.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub use crate::passes::BoxedResolver;
21
use crate::util;
32

43
use rustc_ast::token;

compiler/rustc_interface/src/passes.rs

+3-83
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_a
2323
use rustc_passes::{self, hir_stats, layout_test};
2424
use rustc_plugin_impl as plugin;
2525
use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
26-
use rustc_resolve::{Resolver, ResolverArenas};
26+
use rustc_resolve::Resolver;
2727
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
28-
use rustc_session::cstore::{CrateStoreDyn, MetadataLoader, MetadataLoaderDyn, Untracked};
28+
use rustc_session::cstore::{CrateStoreDyn, MetadataLoader, Untracked};
2929
use rustc_session::output::filename_for_input;
3030
use rustc_session::search_paths::PathKind;
3131
use rustc_session::{Limit, Session};
@@ -37,9 +37,7 @@ use rustc_trait_selection::traits;
3737
use std::any::Any;
3838
use std::ffi::OsString;
3939
use std::io::{self, BufWriter, Write};
40-
use std::marker::PhantomPinned;
4140
use std::path::{Path, PathBuf};
42-
use std::pin::Pin;
4341
use std::sync::{Arc, LazyLock};
4442
use std::{env, fs, iter};
4543

@@ -73,84 +71,6 @@ fn count_nodes(krate: &ast::Crate) -> usize {
7371
counter.count
7472
}
7573

76-
pub use boxed_resolver::BoxedResolver;
77-
mod boxed_resolver {
78-
use super::*;
79-
80-
pub struct BoxedResolver(Pin<Box<BoxedResolverInner>>);
81-
82-
struct BoxedResolverInner {
83-
session: Lrc<Session>,
84-
resolver_arenas: Option<ResolverArenas<'static>>,
85-
resolver: Option<Resolver<'static>>,
86-
_pin: PhantomPinned,
87-
}
88-
89-
// Note: Drop order is important to prevent dangling references. Resolver must be dropped first,
90-
// then resolver_arenas and session.
91-
impl Drop for BoxedResolverInner {
92-
fn drop(&mut self) {
93-
self.resolver.take();
94-
self.resolver_arenas.take();
95-
}
96-
}
97-
98-
impl BoxedResolver {
99-
pub(super) fn new(
100-
session: Lrc<Session>,
101-
make_resolver: impl for<'a> FnOnce(&'a Session, &'a ResolverArenas<'a>) -> Resolver<'a>,
102-
) -> BoxedResolver {
103-
let mut boxed_resolver = Box::new(BoxedResolverInner {
104-
session,
105-
resolver_arenas: Some(Resolver::arenas()),
106-
resolver: None,
107-
_pin: PhantomPinned,
108-
});
109-
// SAFETY: `make_resolver` takes a resolver arena with an arbitrary lifetime and
110-
// returns a resolver with the same lifetime as the arena. We ensure that the arena
111-
// outlives the resolver in the drop impl and elsewhere so these transmutes are sound.
112-
unsafe {
113-
let resolver = make_resolver(
114-
std::mem::transmute::<&Session, &Session>(&boxed_resolver.session),
115-
std::mem::transmute::<&ResolverArenas<'_>, &ResolverArenas<'_>>(
116-
boxed_resolver.resolver_arenas.as_ref().unwrap(),
117-
),
118-
);
119-
boxed_resolver.resolver = Some(resolver);
120-
BoxedResolver(Pin::new_unchecked(boxed_resolver))
121-
}
122-
}
123-
124-
pub fn access<F: for<'a> FnOnce(&mut Resolver<'a>) -> R, R>(&mut self, f: F) -> R {
125-
// SAFETY: The resolver doesn't need to be pinned.
126-
let mut resolver = unsafe {
127-
self.0.as_mut().map_unchecked_mut(|boxed_resolver| &mut boxed_resolver.resolver)
128-
};
129-
f((&mut *resolver).as_mut().unwrap())
130-
}
131-
132-
pub fn into_outputs(mut self) -> ty::ResolverOutputs {
133-
// SAFETY: The resolver doesn't need to be pinned.
134-
let mut resolver = unsafe {
135-
self.0.as_mut().map_unchecked_mut(|boxed_resolver| &mut boxed_resolver.resolver)
136-
};
137-
resolver.take().unwrap().into_outputs()
138-
}
139-
}
140-
}
141-
142-
pub fn create_resolver(
143-
sess: Lrc<Session>,
144-
metadata_loader: Box<MetadataLoaderDyn>,
145-
krate: &ast::Crate,
146-
crate_name: Symbol,
147-
) -> BoxedResolver {
148-
trace!("create_resolver");
149-
BoxedResolver::new(sess, move |sess, resolver_arenas| {
150-
Resolver::new(sess, krate, crate_name, metadata_loader, resolver_arenas)
151-
})
152-
}
153-
15474
pub fn register_plugins<'a>(
15575
sess: &'a Session,
15676
metadata_loader: &'a dyn MetadataLoader,
@@ -256,7 +176,7 @@ pub fn configure_and_expand(
256176
lint_store: &LintStore,
257177
mut krate: ast::Crate,
258178
crate_name: Symbol,
259-
resolver: &mut Resolver<'_>,
179+
resolver: &mut Resolver<'_, '_>,
260180
) -> Result<ast::Crate> {
261181
trace!("configure_and_expand");
262182
pre_expansion_lint(sess, lint_store, resolver.registered_tools(), &krate, crate_name);

0 commit comments

Comments
 (0)