Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee91e31

Browse files
authored
Unrolled build for #146704
Rollup merge of #146704 - jdonszelmann:port-debug-visualizer, r=petrochenkov port `#[debugger_visualizer]` to the new attribute system
2 parents 54a8a1d + 9acc63a commit ee91e31

File tree

18 files changed

+185
-154
lines changed

18 files changed

+185
-154
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use rustc_hir::attrs::{DebugVisualizer, DebuggerVisualizerType};
2+
3+
use super::prelude::*;
4+
5+
pub(crate) struct DebuggerViualizerParser;
6+
7+
impl<S: Stage> CombineAttributeParser<S> for DebuggerViualizerParser {
8+
const PATH: &[Symbol] = &[sym::debugger_visualizer];
9+
const ALLOWED_TARGETS: AllowedTargets =
10+
AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::Crate)]);
11+
const TEMPLATE: AttributeTemplate = template!(
12+
List: &[r#"natvis_file = "...", gdb_script_file = "...""#],
13+
"https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"
14+
);
15+
16+
type Item = DebugVisualizer;
17+
const CONVERT: ConvertFn<Self::Item> = |v, _| AttributeKind::DebuggerVisualizer(v);
18+
19+
fn extend<'c>(
20+
cx: &'c mut AcceptContext<'_, '_, S>,
21+
args: &'c ArgParser<'_>,
22+
) -> impl IntoIterator<Item = Self::Item> + 'c {
23+
let Some(l) = args.list() else {
24+
cx.expected_list(args.span().unwrap_or(cx.attr_span));
25+
return None;
26+
};
27+
let Some(single) = l.single() else {
28+
cx.expected_single_argument(l.span);
29+
return None;
30+
};
31+
let Some(mi) = single.meta_item() else {
32+
cx.expected_name_value(single.span(), None);
33+
return None;
34+
};
35+
let path = mi.path().word_sym();
36+
let visualizer_type = match path {
37+
Some(sym::natvis_file) => DebuggerVisualizerType::Natvis,
38+
Some(sym::gdb_script_file) => DebuggerVisualizerType::GdbPrettyPrinter,
39+
_ => {
40+
cx.expected_specific_argument(
41+
mi.path().span(),
42+
&[sym::natvis_file, sym::gdb_script_file],
43+
);
44+
return None;
45+
}
46+
};
47+
48+
let Some(path) = mi.args().name_value() else {
49+
cx.expected_name_value(single.span(), path);
50+
return None;
51+
};
52+
53+
let Some(path) = path.value_as_str() else {
54+
cx.expected_string_literal(path.value_span, Some(path.value_as_lit()));
55+
return None;
56+
};
57+
58+
Some(DebugVisualizer { span: mi.span(), visualizer_type, path })
59+
}
60+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) mod cfg_old;
3636
pub(crate) mod codegen_attrs;
3737
pub(crate) mod confusables;
3838
pub(crate) mod crate_level;
39+
pub(crate) mod debugger;
3940
pub(crate) mod deprecation;
4041
pub(crate) mod dummy;
4142
pub(crate) mod inline;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::attributes::crate_level::{
2828
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoStdParser, PatternComplexityLimitParser,
2929
RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
3030
};
31+
use crate::attributes::debugger::DebuggerViualizerParser;
3132
use crate::attributes::deprecation::DeprecationParser;
3233
use crate::attributes::dummy::DummyParser;
3334
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -163,6 +164,7 @@ attribute_parsers!(
163164
// tidy-alphabetical-start
164165
Combine<AllowConstFnUnstableParser>,
165166
Combine<AllowInternalUnstableParser>,
167+
Combine<DebuggerViualizerParser>,
166168
Combine<ForceTargetFeatureParser>,
167169
Combine<LinkParser>,
168170
Combine<ReprParser>,

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
44
use rustc_codegen_ssa::traits::*;
5+
use rustc_hir::attrs::DebuggerVisualizerType;
56
use rustc_hir::def_id::LOCAL_CRATE;
67
use rustc_middle::bug;
7-
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
88
use rustc_session::config::{CrateType, DebugInfo};
99

1010
use crate::builder::Builder;

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1111
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
1212
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
1313
use rustc_data_structures::unord::UnordMap;
14-
use rustc_hir::attrs::OptimizeAttr;
14+
use rustc_hir::attrs::{DebuggerVisualizerType, OptimizeAttr};
1515
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1616
use rustc_hir::lang_items::LangItem;
1717
use rustc_hir::{ItemId, Target};
1818
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
19-
use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, DebuggerVisualizerType};
19+
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
2020
use rustc_middle::middle::dependency_format::Dependencies;
2121
use rustc_middle::middle::exported_symbols::{self, SymbolExportKind};
2222
use rustc_middle::middle::lang_items;

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,20 @@ pub struct LinkEntry {
363363
pub import_name_type: Option<(PeImportNameType, Span)>,
364364
}
365365

