From b9a1e693a77b626aade2cc95f549b4b6e6029097 Mon Sep 17 00:00:00 2001 From: Johannes Schilling Date: Wed, 21 Apr 2021 14:09:15 +0200 Subject: [PATCH 1/8] Make AssertKind::fmt_assert_args public --- compiler/rustc_middle/src/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 998868211401f..291ac0118a6cf 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1340,7 +1340,7 @@ impl AssertKind { } /// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing. - fn fmt_assert_args(&self, f: &mut W) -> fmt::Result + pub fn fmt_assert_args(&self, f: &mut W) -> fmt::Result where O: Debug, { From cf46fb1945ac51048b327a84a0b23ae9ec82b35a Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 27 Apr 2021 21:18:01 -0500 Subject: [PATCH 2/8] unignore a couple of tests --- src/test/ui/or-patterns/macro-pat.rs | 2 -- src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/test/ui/or-patterns/macro-pat.rs b/src/test/ui/or-patterns/macro-pat.rs index 8c581b630dece..806d1901702ff 100644 --- a/src/test/ui/or-patterns/macro-pat.rs +++ b/src/test/ui/or-patterns/macro-pat.rs @@ -1,7 +1,5 @@ // run-pass // edition:2021 -// ignore-test -// FIXME(mark-i-m): enable this test again when 2021 machinery is available use Foo::*; diff --git a/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs b/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs index f0ce7597aeed1..c0d148d92042f 100644 --- a/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs +++ b/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs @@ -1,9 +1,7 @@ // Tests that :pat in macros in edition 2021 allows top-level or-patterns. // run-pass -// ignore-test // edition:2021 -// FIXME(mark-i-m): unignore when 2021 machinery is in place. macro_rules! accept_pat { ($p:pat) => {}; From 6697b0d0f61ececf381800e14b4a6720e36e98b9 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 28 Apr 2021 20:51:32 -0500 Subject: [PATCH 3/8] fix test --- src/test/ui/or-patterns/macro-pat.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/or-patterns/macro-pat.rs b/src/test/ui/or-patterns/macro-pat.rs index 806d1901702ff..20d8f84c24743 100644 --- a/src/test/ui/or-patterns/macro-pat.rs +++ b/src/test/ui/or-patterns/macro-pat.rs @@ -3,6 +3,7 @@ use Foo::*; +#[allow(dead_code)] #[derive(Eq, PartialEq, Debug)] enum Foo { A(u64), From c064b6560b7ce0adeb9bbf5d7dcf12b1acb0c807 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Thu, 29 Apr 2021 16:15:50 +0000 Subject: [PATCH 4/8] [Arm64] use isb instruction instead of yield in spin loops On arm64 we have seen on several databases that ISB (instruction synchronization barrier) is better to use than yield in a spin loop. The yield instruction is a nop. The isb instruction puts the processor to sleep for some short time. isb is a good equivalent to the pause instruction on x86. Below is an experiment that shows the effects of yield and isb on Arm64 and the time of a pause instruction on x86 Intel processors. The micro-benchmarks use https://github.com/google/benchmark.git $ cat a.cc static void BM_scalar_increment(benchmark::State& state) { int i = 0; for (auto _ : state) benchmark::DoNotOptimize(i++); } BENCHMARK(BM_scalar_increment); static void BM_yield(benchmark::State& state) { for (auto _ : state) asm volatile("yield"::); } BENCHMARK(BM_yield); static void BM_isb(benchmark::State& state) { for (auto _ : state) asm volatile("isb"::); } BENCHMARK(BM_isb); BENCHMARK_MAIN(); $ g++ -o run a.cc -O2 -lbenchmark -lpthread $ ./run -------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------- AWS Graviton2 (Neoverse-N1) processor: BM_scalar_increment 0.485 ns 0.485 ns 1000000000 BM_yield 0.400 ns 0.400 ns 1000000000 BM_isb 13.2 ns 13.2 ns 52993304 AWS Graviton (A-72) processor: BM_scalar_increment 0.897 ns 0.874 ns 801558633 BM_yield 0.877 ns 0.875 ns 800002377 BM_isb 13.0 ns 12.7 ns 55169412 Apple Arm64 M1 processor: BM_scalar_increment 0.315 ns 0.315 ns 1000000000 BM_yield 0.313 ns 0.313 ns 1000000000 BM_isb 9.06 ns 9.06 ns 77259282 static void BM_pause(benchmark::State& state) { for (auto _ : state) asm volatile("pause"::); } BENCHMARK(BM_pause); Intel Skylake processor: BM_scalar_increment 0.295 ns 0.295 ns 1000000000 BM_pause 41.7 ns 41.7 ns 16780553 Tested on Graviton2 aarch64-linux with `./x.py test`. --- library/core/src/hint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 313729581acd9..8e7c95abd6872 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -128,7 +128,7 @@ pub fn spin_loop() { #[cfg(target_arch = "aarch64")] { // SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets. - unsafe { crate::arch::aarch64::__yield() }; + unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) }; } #[cfg(target_arch = "arm")] { From 060deec4b1e94be6fbc640a027c1a935d970e33e Mon Sep 17 00:00:00 2001 From: lrh2000 Date: Fri, 30 Apr 2021 16:14:42 +0800 Subject: [PATCH 5/8] Move outer fields of enums into variant parts in debuginfo All fields except the discriminant (including `outer_fields`) should be put into structures inside the variant part, which gives an equivalent layout but offers us much better integration with debuggers. --- .../src/debuginfo/metadata.rs | 31 ++++++++++++++++--- src/test/debuginfo/generator-objects.rs | 16 +++++----- src/test/debuginfo/issue-57822.rs | 4 +-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index e6fa852155b51..800133b5f0fac 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -309,6 +309,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> { unfinished_type, member_holding_stub, member_descriptions, + None, ); MetadataCreationResult::new(metadata_stub, true) } @@ -1459,6 +1460,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> { layout: TyAndLayout<'tcx>, tag_type_metadata: Option<&'ll DIType>, containing_scope: &'ll DIScope, + common_members: Vec>, span: Span, } @@ -1523,6 +1525,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { self.enum_type, variant_type_metadata, member_descriptions, + Some(&self.common_members), ); vec![MemberDescription { name: if fallback { String::new() } else { variant_info.variant_name() }, @@ -1572,6 +1575,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { self.enum_type, variant_type_metadata, member_descriptions, + Some(&self.common_members), ); MemberDescription { @@ -1621,6 +1625,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { self.enum_type, variant_type_metadata, variant_member_descriptions, + Some(&self.common_members), ); // Encode the information about the null variant in the union @@ -1695,6 +1700,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { self.enum_type, variant_type_metadata, member_descriptions, + Some(&self.common_members), ); let niche_value = if i == dataful_variant { @@ -2102,6 +2108,7 @@ fn prepare_enum_metadata( layout, tag_type_metadata: discriminant_type_metadata, containing_scope, + common_members: vec![], span, }), ); @@ -2171,7 +2178,7 @@ fn prepare_enum_metadata( } }; - let mut outer_fields = match layout.variants { + let outer_fields = match layout.variants { Variants::Single { .. } => vec![], Variants::Multiple { .. } => { let tuple_mdf = TupleMemberDescriptionFactory { @@ -2210,11 +2217,14 @@ fn prepare_enum_metadata( variant_part_unique_type_id_str.len(), ) }; - outer_fields.push(Some(variant_part)); let struct_wrapper = { // The variant part must be wrapped in a struct according to DWARF. - let type_array = create_DIArray(DIB(cx), &outer_fields); + // All fields except the discriminant (including `outer_fields`) + // should be put into structures inside the variant part, which gives + // an equivalent layout but offers us much better integration with + // debuggers. + let type_array = create_DIArray(DIB(cx), &[Some(variant_part)]); let type_map = debug_context(cx).type_map.borrow(); let unique_type_id_str = type_map.get_unique_type_id_as_string(unique_type_id); @@ -2251,6 +2261,7 @@ fn prepare_enum_metadata( layout, tag_type_metadata: None, containing_scope, + common_members: outer_fields, span, }), ) @@ -2283,7 +2294,13 @@ fn composite_type_metadata( DIFlags::FlagZero, ); // ... and immediately create and add the member descriptions. - set_members_of_composite_type(cx, composite_type, composite_type_metadata, member_descriptions); + set_members_of_composite_type( + cx, + composite_type, + composite_type_metadata, + member_descriptions, + None, + ); composite_type_metadata } @@ -2293,6 +2310,7 @@ fn set_members_of_composite_type( composite_type: Ty<'tcx>, composite_type_metadata: &'ll DICompositeType, member_descriptions: Vec>, + common_members: Option<&Vec>>, ) { // In some rare cases LLVM metadata uniquing would lead to an existing type // description being used instead of a new one created in @@ -2311,10 +2329,13 @@ fn set_members_of_composite_type( } } - let member_metadata: Vec<_> = member_descriptions + let mut member_metadata: Vec<_> = member_descriptions .into_iter() .map(|desc| Some(desc.into_metadata(cx, composite_type_metadata))) .collect(); + if let Some(other_members) = common_members { + member_metadata.extend(other_members.iter()); + } let type_params = compute_type_parameters(cx, composite_type); unsafe { diff --git a/src/test/debuginfo/generator-objects.rs b/src/test/debuginfo/generator-objects.rs index b65471011fd2a..3437b295e6e9c 100644 --- a/src/test/debuginfo/generator-objects.rs +++ b/src/test/debuginfo/generator-objects.rs @@ -7,31 +7,31 @@ // gdb-command:run // gdb-command:print b -// gdb-check:$1 = generator_objects::main::generator-0 {__0: 0x[...], <>: {__state: 0, 0: generator_objects::main::generator-0::Unresumed, 1: generator_objects::main::generator-0::Returned, 2: generator_objects::main::generator-0::Panicked, 3: generator_objects::main::generator-0::Suspend0 {[...]}, 4: generator_objects::main::generator-0::Suspend1 {[...]}}} +// gdb-check:$1 = // gdb-command:continue // gdb-command:print b -// gdb-check:$2 = generator_objects::main::generator-0 {__0: 0x[...], <>: {__state: 3, 0: generator_objects::main::generator-0::Unresumed, 1: generator_objects::main::generator-0::Returned, 2: generator_objects::main::generator-0::Panicked, 3: generator_objects::main::generator-0::Suspend0 {c: 6, d: 7}, 4: generator_objects::main::generator-0::Suspend1 {[...]}}} +// gdb-check:$2 = // gdb-command:continue // gdb-command:print b -// gdb-check:$3 = generator_objects::main::generator-0 {__0: 0x[...], <>: {__state: 4, 0: generator_objects::main::generator-0::Unresumed, 1: generator_objects::main::generator-0::Returned, 2: generator_objects::main::generator-0::Panicked, 3: generator_objects::main::generator-0::Suspend0 {[...]}, 4: generator_objects::main::generator-0::Suspend1 {c: 7, d: 8}}} +// gdb-check:$3 = // gdb-command:continue // gdb-command:print b -// gdb-check:$4 = generator_objects::main::generator-0 {__0: 0x[...], <>: {__state: 1, 0: generator_objects::main::generator-0::Unresumed, 1: generator_objects::main::generator-0::Returned, 2: generator_objects::main::generator-0::Panicked, 3: generator_objects::main::generator-0::Suspend0 {[...]}, 4: generator_objects::main::generator-0::Suspend1 {[...]}}} +// gdb-check:$4 = // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print b -// lldbg-check:(generator_objects::main::generator-0) $0 = { 0 = 0x[...] } +// lldbg-check:(generator_objects::main::generator-0) $0 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::generator-0) $1 = { 0 = 0x[...] } +// lldbg-check:(generator_objects::main::generator-0) $1 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::generator-0) $2 = { 0 = 0x[...] } +// lldbg-check:(generator_objects::main::generator-0) $2 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::generator-0) $3 = { 0 = 0x[...] } +// lldbg-check:(generator_objects::main::generator-0) $3 = #![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] #![omit_gdb_pretty_printer_section] diff --git a/src/test/debuginfo/issue-57822.rs b/src/test/debuginfo/issue-57822.rs index a68e4c0a5565b..3a9eaecd5e75e 100644 --- a/src/test/debuginfo/issue-57822.rs +++ b/src/test/debuginfo/issue-57822.rs @@ -14,7 +14,7 @@ // gdb-check:$1 = issue_57822::main::closure-1 (issue_57822::main::closure-0 (1)) // gdb-command:print b -// gdb-check:$2 = issue_57822::main::generator-3 {__0: issue_57822::main::generator-2 {__0: 2, <>: {[...]}}, <>: {[...]}} +// gdb-check:$2 = // === LLDB TESTS ================================================================================== @@ -24,7 +24,7 @@ // lldbg-check:(issue_57822::main::closure-1) $0 = { 0 = { 0 = 1 } } // lldb-command:print b -// lldbg-check:(issue_57822::main::generator-3) $1 = { 0 = { 0 = 2 } } +// lldbg-check:(issue_57822::main::generator-3) $1 = #![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] #![omit_gdb_pretty_printer_section] From 5bf989ece9e29941f2c517a39289a60bfb8595c0 Mon Sep 17 00:00:00 2001 From: lrh2000 Date: Fri, 30 Apr 2021 20:02:53 +0800 Subject: [PATCH 6/8] Remove artificial flag from generator variants - Literally, variants are not artificial. We have `yield` statements, upvars and inner variables in the source code. - Functionally, we don't want debuggers to suppress the variants. It contains the state of the generator, which is useful when debugging. So they shouldn't be marked artificial. - Debuggers may use artificial flags to find the active variant. In this case, marking variants artificial will make debuggers not work properly. Fixes #79009. --- .../src/debuginfo/metadata.rs | 33 +++++-------------- src/test/codegen/async-fn-debug-msvc.rs | 24 +++++++++----- src/test/codegen/async-fn-debug.rs | 29 +++++++++------- src/test/codegen/generator-debug-msvc.rs | 24 +++++++++----- src/test/codegen/generator-debug.rs | 29 +++++++++------- src/test/debuginfo/generator-objects.rs | 12 ++++--- src/test/debuginfo/issue-57822.rs | 2 +- 7 files changed, 83 insertions(+), 70 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 800133b5f0fac..280d9a4d37021 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1495,10 +1495,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { } else { type_metadata(cx, self.enum_type, self.span) }; - let flags = match self.enum_type.kind() { - ty::Generator(..) => DIFlags::FlagArtificial, - _ => DIFlags::FlagZero, - }; match self.layout.variants { Variants::Single { index } => { @@ -1533,7 +1529,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags, + flags: DIFlags::FlagZero, discriminant: None, source_info: variant_info.source_info(cx), }] @@ -1588,7 +1584,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags, + flags: DIFlags::FlagZero, discriminant: Some( self.layout.ty.discriminant_for_variant(cx.tcx, i).unwrap().val as u64, @@ -1672,7 +1668,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: variant.size, align: variant.align.abi, - flags, + flags: DIFlags::FlagZero, discriminant: None, source_info: variant_info.source_info(cx), }] @@ -1723,7 +1719,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags, + flags: DIFlags::FlagZero, discriminant: niche_value, source_info: variant_info.source_info(cx), } @@ -1855,13 +1851,6 @@ impl<'tcx> VariantInfo<'_, 'tcx> { } None } - - fn is_artificial(&self) -> bool { - match self { - VariantInfo::Generator { .. } => true, - VariantInfo::Adt(..) => false, - } - } } /// Returns a tuple of (1) `type_metadata_stub` of the variant, (2) a @@ -1887,8 +1876,7 @@ fn describe_enum_variant( &variant_name, unique_type_id, Some(containing_scope), - // FIXME(tmandry): This doesn't seem to have any effect. - if variant.is_artificial() { DIFlags::FlagArtificial } else { DIFlags::FlagZero }, + DIFlags::FlagZero, ) }); @@ -1951,11 +1939,6 @@ fn prepare_enum_metadata( ) -> RecursiveTypeDescription<'ll, 'tcx> { let tcx = cx.tcx; let enum_name = compute_debuginfo_type_name(tcx, enum_type, false); - // FIXME(tmandry): This doesn't seem to have any effect. - let enum_flags = match enum_type.kind() { - ty::Generator(..) => DIFlags::FlagArtificial, - _ => DIFlags::FlagZero, - }; let containing_scope = get_namespace_for_item(cx, enum_def_id); // FIXME: This should emit actual file metadata for the enum, but we @@ -2088,7 +2071,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - enum_flags, + DIFlags::FlagZero, None, 0, // RuntimeLang unique_type_id_str.as_ptr().cast(), @@ -2210,7 +2193,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - enum_flags, + DIFlags::FlagZero, discriminator_metadata, empty_array, variant_part_unique_type_id_str.as_ptr().cast(), @@ -2239,7 +2222,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - enum_flags, + DIFlags::FlagZero, None, type_array, 0, diff --git a/src/test/codegen/async-fn-debug-msvc.rs b/src/test/codegen/async-fn-debug-msvc.rs index 2b8c0dfc229a3..f2641404aae21 100644 --- a/src/test/codegen/async-fn-debug-msvc.rs +++ b/src/test/codegen/async-fn-debug-msvc.rs @@ -1,7 +1,7 @@ // Verify debuginfo for generators: // - Each variant points to the file and line of its yield point -// - The generator types and variants are marked artificial -// - Captured vars from the source are not marked artificial +// - The discriminants are marked artificial +// - Other fields are not marked artificial // // // compile-flags: -C debuginfo=2 --edition=2018 @@ -17,26 +17,32 @@ async fn async_fn_test() { // FIXME: No way to reliably check the filename. // CHECK-DAG: [[ASYNC_FN:!.*]] = !DINamespace(name: "async_fn_test" -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[ASYNC_FN]], {{.*}}flags: DIFlagArtificial +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[ASYNC_FN]] // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // For brevity, we only check the struct name and members of the last variant. // CHECK-SAME: file: [[FILE:![0-9]*]], line: 11, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 12, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 14, // CHECK-SAME: baseType: [[VARIANT:![0-9]*]] -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[ASYNC_FN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "RUST$ENUM$DISR", scope: [[S1]], // CHECK-SAME: flags: DIFlagArtificial // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] diff --git a/src/test/codegen/async-fn-debug.rs b/src/test/codegen/async-fn-debug.rs index e9b774b48c3e7..7de115f7e9194 100644 --- a/src/test/codegen/async-fn-debug.rs +++ b/src/test/codegen/async-fn-debug.rs @@ -1,7 +1,7 @@ // Verify debuginfo for async fn: // - Each variant points to the file and line of its yield point -// - The generator types and variants are marked artificial -// - Captured vars from the source are not marked artificial +// - The discriminants are marked artificial +// - Other fields are not marked artificial // // // compile-flags: -C debuginfo=2 --edition=2018 @@ -17,29 +17,36 @@ async fn async_fn_test() { // FIXME: No way to reliably check the filename. // CHECK-DAG: [[ASYNC_FN:!.*]] = !DINamespace(name: "async_fn_test" -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[ASYNC_FN]], {{.*}}flags: DIFlagArtificial +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[ASYNC_FN]] // CHECK: [[VARIANT:!.*]] = !DICompositeType(tag: DW_TAG_variant_part, scope: [[ASYNC_FN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial // CHECK-SAME: discriminator: [[DISC:![0-9]*]] // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE:![0-9]*]], line: 11, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 12, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 14, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] // CHECK-NOT: flags: DIFlagArtificial // CHECK-SAME: ) diff --git a/src/test/codegen/generator-debug-msvc.rs b/src/test/codegen/generator-debug-msvc.rs index 4f8a320ee9b17..44be71f3b9b80 100644 --- a/src/test/codegen/generator-debug-msvc.rs +++ b/src/test/codegen/generator-debug-msvc.rs @@ -1,7 +1,7 @@ // Verify debuginfo for generators: // - Each variant points to the file and line of its yield point -// - The generator types and variants are marked artificial -// - Captured vars from the source are not marked artificial +// - The discriminants are marked artificial +// - Other fields are not marked artificial // // // compile-flags: -C debuginfo=2 @@ -21,26 +21,32 @@ fn generator_test() -> impl Generator { // FIXME: No way to reliably check the filename. // CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "generator_test" -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[GEN_FN]], {{.*}}flags: DIFlagArtificial +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[GEN_FN]] // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // For brevity, we only check the struct name and members of the last variant. // CHECK-SAME: file: [[FILE:![0-9]*]], line: 14, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 18, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 18, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], // CHECK-SAME: file: [[FILE]], line: 17, // CHECK-SAME: baseType: [[VARIANT:![0-9]*]] -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN_FN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "RUST$ENUM$DISR", scope: [[S1]], // CHECK-SAME: flags: DIFlagArtificial // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] diff --git a/src/test/codegen/generator-debug.rs b/src/test/codegen/generator-debug.rs index 86ac6db702ab9..8b87a2f064604 100644 --- a/src/test/codegen/generator-debug.rs +++ b/src/test/codegen/generator-debug.rs @@ -1,7 +1,7 @@ // Verify debuginfo for generators: // - Each variant points to the file and line of its yield point -// - The generator types and variants are marked artificial -// - Captured vars from the source are not marked artificial +// - The discriminants are marked artificial +// - Other fields are not marked artificial // // // compile-flags: -C debuginfo=2 --edition=2018 @@ -21,29 +21,36 @@ fn generator_test() -> impl Generator { // FIXME: No way to reliably check the filename. // CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "generator_test" -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[GEN_FN]], {{.*}}flags: DIFlagArtificial +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[GEN_FN]] // CHECK: [[VARIANT:!.*]] = !DICompositeType(tag: DW_TAG_variant_part, scope: [[GEN_FN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial // CHECK-SAME: discriminator: [[DISC:![0-9]*]] // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE:![0-9]*]], line: 14, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 18, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 18, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 15, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]], // CHECK-SAME: file: [[FILE]], line: 17, -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]], -// CHECK-SAME: flags: DIFlagArtificial +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] // CHECK-NOT: flags: DIFlagArtificial // CHECK-SAME: ) diff --git a/src/test/debuginfo/generator-objects.rs b/src/test/debuginfo/generator-objects.rs index 3437b295e6e9c..1beed1c835d97 100644 --- a/src/test/debuginfo/generator-objects.rs +++ b/src/test/debuginfo/generator-objects.rs @@ -1,22 +1,26 @@ // Require a gdb that can read DW_TAG_variant_part. // min-gdb-version: 8.2 +// LLDB without native Rust support cannot read DW_TAG_variant_part, +// so it prints nothing for generators. But those tests are kept to +// ensure that LLDB won't crash at least (like #57822). + // compile-flags:-g // === GDB TESTS =================================================================================== // gdb-command:run // gdb-command:print b -// gdb-check:$1 = +// gdb-check:$1 = generator_objects::main::generator-0::Unresumed(0x[...]) // gdb-command:continue // gdb-command:print b -// gdb-check:$2 = +// gdb-check:$2 = generator_objects::main::generator-0::Suspend0{c: 6, d: 7, __0: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$3 = +// gdb-check:$3 = generator_objects::main::generator-0::Suspend1{c: 7, d: 8, __0: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$4 = +// gdb-check:$4 = generator_objects::main::generator-0::Returned(0x[...]) // === LLDB TESTS ================================================================================== diff --git a/src/test/debuginfo/issue-57822.rs b/src/test/debuginfo/issue-57822.rs index 3a9eaecd5e75e..6b2b12edda5d7 100644 --- a/src/test/debuginfo/issue-57822.rs +++ b/src/test/debuginfo/issue-57822.rs @@ -14,7 +14,7 @@ // gdb-check:$1 = issue_57822::main::closure-1 (issue_57822::main::closure-0 (1)) // gdb-command:print b -// gdb-check:$2 = +// gdb-check:$2 = issue_57822::main::generator-3::Unresumed(issue_57822::main::generator-2::Unresumed(2)) // === LLDB TESTS ================================================================================== From 49e67c393d4706f05f256d87551ea60dc40f20ee Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 30 Apr 2021 13:04:43 -0700 Subject: [PATCH 7/8] Update compiler-builtins to 0.1.41 to get fix for outlined atomics This should fix linking of other C code (and soon Rust-generated code) on aarch64 musl. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a55ef7b61436e..f7075cafb5e2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -666,9 +666,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3748f82c7d366a0b4950257d19db685d4958d2fa27c6d164a3f069fec42b748b" +checksum = "68448b4c6cee41f17bef42cbdad2fde55d05b91a6116c3a517e5389fb742758d" dependencies = [ "cc", "rustc-std-workspace-core", From 649bf22df56c18b28d41978990071b513094345d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= Date: Sat, 1 May 2021 15:33:49 +0200 Subject: [PATCH 8/8] compute where_outer on demand, remove it from Module --- src/librustdoc/clean/mod.rs | 5 +++-- src/librustdoc/doctree.rs | 13 ++++++++----- src/librustdoc/visit_ast.rs | 11 +++-------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6563f398edb6f..12f03d00a657f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -100,12 +100,13 @@ impl Clean for doctree::Module<'_> { // determine if we should display the inner contents or // the outer `mod` item for the source code. let span = Span::from_rustc_span({ + let where_outer = self.where_outer(cx.tcx); let sm = cx.sess().source_map(); - let outer = sm.lookup_char_pos(self.where_outer.lo()); + let outer = sm.lookup_char_pos(where_outer.lo()); let inner = sm.lookup_char_pos(self.where_inner.lo()); if outer.file.start_pos == inner.file.start_pos { // mod foo { ... } - self.where_outer + where_outer } else { // mod foo; (and a separate SourceFile for the contents) self.where_inner diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index d3f4353a58b7b..eadac89f79ef2 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -1,12 +1,12 @@ //! This module is used to store stuff from Rust's AST in a more convenient //! manner (and with prettier names) before cleaning. +use rustc_middle::ty::TyCtxt; use rustc_span::{self, Span, Symbol}; use rustc_hir as hir; crate struct Module<'hir> { crate name: Symbol, - crate where_outer: Span, crate where_inner: Span, crate mods: Vec>, crate id: hir::HirId, @@ -17,16 +17,19 @@ crate struct Module<'hir> { } impl Module<'hir> { - crate fn new(name: Symbol) -> Module<'hir> { + crate fn new(name: Symbol, id: hir::HirId, where_inner: Span) -> Module<'hir> { Module { name, - id: hir::CRATE_HIR_ID, - where_outer: rustc_span::DUMMY_SP, - where_inner: rustc_span::DUMMY_SP, + id, + where_inner, mods: Vec::new(), items: Vec::new(), foreigns: Vec::new(), macros: Vec::new(), } } + + crate fn where_outer(&self, tcx: TyCtxt<'_>) -> Span { + tcx.hir().span(self.id) + } } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index c9071eea78b79..ab9a112380ec4 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -8,9 +8,9 @@ use rustc_hir::def_id::DefId; use rustc_hir::Node; use rustc_middle::middle::privacy::AccessLevel; use rustc_middle::ty::TyCtxt; +use rustc_span; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Symbol}; -use rustc_span::{self, Span}; use std::mem; @@ -73,7 +73,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> { let span = krate.item.inner; let mut top_level_module = self.visit_mod_contents( - span, &Spanned { span, node: hir::VisibilityKind::Public }, hir::CRATE_HIR_ID, &krate.item, @@ -129,16 +128,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_mod_contents( &mut self, - span: Span, vis: &hir::Visibility<'_>, id: hir::HirId, m: &'tcx hir::Mod<'tcx>, name: Symbol, ) -> Module<'tcx> { - let mut om = Module::new(name); - om.where_outer = span; - om.where_inner = m.inner; - om.id = id; + let mut om = Module::new(name, id, m.inner); // Keep track of if there were any private modules in the path. let orig_inside_public_path = self.inside_public_path; self.inside_public_path &= vis.node.is_pub(); @@ -312,7 +307,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.items.push((item, renamed)) } hir::ItemKind::Mod(ref m) => { - om.mods.push(self.visit_mod_contents(item.span, &item.vis, item.hir_id(), m, name)); + om.mods.push(self.visit_mod_contents(&item.vis, item.hir_id(), m, name)); } hir::ItemKind::Fn(..) | hir::ItemKind::ExternCrate(..)