Skip to content

Commit 7405ad3

Browse files
committed
Auto merge of rust-lang#140475 - tgross35:rollup-mdp98bb, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#134232 (Share the naked asm impl between cg_ssa and cg_clif) - rust-lang#140312 (Improve pretty-printing of braces) - rust-lang#140437 (enable msa feature for mips in codegen tests) - rust-lang#140438 (Add `rust.debug-assertions-tools` option) - rust-lang#140439 (miri: algebraic intrinsics: bring back float non-determinism) - rust-lang#140445 (Treat ManuallyDrop as ~const Destruct) - rust-lang#140446 (chore: fix some tests) - rust-lang#140448 (Rename `rustc_query_append!` to `rustc_with_all_queries!`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7450913 + 9529cc4 commit 7405ad3

File tree

59 files changed

+680
-644
lines changed

Some content is hidden

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

59 files changed

+680
-644
lines changed

bootstrap.example.toml

+6
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@
570570
# Defaults to rust.debug-assertions value
571571
#debug-assertions-std = rust.debug-assertions (boolean)
572572

573+
# Whether or not debug assertions are enabled for the tools built by bootstrap.
574+
# Overrides the `debug-assertions` option, if defined.
575+
#
576+
# Defaults to rust.debug-assertions value
577+
#debug-assertions-tools = rust.debug-assertions (boolean)
578+
573579
# Whether or not to leave debug! and trace! calls in the rust binary.
574580
#
575581
# Defaults to rust.debug-assertions value

compiler/rustc_ast_pretty/src/pprust/state.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
634634
false,
635635
None,
636636
*delim,
637+
None,
637638
tokens,
638639
true,
639640
span,
@@ -679,6 +680,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
679680
false,
680681
None,
681682
*delim,
683+
Some(spacing.open),
682684
tts,
683685
convert_dollar_crate,
684686
dspan.entire(),
@@ -735,6 +737,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
735737
has_bang: bool,
736738
ident: Option<Ident>,
737739
delim: Delimiter,
740+
open_spacing: Option<Spacing>,
738741
tts: &TokenStream,
739742
convert_dollar_crate: bool,
740743
span: Span,
@@ -758,16 +761,26 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
758761
self.nbsp();
759762
}
760763
self.word("{");
761-
if !tts.is_empty() {
764+
765+
// Respect `Alone`, if provided, and print a space. Unless the list is empty.
766+
let open_space = (open_spacing == None || open_spacing == Some(Spacing::Alone))
767+
&& !tts.is_empty();
768+
if open_space {
762769
self.space();
763770
}
764771
let ib = self.ibox(0);
765772
self.print_tts(tts, convert_dollar_crate);
766773
self.end(ib);
767-
let empty = tts.is_empty();
768-
self.bclose(span, empty, cb.unwrap());
774+
775+
// Use `open_space` for the spacing *before* the closing delim.
776+
// Because spacing on delimiters is lost when going through
777+
// proc macros, and otherwise we can end up with ugly cases
778+
// like `{ x}`. Symmetry is better.
779+
self.bclose(span, !open_space, cb.unwrap());
769780
}
770781
delim => {
782+
// `open_spacing` is ignored. We never print spaces after
783+
// non-brace opening delims or before non-brace closing delims.
771784
let token_str = self.token_kind_to_string(&delim.as_open_token_kind());
772785
self.word(token_str);
773786
let ib = self.ibox(0);
@@ -797,6 +810,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
797810
has_bang,
798811
Some(*ident),
799812
macro_def.body.delim,
813+
None,
800814
&macro_def.body.tokens,
801815
true,
802816
sp,
@@ -844,9 +858,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
844858
self.end(ib);
845859
}
846860

