Skip to content

Commit 0ea4528

Browse files
authored
Unrolled build for #150938
Rollup merge of #150938 - collapse_debuginfo, r=jdonszelmann Port `#[collapse_debuginfo]` to the new attribute parsing system Tracking issue: #131229 Felt like doing one again, has been a while :3 r? @jdonszelmann
2 parents 44a5b55 + f0da783 commit 0ea4528

File tree

15 files changed

+210
-264
lines changed

15 files changed

+210
-264
lines changed

‎compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_hir::attrs::MacroUseArgs;
1+
use rustc_hir::attrs::{CollapseMacroDebuginfo, MacroUseArgs};
22
use rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS;
33

44
use super::prelude::*;
@@ -163,3 +163,46 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
163163
Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
164164
}
165165
}
166+
167+
pub(crate) struct CollapseDebugInfoParser;
168+
169+
impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
170+
const PATH: &[Symbol] = &[sym::collapse_debuginfo];
171+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
172+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
173+
const TEMPLATE: AttributeTemplate = template!(
174+
List: &["no", "external", "yes"],
175+
"https://doc.rust-lang.org/reference/attributes/debugger.html#the-collapse_debuginfo-attribute"
176+
);
177+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::MacroDef)]);
178+
179+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
180+
let Some(list) = args.list() else {
181+
cx.expected_list(cx.attr_span, args);
182+
return None;
183+
};
184+
let Some(single) = list.single() else {
185+
cx.expected_single_argument(list.span);
186+
return None;
187+
};
188+
let Some(mi) = single.meta_item() else {
189+
cx.unexpected_literal(single.span());
190+
return None;
191+
};
192+
if let Err(err) = mi.args().no_args() {
193+
cx.expected_no_args(err);
194+
}
195+
let path = mi.path().word_sym();
196+
let info = match path {
197+
Some(sym::yes) => CollapseMacroDebuginfo::Yes,
198+
Some(sym::no) => CollapseMacroDebuginfo::No,
199+
Some(sym::external) => CollapseMacroDebuginfo::External,
200+
_ => {
201+
cx.expected_specific_argument(mi.span(), &[sym::yes, sym::no, sym::external]);
202+
return None;
203+
}
204+
};
205+
206+
Some(AttributeKind::CollapseDebugInfo(info))
207+
}
208+
}

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ use crate::attributes::lint_helpers::{
4848
};
4949
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
5050
use crate::attributes::macro_attrs::{
51-
AllowInternalUnsafeParser, MacroEscapeParser, MacroExportParser, MacroUseParser,
51+
AllowInternalUnsafeParser, CollapseDebugInfoParser, MacroEscapeParser, MacroExportParser,
52+
MacroUseParser,
5253
};
5354
use crate::attributes::must_use::MustUseParser;
5455
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
@@ -191,6 +192,7 @@ attribute_parsers!(
191192

192193
// tidy-alphabetical-start
193194
Single<CfiEncodingParser>,
195+
Single<CollapseDebugInfoParser>,
194196
Single<CoverageParser>,
195197
Single<CrateNameParser>,
196198
Single<CustomMirParser>,

‎compiler/rustc_expand/messages.ftl‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ expand_attributes_on_expressions_experimental =
55
66
expand_cfg_attr_no_attributes = `#[cfg_attr]` does not expand to any attributes
77
8-
expand_collapse_debuginfo_illegal =
9-
illegal value for attribute #[collapse_debuginfo(no|external|yes)]
10-
118
expand_count_repetition_misplaced =
129
`count` can not be placed inside the innermost repetition
1310

‎compiler/rustc_expand/src/base.rs‎

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
66
use std::rc::Rc;
77
use std::sync::Arc;
88

9-
use rustc_ast::attr::{AttributeExt, MarkedAttrs};
9+
use rustc_ast::attr::MarkedAttrs;
1010
use rustc_ast::token::MetaVarKind;
1111
use rustc_ast::tokenstream::TokenStream;
1212
use rustc_ast::visit::{AssocCtxt, Visitor};
@@ -16,15 +16,14 @@ use rustc_data_structures::sync;
1616
use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed, PResult};
1717
use rustc_feature::Features;
1818
use rustc_hir as hir;
19-
use rustc_hir::attrs::{AttributeKind, CfgEntry, Deprecation};
19+
use rustc_hir::attrs::{AttributeKind, CfgEntry, CollapseMacroDebuginfo, Deprecation};
2020
use rustc_hir::def::MacroKinds;
2121
use rustc_hir::limit::Limit;
2222
use rustc_hir::{Stability, find_attr};
2323
use rustc_lint_defs::RegisteredTools;
2424
use rustc_parse::MACRO_ARGUMENTS;
2525
use rustc_parse::parser::{ForceCollect, Parser};
2626
use rustc_session::Session;
27-
use rustc_session::config::CollapseMacroDebuginfo;
2827
use rustc_session::parse::ParseSess;
2928
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
3029
use rustc_span::edition::Edition;
@@ -34,7 +33,6 @@ use rustc_span::{DUMMY_SP, FileName, Ident, Span, Symbol, kw, sym};
3433
use smallvec::{SmallVec, smallvec};
3534
use thin_vec::ThinVec;
3635

