Skip to content

Commit 147a4fb

Browse files
committed
Auto merge of #143876 - matthiaskrgr:rollup-iz5vqpq, r=matthiaskrgr
Rollup of 13 pull requests Successful merges: - #143301 (`tests/ui`: A New Order [26/N]) - #143461 (make `cfg_select` a builtin macro) - #143519 (Check assoc consts and tys later like assoc fns) - #143554 (slice: Mark `rotate_left`, `rotate_right` unstably const) - #143634 (interpret/allocation: expose init + write_wildcards on a range) - #143679 (Preserve the .debug_gdb_scripts section) - #143685 (Resolve: merge `source_bindings` and `target_bindings` into `bindings`) - #143734 (Refactor resolve resolution bindings) - #143774 (constify `From` and `Into`) - #143785 (Add --compile-time-deps argument for x check) - #143786 (Fix fallback for CI_JOB_NAME) - #143825 (clippy: fix test filtering when TESTNAME is empty) - #143826 (Fix command trace) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0fb279b + 29f2761 commit 147a4fb

File tree

125 files changed

+1370
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1370
-706
lines changed

compiler/rustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms']
2727

2828
[features]
2929
# tidy-alphabetical-start
30+
check_only = ['rustc_driver_impl/check_only']
3031
jemalloc = ['dep:tikv-jemalloc-sys']
3132
llvm = ['rustc_driver_impl/llvm']
3233
max_level_info = ['rustc_driver_impl/max_level_info']

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ builtin_macros_cfg_accessible_literal_path = `cfg_accessible` path cannot be a l
8181
builtin_macros_cfg_accessible_multiple_paths = multiple `cfg_accessible` paths are specified
8282
builtin_macros_cfg_accessible_unspecified_path = `cfg_accessible` path is not specified
8383
84+
builtin_macros_cfg_select_no_matches = none of the rules in this `cfg_select` evaluated to true
85+
86+
builtin_macros_cfg_select_unreachable = unreachable rule
87+
.label = always matches
88+
.label2 = this rules is never reached
89+
8490
builtin_macros_coerce_pointee_requires_maybe_sized = `derive(CoercePointee)` requires `{$name}` to be marked `?Sized`
8591
8692
builtin_macros_coerce_pointee_requires_one_field = `CoercePointee` can only be derived on `struct`s with at least one field
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use rustc_ast::tokenstream::TokenStream;
2+
use rustc_attr_parsing as attr;
3+
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
4+
use rustc_parse::parser::cfg_select::{CfgSelectBranches, CfgSelectRule, parse_cfg_select};
5+
use rustc_span::{Ident, Span, sym};
6+
7+
use crate::errors::{CfgSelectNoMatches, CfgSelectUnreachable};
8+
9+
/// Selects the first arm whose rule evaluates to true.
10+
fn select_arm(ecx: &ExtCtxt<'_>, branches: CfgSelectBranches) -> Option<(TokenStream, Span)> {
11+
for (cfg, tt, arm_span) in branches.reachable {
12+
if attr::cfg_matches(
13+
&cfg,
14+
&ecx.sess,
15+
ecx.current_expansion.lint_node_id,
16+
Some(ecx.ecfg.features),
17+
) {
18+
return Some((tt, arm_span));
19+
}
20+
}
21+
22+
branches.wildcard.map(|(_, tt, span)| (tt, span))
23+
}
24+
25+
pub(super) fn expand_cfg_select<'cx>(
26+
ecx: &'cx mut ExtCtxt<'_>,
27+
sp: Span,
28+
tts: TokenStream,
29+
) -> MacroExpanderResult<'cx> {
30+
ExpandResult::Ready(match parse_cfg_select(&mut ecx.new_parser_from_tts(tts)) {
31+
Ok(branches) => {
32+
if let Some((underscore, _, _)) = branches.wildcard {
33+
// Warn for every unreachable rule. We store the fully parsed branch for rustfmt.
34+
for (rule, _, _) in &branches.unreachable {
35+
let span = match rule {
36+
CfgSelectRule::Wildcard(underscore) => underscore.span,
37+
CfgSelectRule::Cfg(cfg) => cfg.span(),
38+
};
39+
let err = CfgSelectUnreachable { span, wildcard_span: underscore.span };
40+
ecx.dcx().emit_warn(err);
41+
}
42+
}
43+
44+
if let Some((tts, arm_span)) = select_arm(ecx, branches) {
45+
return ExpandResult::from_tts(
46+
ecx,
47+
tts,
48+
sp,
49+
arm_span,
50+
Ident::with_dummy_span(sym::cfg_select),
51+
);
52+
} else {
53+
// Emit a compiler error when none of the rules matched.
54+
let guar = ecx.dcx().emit_err(CfgSelectNoMatches { span: sp });
55+
DummyResult::any(sp, guar)
56+
}
57+
}
58+
Err(err) => {
59+
let guar = err.emit();
60+
DummyResult::any(sp, guar)
61+
}
62+
})
63+
}

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,3 +954,21 @@ pub(crate) struct AsmExpectedOther {
954954
pub(crate) span: Span,
955955
pub(crate) is_inline_asm: bool,
956956
}
957+
958+
#[derive(Diagnostic)]
959+
#[diag(builtin_macros_cfg_select_no_matches)]
960+
pub(crate) struct CfgSelectNoMatches {
961+
#[primary_span]
962+
pub span: Span,
963+
}
964+
965+
#[derive(Diagnostic)]
966+
#[diag(builtin_macros_cfg_select_unreachable)]
967+
pub(crate) struct CfgSelectUnreachable {
968+
#[primary_span]
969+
#[label(builtin_macros_label2)]
970+
pub span: Span,
971+
972+
#[label]
973+
pub wildcard_span: Span,
974+
}

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod autodiff;
3333
mod cfg;
3434
mod cfg_accessible;
3535
mod cfg_eval;
36+
mod cfg_select;
3637
mod compile_error;
3738
mod concat;
3839
mod concat_bytes;
@@ -79,6 +80,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
7980
asm: asm::expand_asm,
8081
assert: assert::expand_assert,
8182
cfg: cfg::expand_cfg,
83+
cfg_select: cfg_select::expand_cfg_select,
8284
column: source_util::expand_column,
8385
compile_error: compile_error::expand_compile_error,
8486
concat: concat::expand_concat,

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
3636
_variable_alloca.set_location(_dbg_loc);
3737
}
3838