847-
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, cb: Option<BoxMarker>) {
861+
fn bclose_maybe_open(&mut self, span: rustc_span::Span, no_space: bool, cb: Option<BoxMarker>) {
848862
let has_comment = self.maybe_print_comment(span.hi());
849-
if !empty || has_comment {
863+
if !no_space || has_comment {
850864
self.break_offset_if_not_bol(1, -INDENT_UNIT);
851865
}
852866
self.word("}");
@@ -855,9 +869,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
855869
}
856870
}
857871

858-
fn bclose(&mut self, span: rustc_span::Span, empty: bool, cb: BoxMarker) {
872+
fn bclose(&mut self, span: rustc_span::Span, no_space: bool, cb: BoxMarker) {
859873
let cb = Some(cb);
860-
self.bclose_maybe_open(span, empty, cb)
874+
self.bclose_maybe_open(span, no_space, cb)
861875
}
862876

863877
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
@@ -1434,8 +1448,8 @@ impl<'a> State<'a> {
14341448
}
14351449
}
14361450

1437-
let empty = !has_attrs && blk.stmts.is_empty();
1438-
self.bclose_maybe_open(blk.span, empty, cb);
1451+
let no_space = !has_attrs && blk.stmts.is_empty();
1452+
self.bclose_maybe_open(blk.span, no_space, cb);
14391453
self.ann.post(self, AnnNode::Block(blk))
14401454
}
14411455

@@ -1482,6 +1496,7 @@ impl<'a> State<'a> {
14821496
true,
14831497
None,
14841498
m.args.delim,
1499+
None,
14851500
&m.args.tokens,
14861501
true,
14871502
m.span(),

compiler/rustc_builtin_macros/src/autodiff.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ mod llvm_enzyme {
323323
Spacing::Joint,
324324
)];
325325
let never_arg = ast::DelimArgs {
326-
dspan: ast::tokenstream::DelimSpan::from_single(span),
326+
dspan: DelimSpan::from_single(span),
327327
delim: ast::token::Delimiter::Parenthesis,
328-
tokens: ast::tokenstream::TokenStream::from_iter(ts2),
328+
tokens: TokenStream::from_iter(ts2),
329329
};
330330
let inline_item = ast::AttrItem {
331331
unsafety: ast::Safety::Default,

compiler/rustc_codegen_cranelift/src/base.rs

+2-37
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use rustc_ast::InlineAsmOptions;
88
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
99
use rustc_data_structures::profiling::SelfProfilerRef;
1010
use rustc_index::IndexVec;
11-
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
12-
use rustc_middle::mir::InlineAsmMacro;
1311
use rustc_middle::ty::TypeVisitableExt;
1412
use rustc_middle::ty::adjustment::PointerCoercion;
1513
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
@@ -18,7 +16,6 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1816
use crate::constant::ConstantCx;
1917
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
2018
use crate::enable_verifier;
21-
use crate::inline_asm::codegen_naked_asm;
2219
use crate::prelude::*;
2320
use crate::pretty_clif::CommentWriter;
2421

@@ -37,7 +34,7 @@ pub(crate) fn codegen_fn<'tcx>(
3734
cached_func: Function,
3835
module: &mut dyn Module,
3936
instance: Instance<'tcx>,
40-
) -> Option<CodegenedFunction> {
37+
) -> CodegenedFunction {
4138
debug_assert!(!instance.args.has_infer());
4239

4340
let symbol_name = tcx.symbol_name(instance).name.to_string();
@@ -54,38 +51,6 @@ pub(crate) fn codegen_fn<'tcx>(
5451
String::from_utf8_lossy(&buf).into_owned()
5552
});
5653

57-
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
58-
assert_eq!(mir.basic_blocks.len(), 1);
59-
assert!(mir.basic_blocks[START_BLOCK].statements.is_empty());
60-
61-
match &mir.basic_blocks[START_BLOCK].terminator().kind {
62-
TerminatorKind::InlineAsm {
63-
asm_macro: InlineAsmMacro::NakedAsm,
64-
template,
65-
operands,
66-
options,
67-
line_spans: _,
68-
targets: _,
69-
unwind: _,
70-
} => {
71-
codegen_naked_asm(
72-
tcx,
73-
cx,
74-
module,
75-
instance,
76-
mir.basic_blocks[START_BLOCK].terminator().source_info.span,
77-
&symbol_name,
78-
template,
79-
operands,
80-
*options,
81-
);
82-
}
83-
_ => unreachable!(),
84-
}
85-
86-
return None;
87-
}
88-
8954
// Declare function
9055
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
9156
let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap();
@@ -166,7 +131,7 @@ pub(crate) fn codegen_fn<'tcx>(
166131
// Verify function
167132
verify_func(tcx, &clif_comments, &func);
168133

