From 8ad6e5fb671a2343b81aee29cb344f4804bbb0f4 Mon Sep 17 00:00:00 2001 From: Milo <50248166+Milo123459@users.noreply.github.com> Date: Fri, 5 Nov 2021 18:27:54 +0000 Subject: [PATCH 1/6] Add UnwindSafe to Once --- library/std/src/sync/once.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 1710c0053934a..47921283b2185 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -90,6 +90,7 @@ mod tests; use crate::cell::Cell; use crate::fmt; use crate::marker; +use crate::panic::UnwindSafe; use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use crate::thread::{self, Thread}; @@ -123,6 +124,9 @@ unsafe impl Sync for Once {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for Once {} +#[stable(feature = "sync_once_ref_unwind_safe", since = "1.59.0")] +impl UnwindSafe for Once {} + /// State yielded to [`Once::call_once_force()`]’s closure parameter. The state /// can be used to query the poison status of the [`Once`]. #[stable(feature = "once_poison", since = "1.51.0")] From 59949900885930494df9c803b61bbe93e507e0cb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 20 Dec 2021 12:33:55 +0100 Subject: [PATCH 2/6] disable test with self-referential generator on Miri --- library/core/tests/future.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/tests/future.rs b/library/core/tests/future.rs index e8b83b5cbc21e..0ed8c52c21224 100644 --- a/library/core/tests/future.rs +++ b/library/core/tests/future.rs @@ -30,6 +30,7 @@ fn poll_n(val: usize, num: usize) -> PollN { } #[test] +#[cfg_attr(miri, ignore)] // self-referential generators do not work with Miri's aliasing checks fn test_join() { block_on(async move { let x = join!(async { 0 }).await; From 91161ed110c87b6e2dba08269e45509e317fbc73 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 20 Dec 2021 11:49:47 -0800 Subject: [PATCH 3/6] impl RefUnwindSafe for Once --- library/std/src/sync/once.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 47921283b2185..f76d0759561ac 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -90,7 +90,7 @@ mod tests; use crate::cell::Cell; use crate::fmt; use crate::marker; -use crate::panic::UnwindSafe; +use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use crate::thread::{self, Thread}; @@ -124,9 +124,12 @@ unsafe impl Sync for Once {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for Once {} -#[stable(feature = "sync_once_ref_unwind_safe", since = "1.59.0")] +#[stable(feature = "sync_once_unwind_safe", since = "1.59.0")] impl UnwindSafe for Once {} +#[stable(feature = "sync_once_unwind_safe", since = "1.59.0")] +impl RefUnwindSafe for Once {} + /// State yielded to [`Once::call_once_force()`]’s closure parameter. The state /// can be used to query the poison status of the [`Once`]. #[stable(feature = "once_poison", since = "1.51.0")] From 1ea4aa003660316d7c208e4cb2a38c6100805a21 Mon Sep 17 00:00:00 2001 From: fee1-dead Date: Wed, 22 Dec 2021 00:25:50 +0800 Subject: [PATCH 4/6] Fixed a small typo in ui test comments --- src/test/ui/rfc-2632-const-trait-impl/issue-92111.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-92111.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-92111.rs index d30f4edd4b25c..9bf0886084f91 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/issue-92111.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-92111.rs @@ -1,7 +1,7 @@ // Regression test for #92111. // // The issue was that we normalize trait bounds before caching -// results of selection. Checking that `impl NoDrop for S` requires +// results of selection. Checking that `impl Tr for S` requires // checking `S: !Drop` because it cannot overlap with the blanket // impl. Then we save the (unsatisfied) result from checking `S: Drop`. // Then the call to `a` checks whether `S: ~const Drop` but we normalize From cac431ba750c4f079690731b976bc67d979cb8e3 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 22 Dec 2021 14:35:17 -0500 Subject: [PATCH 5/6] Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt` The `AggregateKind` enum ends up in the final mir `Body`. Currently, any changes to `AdtDef` (regardless of how significant they are) will legitimately cause the overall result of `optimized_mir` to change, invalidating any codegen re-use involving that mir. This will get worse once we start hashing the `Span` inside `FieldDef` (which is itself contained in `AdtDef`). To try to reduce these kinds of invalidations, this commit changes `AggregateKind::Adt` to store just the `DefId`, instead of the full `AdtDef`. This allows the result of `optimized_mir` to be unchanged if the `AdtDef` changes in a way that doesn't actually affect any of the MIR we build. --- compiler/rustc_borrowck/src/type_check/mod.rs | 7 ++-- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 4 +-- .../rustc_const_eval/src/interpret/step.rs | 4 +-- .../src/transform/check_consts/qualifs.rs | 3 +- .../rustc_const_eval/src/util/aggregate.rs | 3 +- compiler/rustc_middle/src/mir/mod.rs | 32 +++++++++---------- compiler/rustc_middle/src/mir/tcx.rs | 2 +- .../rustc_mir_build/src/build/expr/into.rs | 2 +- .../rustc_mir_transform/src/check_unsafety.rs | 4 +-- compiler/rustc_mir_transform/src/generator.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 2 +- 11 files changed, 33 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 872a432144704..1f745f977d4c4 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1916,7 +1916,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let tcx = self.tcx(); match *ak { - AggregateKind::Adt(def, variant_index, substs, _, active_field_index) => { + AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => { + let def = tcx.adt_def(adt_did); let variant = &def.variants[variant_index]; let adj_field_index = active_field_index.unwrap_or(field_index); if let Some(field) = variant.fields.get(adj_field_index) { @@ -2621,8 +2622,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); let (def_id, instantiated_predicates) = match aggregate_kind { - AggregateKind::Adt(def, _, substs, _, _) => { - (def.did, tcx.predicates_of(def.did).instantiate(tcx, substs)) + AggregateKind::Adt(adt_did, _, substs, _, _) => { + (*adt_did, tcx.predicates_of(*adt_did).instantiate(tcx, substs)) } // For closures, we have some **extra requirements** we diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index f087b9f7815da..6f960ca44cdd3 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -112,9 +112,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Aggregate(ref kind, ref operands) => { let (dest, active_field_index) = match **kind { - mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => { + mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => { dest.codegen_set_discr(&mut bx, variant_index); - if adt_def.is_enum() { + if bx.tcx().adt_def(adt_did).is_enum() { (dest.project_downcast(&mut bx, variant_index), active_field_index) } else { (dest, active_field_index) diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 992cef1cb6aa0..6e37aae0f5e5c 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -199,9 +199,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Aggregate(ref kind, ref operands) => { // active_field_index is for union initialization. let (dest, active_field_index) = match **kind { - mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => { + mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => { self.write_discriminant(variant_index, &dest)?; - if adt_def.is_enum() { + if self.tcx.adt_def(adt_did).is_enum() { assert!(active_field_index.is_none()); (self.place_downcast(&dest, variant_index)?, None) } else { diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index a8077b258bb75..27f2da34262a1 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -270,7 +270,8 @@ where Rvalue::Aggregate(kind, operands) => { // Return early if we know that the struct or enum being constructed is always // qualified. - if let AggregateKind::Adt(def, _, substs, ..) = **kind { + if let AggregateKind::Adt(adt_did, _, substs, ..) = **kind { + let def = cx.tcx.adt_def(adt_did); if Q::in_adt_inherently(cx, def, substs) { return true; } diff --git a/compiler/rustc_const_eval/src/util/aggregate.rs b/compiler/rustc_const_eval/src/util/aggregate.rs index 4bc0357cab804..e5f5e7072d590 100644 --- a/compiler/rustc_const_eval/src/util/aggregate.rs +++ b/compiler/rustc_const_eval/src/util/aggregate.rs @@ -22,7 +22,8 @@ pub fn expand_aggregate<'tcx>( ) -> impl Iterator> + TrustedLen { let mut set_discriminant = None; let active_field_index = match kind { - AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => { + AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => { + let adt_def = tcx.adt_def(adt_did); if adt_def.is_enum() { set_discriminant = Some(Statement { kind: StatementKind::SetDiscriminant { place: Box::new(lhs), variant_index }, diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index d2dd15aad1276..c7c306e7d06cc 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2268,7 +2268,7 @@ pub enum AggregateKind<'tcx> { /// active field number and is present only for union expressions /// -- e.g., for a union expression `SomeUnion { c: .. }`, the /// active field index would identity the field `c` - Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option, Option), + Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option, Option), Closure(DefId, SubstsRef<'tcx>), Generator(DefId, SubstsRef<'tcx>, hir::Movability), @@ -2427,28 +2427,26 @@ impl<'tcx> Debug for Rvalue<'tcx> { } } - AggregateKind::Adt(adt_def, variant, substs, _user_ty, _) => { - let variant_def = &adt_def.variants[variant]; - - let name = ty::tls::with(|tcx| { + AggregateKind::Adt(adt_did, variant, substs, _user_ty, _) => { + ty::tls::with(|tcx| { let mut name = String::new(); + let variant_def = &tcx.adt_def(adt_did).variants[variant]; let substs = tcx.lift(substs).expect("could not lift for printing"); FmtPrinter::new(tcx, &mut name, Namespace::ValueNS) .print_def_path(variant_def.def_id, substs)?; - Ok(name) - })?; - - match variant_def.ctor_kind { - CtorKind::Const => fmt.write_str(&name), - CtorKind::Fn => fmt_tuple(fmt, &name), - CtorKind::Fictive => { - let mut struct_fmt = fmt.debug_struct(&name); - for (field, place) in iter::zip(&variant_def.fields, places) { - struct_fmt.field(field.ident.as_str(), place); + + match variant_def.ctor_kind { + CtorKind::Const => fmt.write_str(&name), + CtorKind::Fn => fmt_tuple(fmt, &name), + CtorKind::Fictive => { + let mut struct_fmt = fmt.debug_struct(&name); + for (field, place) in iter::zip(&variant_def.fields, places) { + struct_fmt.field(field.ident.as_str(), place); + } + struct_fmt.finish() } - struct_fmt.finish() } - } + }) } AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| { diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index c3c5ebe705eff..e577df4820556 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -200,7 +200,7 @@ impl<'tcx> Rvalue<'tcx> { Rvalue::Aggregate(ref ak, ref ops) => match **ak { AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))), - AggregateKind::Adt(def, _, substs, _, _) => tcx.type_of(def.did).subst(tcx, substs), + AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs), AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs), AggregateKind::Generator(did, substs, movability) => { tcx.mk_generator(did, substs, movability) diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index abec67af08bff..d9896ff5ac93e 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -377,7 +377,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) }); let adt = Box::new(AggregateKind::Adt( - adt_def, + adt_def.did, variant_index, substs, user_ty, diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 2dda19badd7c1..a40c4d1c3662b 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -117,8 +117,8 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { match rvalue { Rvalue::Aggregate(box ref aggregate, _) => match aggregate { &AggregateKind::Array(..) | &AggregateKind::Tuple => {} - &AggregateKind::Adt(ref def, ..) => { - match self.tcx.layout_scalar_valid_range(def.did) { + &AggregateKind::Adt(adt_did, ..) => { + match self.tcx.layout_scalar_valid_range(adt_did) { (Bound::Unbounded, Bound::Unbounded) => {} _ => self.require_unsafe( UnsafetyViolationKind::General, diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 6220cee8d2162..bc9a104e849dc 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -243,7 +243,7 @@ impl<'tcx> TransformVisitor<'tcx> { val: Operand<'tcx>, source_info: SourceInfo, ) -> impl Iterator> { - let kind = AggregateKind::Adt(self.state_adt_ref, idx, self.state_substs, None, None); + let kind = AggregateKind::Adt(self.state_adt_ref.did, idx, self.state_substs, None, None); assert_eq!(self.state_adt_ref.variants[idx].fields.len(), 1); let ty = self .tcx diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index d003938036144..58996dcd6735a 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -777,7 +777,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { adt_def.variants[variant_index].fields.iter().enumerate().map(|(idx, field_def)| { (Operand::Move(Place::from(Local::new(idx + 1))), field_def.ty(tcx, substs)) }), - AggregateKind::Adt(adt_def, variant_index, substs, None, None), + AggregateKind::Adt(adt_def.did, variant_index, substs, None, None), source_info, tcx, ) From b4678870d9c21e9d605ee91af0d62d874a6f78aa Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Dec 2021 08:44:14 -0800 Subject: [PATCH 6/6] Update books --- src/doc/book | 2 +- src/doc/nomicon | 2 +- src/doc/reference | 2 +- src/doc/rustc-dev-guide | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index 5f9358faeb1f4..8a0bb3c96e719 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 5f9358faeb1f46e19b8a23a21e79fd7fe150491e +Subproject commit 8a0bb3c96e71927b80fa2286d7a5a5f2547c6aa4 diff --git a/src/doc/nomicon b/src/doc/nomicon index 49681ea4a9fa8..c05c452b36358 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 49681ea4a9fa81173dbe9ffed74b4d4a35eae9e3 +Subproject commit c05c452b36358821bf4122f9c418674edd1d713d diff --git a/src/doc/reference b/src/doc/reference index 954f3d441ad88..06f9e61931bcf 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 954f3d441ad880737a13e241108f791a4d2a38cd +Subproject commit 06f9e61931bcf58b91dfe6c924057e42ce273ee1 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index a374e7d8bb6b7..9bf0028b55779 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit a374e7d8bb6b79de45b92295d06b4ac0ef35bc09 +Subproject commit 9bf0028b557798ddd07a6f652e4d0c635d3d6620