39-
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
40-
// TODO(antoyo): insert reference to gdb debug scripts section global.
41-
}
42-
4339
/// FIXME(tempdragon): Currently, this function is not yet implemented. It seems that the
4440
/// debug name and the mangled name should both be included in the LValues.
4541
/// Besides, a function to get the rvalue type(m_is_lvalue) should also be included.
@@ -254,7 +250,8 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
254250
// TODO(antoyo): implement.
255251
}
256252

257-
fn debuginfo_finalize(&self) {
253+
fn debuginfo_finalize(&mut self) {
254+
// TODO: emit section `.debug_gdb_scripts`.
258255
self.context.set_debug_info(true)
259256
}
260257

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ serde_json = "1"
4343
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4444
tracing = "0.1"
4545
# tidy-alphabetical-end
46+
47+
[features]
48+
check_only = ["rustc_llvm/check_only"]

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ pub(crate) fn compile_codegen_unit(
109109
}
110110

111111
// Finalize code coverage by injecting the coverage map. Note, the coverage map will
112-
// also be added to the `llvm.compiler.used` variable, created next.
112+
// also be added to the `llvm.compiler.used` variable, created below.
113113
if cx.sess().instrument_coverage() {
114114
cx.coverageinfo_finalize();
115115
}
116116

117+
// Finalize debuginfo. This adds to `llvm.used`, created below.
118+
if cx.sess().opts.debuginfo != DebugInfo::None {
119+
cx.debuginfo_finalize();
120+
}
121+
117122
// Create the llvm.used and llvm.compiler.used variables.
118123
if !cx.used_statics.is_empty() {
119124
cx.create_used_variable_impl(c"llvm.used", &cx.used_statics);
@@ -130,11 +135,6 @@ pub(crate) fn compile_codegen_unit(
130135
llvm::LLVMDeleteGlobal(old_g);
131136
}
132137
}
133-
134-
// Finalize debuginfo
135-
if cx.sess().opts.debuginfo != DebugInfo::None {
136-
cx.debuginfo_finalize();
137-
}
138138
}
139139

140140
ModuleCodegen::new_regular(cgu_name.to_string(), llvm_module)

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// .debug_gdb_scripts binary section.
22