37-
use crate::base::ast::MetaItemInner;
3836
use crate::errors;
3937
use crate::expand::{self, AstFragment, Invocation};
4038
use crate::mbe::macro_rules::ParserAnyMacro;
@@ -887,25 +885,6 @@ impl SyntaxExtension {
887885
}
888886
}
889887

890-
fn collapse_debuginfo_by_name(
891-
attr: &impl AttributeExt,
892-
) -> Result<CollapseMacroDebuginfo, Span> {
893-
let list = attr.meta_item_list();
894-
let Some([MetaItemInner::MetaItem(item)]) = list.as_deref() else {
895-
return Err(attr.span());
896-
};
897-
if !item.is_word() {
898-
return Err(item.span);
899-
}
900-
901-
match item.name() {
902-
Some(sym::no) => Ok(CollapseMacroDebuginfo::No),
903-
Some(sym::external) => Ok(CollapseMacroDebuginfo::External),
904-
Some(sym::yes) => Ok(CollapseMacroDebuginfo::Yes),
905-
_ => Err(item.path.span),
906-
}
907-
}
908-
909888
/// if-ext - if macro from different crate (related to callsite code)
910889
/// | cmd \ attr | no | (unspecified) | external | yes |
911890
/// | no | no | no | no | no |
@@ -914,21 +893,15 @@ impl SyntaxExtension {
914893
/// | yes | yes | yes | yes | yes |
915894
fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) -> bool {
916895
let flag = sess.opts.cg.collapse_macro_debuginfo;
917-
let attr = ast::attr::find_by_name(attrs, sym::collapse_debuginfo)
918-
.and_then(|attr| {
919-
Self::collapse_debuginfo_by_name(attr)
920-
.map_err(|span| {
921-
sess.dcx().emit_err(errors::CollapseMacroDebuginfoIllegal { span })
922-
})
923-
.ok()
924-
})
925-
.unwrap_or_else(|| {
926-
if find_attr!(attrs, AttributeKind::RustcBuiltinMacro { .. }) {
927-
CollapseMacroDebuginfo::Yes
928-
} else {
929-
CollapseMacroDebuginfo::Unspecified
930-
}
931-
});
896+
let attr =
897+
if let Some(info) = find_attr!(attrs, AttributeKind::CollapseDebugInfo(info) => info) {
898+
info.clone()
899+
} else if find_attr!(attrs, AttributeKind::RustcBuiltinMacro { .. }) {
900+
CollapseMacroDebuginfo::Yes
901+
} else {
902+
CollapseMacroDebuginfo::Unspecified
903+
};
904+
932905
#[rustfmt::skip]
933906
let collapse_table = [
934907
[false, false, false, false],

‎compiler/rustc_expand/src/errors.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ pub(crate) struct ResolveRelativePath {
7878
pub path: String,
7979
}
8080

81-
#[derive(Diagnostic)]
82-
#[diag(expand_collapse_debuginfo_illegal)]
83-
pub(crate) struct CollapseMacroDebuginfoIllegal {
84-
#[primary_span]
85-
pub span: Span,
86-
}
87-
8881
#[derive(Diagnostic)]
8982
#[diag(expand_macro_const_stability)]
9083
pub(crate) struct MacroConstStability {

‎compiler/rustc_hir/src/attrs/data_structures.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,26 @@ impl<E: rustc_span::SpanEncoder> rustc_serialize::Encodable<E> for DocAttribute
568568
}
569569
}
570570

571+
/// How to perform collapse macros debug info
572+
/// if-ext - if macro from different crate (related to callsite code)
573+
/// | cmd \ attr | no | (unspecified) | external | yes |
574+
/// | no | no | no | no | no |
575+
/// | (unspecified) | no | no | if-ext | yes |
576+
/// | external | no | if-ext | if-ext | yes |
577+
/// | yes | yes | yes | yes | yes |
578+
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
579+
#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)]
580+
pub enum CollapseMacroDebuginfo {
581+
/// Don't collapse debuginfo for the macro
582+
No = 0,
583+
/// Unspecified value
584+
Unspecified = 1,
585+
/// Collapse debuginfo if the macro comes from a different crate
586+
External = 2,
587+
/// Collapse debuginfo for the macro
588+
Yes = 3,
589+
}
590+
571591
/// Represents parsed *built-in* inert attributes.
572592
///
573593
/// ## Overview
@@ -664,6 +684,9 @@ pub enum AttributeKind {
664684
/// Represents `#[cold]`.
665685
Cold(Span),
666686

687+
/// Represents `#[collapse_debuginfo]`.
688+
CollapseDebugInfo(CollapseMacroDebuginfo),
689+
667690
/// Represents `#[rustc_confusables]`.
668691
Confusables {
669692
symbols: ThinVec<Symbol>,

‎compiler/rustc_hir/src/attrs/encode_cross_crate.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl AttributeKind {
3131
CfiEncoding { .. } => Yes,
3232
Coinductive(..) => No,
3333
Cold(..) => No,
34+
CollapseDebugInfo(..) => Yes,
3435
Confusables { .. } => Yes,
3536
ConstContinue(..) => No,
3637
ConstStability { .. } => Yes,

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use rustc_abi::Align;
88
use rustc_data_structures::profiling::TimePassesFormat;
99
use rustc_errors::emitter::HumanReadableErrorType;
1010
use rustc_errors::{ColorConfig, registry};
11-
use rustc_hir::attrs::NativeLibKind;
11+
use rustc_hir::attrs::{CollapseMacroDebuginfo, NativeLibKind};
1212
use rustc_session::config::{
13-
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CollapseMacroDebuginfo, CoverageLevel,
14-
CoverageOptions, DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation,
15-
Externs, FmtDebug, FunctionReturn, InliningThreshold, Input, InstrumentCoverage,
16-
InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli, MirIncludeSpans,
17-
NextSolverConfig, Offload, Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet,
18-
Passes, PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath,
13+
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CoverageLevel, CoverageOptions,
14+
DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation, Externs,
15+
FmtDebug, FunctionReturn, InliningThreshold, Input, InstrumentCoverage, InstrumentXRay,
16+
LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli, MirIncludeSpans, NextSolverConfig,
17+
Offload, Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet, Passes,
18+
PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath,
1919
SymbolManglingVersion, WasiExecModel, build_configuration, build_session_options,
2020
rustc_optgroups,
2121
};

‎compiler/rustc_passes/messages.ftl‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ passes_change_fields_to_be_of_unit_type =
5555
*[other] fields
5656
}
5757
58-
passes_collapse_debuginfo =
59-
`collapse_debuginfo` attribute should be applied to macro definitions
60-
.label = not a macro definition
61-
6258
passes_const_continue_attr =
6359
`#[const_continue]` should be applied to a break expression
6460
.label = not a break expression

‎compiler/rustc_passes/src/check_attr.rs‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
229229
| AttributeKind::BodyStability { .. }
230230
| AttributeKind::ConstStabilityIndirect
231231
| AttributeKind::MacroTransparency(_)
232+
| AttributeKind::CollapseDebugInfo(..)
232233
| AttributeKind::CfgTrace(..)
233234
| AttributeKind::Pointee(..)
234235
| AttributeKind::Dummy
@@ -324,7 +325,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
324325
| [sym::rustc_dirty, ..]
325326
| [sym::rustc_if_this_changed, ..]
326327
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
327-
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
328328
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
329329
[sym::autodiff_forward, ..] | [sym::autodiff_reverse, ..] => {
330330
self.check_autodiff(hir_id, attr, span, target)
@@ -716,18 +716,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
716716
}
717717
}
718718
}
719-
/// Checks if `#[collapse_debuginfo]` is applied to a macro.
720-
fn check_collapse_debuginfo(&self, attr: &Attribute, span: Span, target: Target) {
721-
match target {
722-
Target::MacroDef => {}
723-
_ => {
724-
self.tcx.dcx().emit_err(errors::CollapseDebuginfo {
725-
attr_span: attr.span(),
726-
defn_span: span,
727-
});
728-
}
729-
}
730-
}
731719

732720
/// Checks if a `#[track_caller]` is applied to a function.
733721
fn check_track_caller(

0 commit comments

Comments
 (0)