Skip to content

Commit 3128fd8

Browse files
committed
Auto merge of #110666 - JohnTitor:rollup-3pwilte, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #109949 (rustdoc: migrate `document_type_layout` to askama) - #110622 (Stable hash tag (discriminant) of `GenericArg`) - #110635 (More `IS_ZST` in `library`) - #110640 (compiler/rustc_target: Raise m68k-linux-gnu baseline to 68020) - #110657 (nit: consistent naming for SimplifyConstCondition) - #110659 (rustdoc: clean up JS) - #110660 (Print ty placeholders pretty) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 37b22cf + 16e2096 commit 3128fd8

File tree

19 files changed

+200
-180
lines changed

19 files changed

+200
-180
lines changed

Diff for: compiler/rustc_middle/src/ty/impls_ty.rs

-28
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'t
7373
}
7474
}
7575

76-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKind<'tcx> {
77-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
78-
match self {
79-
// WARNING: We dedup cache the `HashStable` results for `List`
80-
// while ignoring types and freely transmute
81-
// between `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>`.
82-
// See `fn mk_type_list` for more details.
83-
//
84-
// We therefore hash types without adding a hash for their discriminant.
85-
//
86-
// In order to make it very unlikely for the sequence of bytes being hashed for
87-
// a `GenericArgKind::Type` to be the same as the sequence of bytes being
88-
// hashed for one of the other variants, we hash some very high number instead
89-
// of their actual discriminant since `TyKind` should never start with anything
90-
// that high.
91-
ty::subst::GenericArgKind::Type(ty) => ty.hash_stable(hcx, hasher),
92-
ty::subst::GenericArgKind::Const(ct) => {
93-
0xF3u8.hash_stable(hcx, hasher);
94-
ct.hash_stable(hcx, hasher);
95-
}
96-
ty::subst::GenericArgKind::Lifetime(lt) => {
97-
0xF5u8.hash_stable(hcx, hasher);
98-
lt.hash_stable(hcx, hasher);
99-
}
100-
}
101-
}
102-
}
103-
10476
// AllocIds get resolved to whatever they point to (to be stable)
10577
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
10678
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ pub trait PrettyPrinter<'tcx>:
738738
}
739739
}
740740
ty::Placeholder(placeholder) => match placeholder.bound.kind {
741-
ty::BoundTyKind::Anon => p!(write("Placeholder({:?})", placeholder)),
741+
ty::BoundTyKind::Anon => {
742+
self.pretty_print_placeholder_var(placeholder.universe, placeholder.bound.var)?
743+
}
742744
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
743745
},
744746
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
@@ -1172,6 +1174,18 @@ pub trait PrettyPrinter<'tcx>:
11721174
}
11731175
}
11741176

1177+
fn pretty_print_placeholder_var(
1178+
&mut self,
1179+
ui: ty::UniverseIndex,
1180+
var: ty::BoundVar,
1181+
) -> Result<(), Self::Error> {
1182+
if ui == ty::UniverseIndex::ROOT {
1183+
write!(self, "!{}", var.index())
1184+
} else {
1185+
write!(self, "!{}_{}", ui.index(), var.index())
1186+
}
1187+
}
1188+
11751189
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
11761190
None
11771191
}

Diff for: compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TYPE_TAG: usize = 0b00;
4747
const REGION_TAG: usize = 0b01;
4848
const CONST_TAG: usize = 0b10;
4949