366+
#[derive(HashStable_Generic, PrintAttribute)]
367+
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)]
368+
pub enum DebuggerVisualizerType {
369+
Natvis,
370+
GdbPrettyPrinter,
371+
}
372+
373+
#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
374+
pub struct DebugVisualizer {
375+
pub span: Span,
376+
pub visualizer_type: DebuggerVisualizerType,
377+
pub path: Symbol,
378+
}
379+
366380
/// Represents parsed *built-in* inert attributes.
367381
///
368382
/// ## Overview
@@ -485,7 +499,10 @@ pub enum AttributeKind {
485499
/// Represents `#[custom_mir]`.
486500
CustomMir(Option<(MirDialect, Span)>, Option<(MirPhase, Span)>, Span),
487501

488-
///Represents `#[rustc_deny_explicit_impl]`.
502+
/// Represents `#[debugger_visualizer]`.
503+
DebuggerVisualizer(ThinVec<DebugVisualizer>),
504+
505+
/// Represents `#[rustc_deny_explicit_impl]`.
489506
DenyExplicitImpl(Span),
490507

491508
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl AttributeKind {
3737
Coverage(..) => No,
3838
CrateName { .. } => No,
3939
CustomMir(_, _, _) => Yes,
40+
DebuggerVisualizer(..) => No,
4041
DenyExplicitImpl(..) => No,
4142
Deprecation { .. } => Yes,
4243
DoNotImplementViaObject(..) => No,

compiler/rustc_middle/src/middle/debugger_visualizer.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
use std::path::PathBuf;
22
use std::sync::Arc;
33

4+
use rustc_hir::attrs::DebuggerVisualizerType;
45
use rustc_macros::{Decodable, Encodable, HashStable};
56

6-
#[derive(HashStable)]
7-
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)]
8-
pub enum DebuggerVisualizerType {
9-
Natvis,
10-
GdbPrettyPrinter,
11-
}
12-
137
/// A single debugger visualizer file.
148
#[derive(HashStable)]
159
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ passes_dead_codes =
9393
}
9494
} never {$participle}
9595
96-
passes_debug_visualizer_invalid =
97-
invalid argument
98-
.note_1 = expected: `natvis_file = "..."`
99-
.note_2 = OR
100-
.note_3 = expected: `gdb_script_file = "..."`
101-
102-
passes_debug_visualizer_placement =
103-
attribute should be applied to a module
104-
10596
passes_debug_visualizer_unreadable =
10697
couldn't read {$file}: {$error}
10798

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
282282
| AttributeKind::ObjcClass { .. }
283283
| AttributeKind::ObjcSelector { .. }
284284
| AttributeKind::RustcCoherenceIsCore(..)
285+
| AttributeKind::DebuggerVisualizer(..)
285286
) => { /* do nothing */ }
286287
Attribute::Unparsed(attr_item) => {
287288
style = Some(attr_item.style);
@@ -302,7 +303,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
302303
&mut doc_aliases,
303304
),
304305
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
305-
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
306306
[sym::rustc_no_implicit_autorefs, ..] => {
307307
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
308308
}
@@ -1783,20 +1783,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17831783
}
17841784
}
17851785

1786-
/// Checks if the items on the `#[debugger_visualizer]` attribute are valid.
1787-
fn check_debugger_visualizer(&self, attr: &Attribute, target: Target) {
1788-
// Here we only check that the #[debugger_visualizer] attribute is attached
1789-
// to nothing other than a module. All other checks are done in the
1790-
// `debugger_visualizer` query where they need to be done for decoding
1791-
// anyway.
1792-
match target {
1793-
Target::Mod => {}
1794-
_ => {
1795-
self.dcx().emit_err(errors::DebugVisualizerPlacement { span: attr.span() });
1796-
}
1797-
}
1798-
}
1799-
18001786
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
18011787
/// (Allows proc_macro functions)
18021788
fn check_rustc_allow_const_fn_unstable(

0 commit comments

Comments
 (0)