169-
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
134+
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
170135
}
171136

172137
pub(crate) fn compile_fn(

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+32-10
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
2222
use rustc_metadata::EncodedMetadata;
2323
use rustc_metadata::fs::copy_to_stdout;
2424
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
25-
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
25+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
26+
use rustc_middle::mir::mono::{
27+
CodegenUnit, Linkage as RLinkage, MonoItem, MonoItemData, Visibility,
28+
};
2629
use rustc_session::Session;
2730
use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType};
2831

2932
use crate::CodegenCx;
3033
use crate::base::CodegenedFunction;
3134
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
3235
use crate::debuginfo::TypeDebugContext;
33-
use crate::global_asm::GlobalAsmConfig;
36+
use crate::global_asm::{GlobalAsmConfig, GlobalAsmContext};
3437
use crate::prelude::*;
3538
use crate::unwind_module::UnwindModule;
3639

@@ -530,19 +533,35 @@ fn codegen_cgu_content(
530533
let mut type_dbg = TypeDebugContext::default();
531534
super::predefine_mono_items(tcx, module, &mono_items);
532535
let mut codegened_functions = vec![];
533-
for (mono_item, _) in mono_items {
536+
for (mono_item, item_data) in mono_items {
534537
match mono_item {
535-
MonoItem::Fn(inst) => {
536-
if let Some(codegened_function) = crate::base::codegen_fn(
538+
MonoItem::Fn(instance) => {
539+
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED)
540+
{
541+
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
542+
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
543+
instance,
544+
MonoItemData {
545+
linkage: RLinkage::External,
546+
visibility: if item_data.linkage == RLinkage::Internal {
547+
Visibility::Hidden
548+
} else {
549+
item_data.visibility
550+
},
551+
..item_data
552+
},
553+
);
554+
continue;
555+
}
556+
let codegened_function = crate::base::codegen_fn(
537557
tcx,
538558
&mut cx,
539559
&mut type_dbg,
540560
Function::new(),
541561
module,
542-
inst,
543-
) {
544-
codegened_functions.push(codegened_function);
545-
}
562+
instance,
563+
);
564+
codegened_functions.push(codegened_function);
546565
}
547566
MonoItem::Static(def_id) => {
548567
let data_id = crate::constant::codegen_static(tcx, module, def_id);
@@ -551,7 +570,10 @@ fn codegen_cgu_content(
551570
}
552571
}
553572
MonoItem::GlobalAsm(item_id) => {
554-
crate::global_asm::codegen_global_asm_item(tcx, &mut cx.global_asm, item_id);
573+
rustc_codegen_ssa::base::codegen_global_asm(
574+
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
575+
item_id,
576+
);
555577
}
556578
}
557579
}

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
126126
module: &mut dyn Module,
127127
instance: Instance<'tcx>,
128128
) {
129+
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
130+
tcx.dcx()
131+
.span_fatal(tcx.def_span(instance.def_id()), "Naked asm is not supported in JIT mode");
132+
}
133+
129134
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
130135
tcx.prof.clone(),
131136
)));
@@ -135,16 +140,15 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
135140
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
136141

137142
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
138-
if let Some(codegened_func) = crate::base::codegen_fn(
143+
let codegened_func = crate::base::codegen_fn(
139144
tcx,
140145
cx,
141146
&mut TypeDebugContext::default(),
142147
cached_func,
143148
module,
144149
instance,
145-
) {
146-
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
147-
}
150+
);
151+
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
148152
});
149153
}
150154

0 commit comments

Comments
 (0)