50-
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord)]
50+
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)]
5151
pub enum GenericArgKind<'tcx> {
5252
Lifetime(ty::Region<'tcx>),
5353
Type(Ty<'tcx>),

Diff for: compiler/rustc_mir_transform/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,12 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
507507
//
508508
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
509509
&const_debuginfo::ConstDebugInfo,
510-
&o1(simplify_branches::SimplifyConstConditionPassName::AfterConstProp),
510+
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
511511
&early_otherwise_branch::EarlyOtherwiseBranch,
512512
&simplify_comparison_integral::SimplifyComparisonIntegral,
513513
&dead_store_elimination::DeadStoreElimination,
514514
&dest_prop::DestinationPropagation,
515-
&o1(simplify_branches::SimplifyConstConditionPassName::Final),
515+
&o1(simplify_branches::SimplifyConstCondition::Final),
516516
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
517517
&o1(simplify::SimplifyCfg::Final),
518518
&nrvo::RenameReturnPlace,

Diff for: compiler/rustc_mir_transform/src/simplify_branches.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use crate::MirPass;
22
use rustc_middle::mir::*;
33
use rustc_middle::ty::TyCtxt;
44

5-
pub enum SimplifyConstConditionPassName {
5+
pub enum SimplifyConstCondition {
66
AfterConstProp,
77
Final,
88
}
99
/// A pass that replaces a branch with a goto when its condition is known.
10-
impl<'tcx> MirPass<'tcx> for SimplifyConstConditionPassName {
10+
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
1111
fn name(&self) -> &'static str {
1212
match self {
13-
SimplifyConstConditionPassName::AfterConstProp => {
14-
"SimplifyConstCondition-after-const-prop"
15-
}
16-
SimplifyConstConditionPassName::Final => "SimplifyConstCondition-final",
13+
SimplifyConstCondition::AfterConstProp => "SimplifyConstCondition-after-const-prop",
14+
SimplifyConstCondition::Final => "SimplifyConstCondition-final",
1715
}
1816
}
1917

Diff for: compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let mut base = super::linux_gnu_base::opts();
6+
base.cpu = "M68020".into();
67
base.max_atomic_width = Some(32);
78

89
Target {

Diff for: compiler/rustc_type_ir/src/sty.rs

+10
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ pub enum TyKind<I: Interner> {
203203
/// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
204204
/// back to inference variables in a new inference context when inside of the query.
205205
///
206+
/// It is conventional to render anonymous bound types like `^N` or `^D_N`,
207+
/// where `N` is the bound variable's anonymous index into the binder, and
208+
/// `D` is the debruijn index, or totally omitted if the debruijn index is zero.
209+
///
206210
/// See the `rustc-dev-guide` for more details about
207211
/// [higher-ranked trait bounds][1] and [canonical queries][2].
208212
///
@@ -212,6 +216,12 @@ pub enum TyKind<I: Interner> {
212216

213217
/// A placeholder type, used during higher ranked subtyping to instantiate
214218
/// bound variables.
219+
///
220+
/// It is conventional to render anonymous placeholer types like `!N` or `!U_N`,
221+
/// where `N` is the placeholder variable's anonymous index (which corresponds
222+
/// to the bound variable's index from the binder from which it was instantiated),
223+
/// and `U` is the universe index in which it is instantiated, or totally omitted
224+
/// if the universe index is zero.
215225
Placeholder(I::PlaceholderType),
216226

217227
/// A type variable used during type checking.

Diff for: library/alloc/src/boxed/thin.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::fmt::{self, Debug, Display, Formatter};
77
use core::marker::PhantomData;
88
#[cfg(not(no_global_oom_handling))]
99
use core::marker::Unsize;
10-
use core::mem;
10+
use core::mem::{self, SizedTypeProperties};
1111
use core::ops::{Deref, DerefMut};
1212
use core::ptr::Pointee;
1313
use core::ptr::{self, NonNull};
@@ -202,9 +202,7 @@ impl<H> WithHeader<H> {
202202
let ptr = if layout.size() == 0 {
203203
// Some paranoia checking, mostly so that the ThinBox tests are
204204
// more able to catch issues.
205-
debug_assert!(
206-
value_offset == 0 && mem::size_of::<T>() == 0 && mem::size_of::<H>() == 0
207-
);
205+
debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST);
208206
layout.dangling()
209207
} else {
210208
let ptr = alloc::alloc(layout);
@@ -249,9 +247,7 @@ impl<H> WithHeader<H> {
249247
alloc::dealloc(self.ptr.as_ptr().sub(value_offset), layout);
250248
} else {
251249
debug_assert!(
252-
value_offset == 0
253-
&& mem::size_of::<H>() == 0
254-
&& self.value_layout.size() == 0
250+
value_offset == 0 && H::IS_ZST && self.value_layout.size() == 0
255251
);
256252
}
257253
}

Diff for: library/alloc/src/vec/drain.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
112112
let unyielded_ptr = this.iter.as_slice().as_ptr();
113113

114114
// ZSTs have no identity, so we don't need to move them around.
115-
let needs_move = mem::size_of::<T>() != 0;
116-
117-
if needs_move {
115+
if !T::IS_ZST {
118116
let start_ptr = source_vec.as_mut_ptr().add(start);
119117

120118
// memmove back unyielded elements

Diff for: library/alloc/src/vec/drain_filter.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::alloc::{Allocator, Global};
2-
use core::mem::{self, ManuallyDrop};
2+
use core::mem::{ManuallyDrop, SizedTypeProperties};
33
use core::ptr;
44
use core::slice;
55

@@ -96,9 +96,7 @@ where
9696

9797
unsafe {
9898
// ZSTs have no identity, so we don't need to move them around.
99-
let needs_move = mem::size_of::<T>() != 0;
100-
101-
if needs_move && this.idx < this.old_len && this.del > 0 {
99+
if !T::IS_ZST && this.idx < this.old_len && this.del > 0 {
102100
let ptr = this.vec.as_mut_ptr();
103101
let src = ptr.add(this.idx);
104102
let dst = src.sub(this.del);

Diff for: library/core/src/slice/iter/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ macro_rules! iterator {
7373
// Unsafe because the offset must not exceed `self.len()`.
7474
#[inline(always)]
7575
unsafe fn post_inc_start(&mut self, offset: usize) -> * $raw_mut T {
76-
if mem::size_of::<T>() == 0 {
76+
if T::IS_ZST {
7777
zst_shrink!(self, offset);
7878
self.ptr.as_ptr()
7979
} else {

Diff for: src/librustdoc/html/render/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod context;
3232
mod print_item;
3333
mod sidebar;
3434
mod span_map;
35+
mod type_layout;
3536
mod write_shared;
3637

3738
pub(crate) use self::context::*;

Diff for: src/librustdoc/html/render/print_item.rs

+2-116
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ use rustc_hir as hir;
66
use rustc_hir::def::CtorKind;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::middle::stability;
9-
use rustc_middle::span_bug;
10-
use rustc_middle::ty::layout::LayoutError;
11-
use rustc_middle::ty::{self, Adt, TyCtxt};
9+
use rustc_middle::ty::{self, TyCtxt};
1210
use rustc_span::hygiene::MacroKind;
1311
use rustc_span::symbol::{kw, sym, Symbol};
14-
use rustc_target::abi::{LayoutS, Primitive, TagEncoding, Variants};
1512
use std::cmp::Ordering;
1613
use std::fmt;
1714
use std::rc::Rc;
1815

16+
use super::type_layout::document_type_layout;
1917
use super::{
2018
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
2119
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
@@ -1933,118 +1931,6 @@ fn document_non_exhaustive<'a>(item: &'a clean::Item) -> impl fmt::Display + 'a
19331931
})
19341932
}
19351933

1936-
fn document_type_layout<'a, 'cx: 'a>(
1937-
cx: &'a Context<'cx>,
1938-
ty_def_id: DefId,
1939-
) -> impl fmt::Display + 'a + Captures<'cx> {
1940-
fn write_size_of_layout(mut w: impl fmt::Write, layout: &LayoutS, tag_size: u64) {
1941-
if layout.abi.is_unsized() {
1942-
write!(w, "(unsized)").unwrap();
1943-
} else {
1944-
let size = layout.size.bytes() - tag_size;
1945-
write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" }).unwrap();
1946-
if layout.abi.is_uninhabited() {
1947-
write!(
1948-
w,
1949-
" (<a href=\"https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited\">uninhabited</a>)"
1950-
).unwrap();
1951-
}
1952-
}
1953-
}
1954-
1955-
display_fn(move |mut f| {
1956-
if !cx.shared.show_type_layout {
1957-
return Ok(());
1958-
}
1959-
1960-
writeln!(
1961-
f,
1962-
"<h2 id=\"layout\" class=\"small-section-header\"> \
1963-
Layout<a href=\"#layout\" class=\"anchor\">§</a></h2>"
1964-
)?;
1965-
writeln!(f, "<div class=\"docblock\">")?;
1966-
1967-
let tcx = cx.tcx();
1968-
let param_env = tcx.param_env(ty_def_id);
1969-
let ty = tcx.type_of(ty_def_id).subst_identity();
1970-
match tcx.layout_of(param_env.and(ty)) {
1971-
Ok(ty_layout) => {
1972-
writeln!(
1973-
f,
1974-
"<div class=\"warning\"><p><strong>Note:</strong> Most layout information is \
1975-
<strong>completely unstable</strong> and may even differ between compilations. \
1976-
The only exception is types with certain <code>repr(...)</code> attributes. \
1977-
Please see the Rust Reference’s \
1978-
<a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \
1979-
chapter for details on type layout guarantees.</p></div>"
1980-
)?;
1981-
f.write_str("<p><strong>Size:</strong> ")?;
1982-
write_size_of_layout(&mut f, &ty_layout.layout.0, 0);
1983-
writeln!(f, "</p>")?;
1984-
if let Variants::Multiple { variants, tag, tag_encoding, .. } =
1985-
&ty_layout.layout.variants()
1986-
{
1987-
if !variants.is_empty() {
1988-
f.write_str(
1989-
"<p><strong>Size for each variant:</strong></p>\
1990-
<ul>",
1991-
)?;
1992-
1993-
let Adt(adt, _) = ty_layout.ty.kind() else {
1994-
span_bug!(tcx.def_span(ty_def_id), "not an adt")
1995-
};
1996-
1997-
let tag_size = if let TagEncoding::Niche { .. } = tag_encoding {
1998-
0
1999-
} else if let Primitive::Int(i, _) = tag.primitive() {
2000-
i.size().bytes()
2001-
} else {
2002-
span_bug!(tcx.def_span(ty_def_id), "tag is neither niche nor int")
2003-
};
2004-
2005-
for (index, layout) in variants.iter_enumerated() {
2006-
let name = adt.variant(index).name;
2007-
write!(&mut f, "<li><code>{name}</code>: ")?;
2008-
write_size_of_layout(&mut f, layout, tag_size);
2009-
writeln!(&mut f, "</li>")?;
2010-
}
2011-
f.write_str("</ul>")?;
2012-
}
2013-
}
2014-
}
2015-
// This kind of layout error can occur with valid code, e.g. if you try to
2016-
// get the layout of a generic type such as `Vec<T>`.
2017-
Err(LayoutError::Unknown(_)) => {
2018-
writeln!(
2019-
f,
2020-
"<p><strong>Note:</strong> Unable to compute type layout, \
2021-
possibly due to this type having generic parameters. \
2022-
Layout can only be computed for concrete, fully-instantiated types.</p>"
2023-
)?;
2024-
}
2025-
// This kind of error probably can't happen with valid code, but we don't
2026-
// want to panic and prevent the docs from building, so we just let the
2027-
// user know that we couldn't compute the layout.
2028-
Err(LayoutError::SizeOverflow(_)) => {
2029-
writeln!(
2030-
f,
2031-
"<p><strong>Note:</strong> Encountered an error during type layout; \
2032-
the type was too big.</p>"
2033-
)?;
2034-
}
2035-
Err(LayoutError::NormalizationFailure(_, _)) => {
2036-
writeln!(
2037-
f,
2038-
"<p><strong>Note:</strong> Encountered an error during type layout; \
2039-
the type failed to be normalized.</p>"
2040-
)?;
2041-
}
2042-
}
2043-
2044-
writeln!(f, "</div>")
2045-
})
2046-
}
2047-
20481934
fn pluralize(count: usize) -> &'static str {
20491935
if count > 1 { "s" } else { "" }
20501936
}

0 commit comments

Comments
 (0)