3+
use std::ffi::CString;
4+
35
use rustc_ast::attr;
46
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
57
use rustc_codegen_ssa::traits::*;
@@ -9,31 +11,21 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
911
use rustc_session::config::{CrateType, DebugInfo};
1012
use rustc_span::sym;
1113

12-
use crate::builder::Builder;
1314
use crate::common::CodegenCx;
1415
use crate::llvm;
1516
use crate::value::Value;
1617

17-
/// Inserts a side-effect free instruction sequence that makes sure that the
18-
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
19-
pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) {
20-
if needs_gdb_debug_scripts_section(bx) {
21-
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx);
22-
// Load just the first byte as that's all that's necessary to force
23-
// LLVM to keep around the reference to the global.
24-
let volatile_load_instruction = bx.volatile_load(bx.type_i8(), gdb_debug_scripts_section);
25-
unsafe {
26-
llvm::LLVMSetAlignment(volatile_load_instruction, 1);
27-
}
28-
}
29-
}
30-
3118
/// Allocates the global variable responsible for the .debug_gdb_scripts binary
3219
/// section.
3320
pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
34-
cx: &CodegenCx<'ll, '_>,
21+
cx: &mut CodegenCx<'ll, '_>,
3522
) -> &'ll Value {
36-
let c_section_var_name = c"__rustc_debug_gdb_scripts_section__";
23+
let c_section_var_name = CString::new(format!(
24+
"__rustc_debug_gdb_scripts_section_{}_{:08x}",
25+
cx.tcx.crate_name(LOCAL_CRATE),
26+
cx.tcx.stable_crate_id(LOCAL_CRATE),
27+
))
28+
.unwrap();
3729
let section_var_name = c_section_var_name.to_str().unwrap();
3830

3931
let section_var = unsafe { llvm::LLVMGetNamedGlobal(cx.llmod, c_section_var_name.as_ptr()) };
@@ -80,6 +72,8 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8072
// This should make sure that the whole section is not larger than
8173
// the string it contains. Otherwise we get a warning from GDB.
8274
llvm::LLVMSetAlignment(section_var, 1);
75+
// Make sure that the linker doesn't optimize the global away.
76+
cx.add_used_global(section_var);
8377
section_var
8478
}
8579
})

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tracing::debug;
3030

3131
use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, type_di_node};
3232
use self::namespace::mangled_name_of_instance;
33-
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
33+
use self::utils::{DIB, create_DIArray, debug_context, is_node_local_to_unit};
3434
use crate::builder::Builder;
3535
use crate::common::{AsCCharPtr, CodegenCx};
3636
use crate::llvm;
@@ -131,20 +131,22 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
131131
}
132132

133133
/// Creates any deferred debug metadata nodes
134-
pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
135-
if let Some(dbg_cx) = &cx.dbg_cx {
136-
debug!("finalize");
137-
138-
if gdb::needs_gdb_debug_scripts_section(cx) {
139-
// Add a .debug_gdb_scripts section to this compile-unit. This will
140-
// cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
141-
// which activates the Rust pretty printers for binary this section is
142-
// contained in.
143-
gdb::get_or_insert_gdb_debug_scripts_section_global(cx);
144-
}
134+
pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
135+
if cx.dbg_cx.is_none() {
136+
return;
137+
}
138+
139+
debug!("finalize");
145140

146-
dbg_cx.finalize(cx.sess());
141+
if gdb::needs_gdb_debug_scripts_section(cx) {
142+
// Add a .debug_gdb_scripts section to this compile-unit. This will
143+
// cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
144+
// which activates the Rust pretty printers for binary this section is
145+
// contained in.
146+
gdb::get_or_insert_gdb_debug_scripts_section_global(cx);
147147
}
148+
149+
debug_context(cx).finalize(cx.sess());
148150
}
149151

150152
impl<'ll> Builder<'_, 'll, '_> {
@@ -215,10 +217,6 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
215217
}
216218
}
217219

218-
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
219-
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
220-
}
221-
222220
fn set_var_name(&mut self, value: &'ll Value, name: &str) {
223221
// Avoid wasting time if LLVM value names aren't even enabled.
224222
if self.sess().fewer_names() {
@@ -614,7 +612,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
614612
metadata::extend_scope_to_file(self, scope_metadata, file)
615613
}
616614

617-
fn debuginfo_finalize(&self) {
615+
fn debuginfo_finalize(&mut self) {
618616
finalize(self)
619617
}
620618

0 commit comments

Comments
 (0)