Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5978f35

Browse files
committedJun 19, 2024
Auto merge of rust-lang#126671 - fmease:rollup-dmet4fi, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#123782 (Test that opaque types can't have themselves as a hidden type with incompatible lifetimes) - rust-lang#124580 (Suggest removing unused tuple fields if they are the last fields) - rust-lang#125787 (Migrate `bin-emit-no-symbols` `run-make` test to `rmake`) - rust-lang#126553 (match lowering: expand or-candidates mixed with candidates above) - rust-lang#126594 (Make async drop code more consistent with regular drop code) - rust-lang#126654 (Make pretty printing for `f16` and `f128` consistent) - rust-lang#126656 (rustc_type_ir: Omit some struct fields from Debug output) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3c0f019 + b980f6d commit 5978f35

39 files changed

+698
-219
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn exported_symbols_provider_local(
371371
}) => {
372372
// A little sanity-check
373373
debug_assert_eq!(
374-
args.non_erasable_generics(tcx, def_id).skip(1).next(),
374+
args.non_erasable_generics(tcx, def_id).next(),
375375
Some(GenericArgKind::Type(ty))
376376
);
377377
symbols.push((
@@ -422,10 +422,7 @@ fn upstream_monomorphizations_provider(
422422
}
423423
ExportedSymbol::AsyncDropGlueCtorShim(ty) => {
424424
if let Some(async_drop_in_place_fn_def_id) = async_drop_in_place_fn_def_id {
425-
(
426-
async_drop_in_place_fn_def_id,
427-
tcx.mk_args(&[tcx.lifetimes.re_erased.into(), ty.into()]),
428-
)
425+
(async_drop_in_place_fn_def_id, tcx.mk_args(&[ty.into()]))
429426
} else {
430427
// `drop_in_place` in place does not exist, don't try
431428
// to use it.
@@ -473,11 +470,16 @@ fn upstream_drop_glue_for_provider<'tcx>(
473470
tcx: TyCtxt<'tcx>,
474471
args: GenericArgsRef<'tcx>,
475472
) -> Option<CrateNum> {
476-
if let Some(def_id) = tcx.lang_items().drop_in_place_fn() {
477-
tcx.upstream_monomorphizations_for(def_id).and_then(|monos| monos.get(&args).cloned())
478-
} else {
479-
None
480-
}
473+
let def_id = tcx.lang_items().drop_in_place_fn()?;
474+
tcx.upstream_monomorphizations_for(def_id)?.get(&args).cloned()
475+
}
476+
477+
fn upstream_async_drop_glue_for_provider<'tcx>(
478+
tcx: TyCtxt<'tcx>,
479+
args: GenericArgsRef<'tcx>,
480+
) -> Option<CrateNum> {
481+
let def_id = tcx.lang_items().async_drop_in_place_fn()?;
482+
tcx.upstream_monomorphizations_for(def_id)?.get(&args).cloned()
481483
}
482484

483485
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
@@ -491,6 +493,7 @@ pub fn provide(providers: &mut Providers) {
491493
providers.upstream_monomorphizations = upstream_monomorphizations_provider;
492494
providers.is_unreachable_local_definition = is_unreachable_local_definition_provider;
493495
providers.upstream_drop_glue_for = upstream_drop_glue_for_provider;
496+
providers.upstream_async_drop_glue_for = upstream_async_drop_glue_for_provider;
494497
providers.wasm_import_module_map = wasm_import_module_map;
495498
providers.extern_queries.is_reachable_non_generic = is_reachable_non_generic_provider_extern;
496499
providers.extern_queries.upstream_monomorphizations_for =

‎compiler/rustc_middle/src/query/mod.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -1554,12 +1554,13 @@ rustc_queries! {
15541554
}
15551555
}
15561556

1557-
/// The entire set of monomorphizations the local crate can safely link
1558-
/// to because they are exported from upstream crates. Do not depend on
1559-
/// this directly, as its value changes anytime a monomorphization gets
1560-
/// added or removed in any upstream crate. Instead use the narrower
1561-
/// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1562-
/// better, `Instance::upstream_monomorphization()`.
1557+
/// The entire set of monomorphizations the local crate can safely
1558+
/// link to because they are exported from upstream crates. Do
1559+
/// not depend on this directly, as its value changes anytime
1560+
/// a monomorphization gets added or removed in any upstream
1561+
/// crate. Instead use the narrower `upstream_monomorphizations_for`,
1562+
/// `upstream_drop_glue_for`, `upstream_async_drop_glue_for`, or,
1563+
/// even better, `Instance::upstream_monomorphization()`.
15631564
query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<UnordMap<GenericArgsRef<'tcx>, CrateNum>> {
15641565
arena_cache
15651566
desc { "collecting available upstream monomorphizations" }
@@ -1601,6 +1602,26 @@ rustc_queries! {
16011602
desc { "available upstream drop-glue for `{:?}`", args }
16021603
}
16031604

1605+
/// Returns the upstream crate that exports async-drop-glue for
1606+
/// the given type (`args` is expected to be a single-item list
1607+
/// containing the type one wants async-drop-glue for).
1608+
///
1609+
/// This is a subset of `upstream_monomorphizations_for` in order
1610+
/// to increase dep-tracking granularity. Otherwise adding or
1611+
/// removing any type with async-drop-glue in any upstream crate
1612+
/// would invalidate all functions calling async-drop-glue of an
1613+
/// upstream type.
1614+
///
1615+
/// You likely want to call `Instance::upstream_monomorphization()`
1616+
/// instead of invoking this query directly.
1617+
///
1618+
/// NOTE: This query could easily be extended to also support other
1619+
/// common functions that have are large set of monomorphizations
1620+
/// (like `Clone::clone` for example).
1621+
query upstream_async_drop_glue_for(args: GenericArgsRef<'tcx>) -> Option<CrateNum> {
1622+
desc { "available upstream async-drop-glue for `{:?}`", args }
1623+
}
1624+
16041625
/// Returns a list of all `extern` blocks of a crate.
16051626
query foreign_modules(_: CrateNum) -> &'tcx FxIndexMap<DefId, ForeignModule> {
16061627
arena_cache

‎compiler/rustc_middle/src/ty/instance.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ impl<'tcx> Instance<'tcx> {
219219
InstanceKind::Item(def) => tcx
220220
.upstream_monomorphizations_for(def)
221221
.and_then(|monos| monos.get(&self.args).cloned()),
222-
InstanceKind::DropGlue(_, Some(_)) | InstanceKind::AsyncDropGlueCtorShim(_, _) => {
223-
tcx.upstream_drop_glue_for(self.args)
222+
InstanceKind::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
223+
InstanceKind::AsyncDropGlueCtorShim(_, Some(_)) => {
224+
tcx.upstream_async_drop_glue_for(self.args)
224225
}
225226
_ => None,
226227
}
@@ -256,7 +257,7 @@ impl<'tcx> InstanceKind<'tcx> {
256257
match self {
257258
ty::InstanceKind::Item(def) => Some(def),
258259
ty::InstanceKind::DropGlue(def_id, Some(_))
259-
| InstanceKind::AsyncDropGlueCtorShim(def_id, _)
260+
| InstanceKind::AsyncDropGlueCtorShim(def_id, Some(_))
260261
| InstanceKind::ThreadLocalShim(def_id) => Some(def_id),
261262
InstanceKind::VTableShim(..)
262263
| InstanceKind::ReifyShim(..)
@@ -267,6 +268,7 @@ impl<'tcx> InstanceKind<'tcx> {
267268
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
268269
| ty::InstanceKind::CoroutineKindShim { .. }
269270
| InstanceKind::DropGlue(..)
271+
| InstanceKind::AsyncDropGlueCtorShim(..)
270272
| InstanceKind::CloneShim(..)
271273
| InstanceKind::FnPtrAddrShim(..) => None,
272274
}
@@ -312,7 +314,9 @@ impl<'tcx> InstanceKind<'tcx> {
312314
if self.requires_inline(tcx) {
313315
return true;
314316
}
315-
if let ty::InstanceKind::DropGlue(.., Some(ty)) = *self {
317+
if let ty::InstanceKind::DropGlue(.., Some(ty))
318+
| ty::InstanceKind::AsyncDropGlueCtorShim(.., Some(ty)) = *self
319+
{
316320
// Drop glue generally wants to be instantiated at every codegen
317321
// unit, but without an #[inline] hint. We should make this
318322
// available to normal end-users.
@@ -327,9 +331,14 @@ impl<'tcx> InstanceKind<'tcx> {
327331
// drops of `Option::None` before LTO. We also respect the intent of
328332
// `#[inline]` on `Drop::drop` implementations.
329333
return ty.ty_adt_def().map_or(true, |adt_def| {
330-
adt_def
331-
.destructor(tcx)
332-
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.did))
334+
match *self {
335+
ty::InstanceKind::DropGlue(..) => adt_def.destructor(tcx).map(|dtor| dtor.did),
336+
ty::InstanceKind::AsyncDropGlueCtorShim(..) => {
337+
adt_def.async_destructor(tcx).map(|dtor| dtor.ctor)
338+
}
339+
_ => unreachable!(),
340+
}
341+
.map_or_else(|| adt_def.is_enum(), |did| tcx.cross_crate_inlinable(did))
333342
});
334343
}
335344
if let ty::InstanceKind::ThreadLocalShim(..) = *self {

‎compiler/rustc_middle/src/ty/print/pretty.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ty::{
77
ConstInt, Expr, ParamConst, ScalarInt, Term, TermKind, TypeFoldable, TypeSuperFoldable,
88
TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
99
};
10-
use rustc_apfloat::ieee::{Double, Single};
10+
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
1111
use rustc_apfloat::Float;
1212
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1313
use rustc_data_structures::unord::UnordMap;
@@ -1710,6 +1710,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
17101710
ty::Bool if int == ScalarInt::FALSE => p!("false"),
17111711
ty::Bool if int == ScalarInt::TRUE => p!("true"),
17121712
// Float
1713+
ty::Float(ty::FloatTy::F16) => {
1714+
let val = Half::try_from(int).unwrap();
1715+
p!(write("{}{}f16", val, if val.is_finite() { "" } else { "_" }))
1716+
}
17131717
ty::Float(ty::FloatTy::F32) => {
17141718
let val = Single::try_from(int).unwrap();
17151719
p!(write("{}{}f32", val, if val.is_finite() { "" } else { "_" }))
@@ -1718,6 +1722,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
17181722
let val = Double::try_from(int).unwrap();
17191723
p!(write("{}{}f64", val, if val.is_finite() { "" } else { "_" }))
17201724
}
1725+
ty::Float(ty::FloatTy::F128) => {
1726+
let val = Quad::try_from(int).unwrap();
1727+
p!(write("{}{}f128", val, if val.is_finite() { "" } else { "_" }))
1728+
}
17211729
// Int
17221730
ty::Uint(_) | ty::Int(_) => {
17231731
let int =
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.