Skip to content

Rollup of 8 pull requests #140475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
14491b0
Use START_BLOCK in codegen_naked_asm
bjorn3 Dec 12, 2024
03f4e88
Handle protected visibility in codegen_naked_asm
bjorn3 Dec 12, 2024
ffdc292
Don't begin defining a function when codegening a naked function
bjorn3 Dec 12, 2024
1988de5
Only require a CodegenCx for codegen_naked_asm
bjorn3 Dec 12, 2024
764d3a5
Make codegen_naked_asm retrieve the MIR Body itself
bjorn3 Dec 12, 2024
a73eba9
Move codegen_naked_asm call up into MonoItem::define
bjorn3 Dec 12, 2024
e2e96fa
Pass MonoItemData to MonoItem::define
bjorn3 Dec 12, 2024
94e95f3
Make codegen_naked_asm public
bjorn3 Dec 12, 2024
421f22e
Pass &mut self to codegen_global_asm
bjorn3 Dec 12, 2024
f5c93fa
Use cg_ssa's version of codegen_naked_asm in cg_clif
bjorn3 Dec 12, 2024
3066da8
Share part of the global_asm!() implementation between cg_ssa and cg_…
bjorn3 Dec 13, 2024
5b1e495
Add a few extra tests to `tests/ui/macros/stringify.rs`.
nnethercote Apr 23, 2025
99f6b63
Improve pretty-printing of braces.
nnethercote May 17, 2024
cf12e29
enable msa feature for mips in codegen tests
koalatux Apr 29, 2025
4fe94ba
add `rust.debug-assertions-tools` option
pietroalbini Apr 29, 2025
2393e44
miri: algebraic intrinsics: bring back float non-determinism
RalfJung Apr 29, 2025
478b378
Move `on impl position` test to proper directory
mejrs Apr 29, 2025
fc2cd77
Fix comment describing what the test does
mejrs Apr 29, 2025
923ca85
Add test
oli-obk Apr 29, 2025
a1c7059
Treat `ManuallyDrop` as `~const Destruct`
oli-obk Apr 29, 2025
a4ce307
Coalesce duplicate missing clone tests
mejrs Apr 29, 2025
64bcf3b
Rename `rustc_query_append!` to `rustc_with_all_queries!`
Zalathar Apr 29, 2025
ed2f4b6
Reformat parameters to macros used by with-all-queries
Zalathar Apr 29, 2025
40ebd1b
Rollup merge of #134232 - bjorn3:naked_asm_improvements, r=wesleywiser
tgross35 Apr 29, 2025
3e26eb9
Rollup merge of #140312 - nnethercote:DelimArgs-spacing, r=petrochenkov
tgross35 Apr 29, 2025
f241cb1
Rollup merge of #140437 - husqvarnagroup:af/codegen-test-mips-msa, r=…
tgross35 Apr 29, 2025
3ef052f
Rollup merge of #140438 - ferrocene:pa-debug-assertions-tools, r=Kobzol
tgross35 Apr 29, 2025
8719830
Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli…
tgross35 Apr 29, 2025
59613f5
Rollup merge of #140445 - oli-obk:const-manually-drop, r=fee1-dead
tgross35 Apr 29, 2025
ef36ca5
Rollup merge of #140446 - mejrs:test1, r=jieyouxu
tgross35 Apr 29, 2025
9529cc4
Rollup merge of #140448 - Zalathar:query-append, r=compiler-errors
tgross35 Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@
# Defaults to rust.debug-assertions value
#debug-assertions-std = rust.debug-assertions (boolean)

# Whether or not debug assertions are enabled for the tools built by bootstrap.
# Overrides the `debug-assertions` option, if defined.
#
# Defaults to rust.debug-assertions value
#debug-assertions-tools = rust.debug-assertions (boolean)

# Whether or not to leave debug! and trace! calls in the rust binary.
#
# Defaults to rust.debug-assertions value
Expand Down
33 changes: 24 additions & 9 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
false,
None,
*delim,
None,
tokens,
true,
span,
Expand Down Expand Up @@ -679,6 +680,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
false,
None,
*delim,
Some(spacing.open),
tts,
convert_dollar_crate,
dspan.entire(),
Expand Down Expand Up @@ -735,6 +737,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
has_bang: bool,
ident: Option<Ident>,
delim: Delimiter,
open_spacing: Option<Spacing>,
tts: &TokenStream,
convert_dollar_crate: bool,
span: Span,
Expand All @@ -758,16 +761,26 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.nbsp();
}
self.word("{");
if !tts.is_empty() {

// Respect `Alone`, if provided, and print a space. Unless the list is empty.
let open_space = (open_spacing == None || open_spacing == Some(Spacing::Alone))
&& !tts.is_empty();
if open_space {
self.space();
}
let ib = self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end(ib);
let empty = tts.is_empty();
self.bclose(span, empty, cb.unwrap());

// Use `open_space` for the spacing *before* the closing delim.
// Because spacing on delimiters is lost when going through
// proc macros, and otherwise we can end up with ugly cases
// like `{ x}`. Symmetry is better.
self.bclose(span, !open_space, cb.unwrap());
}
delim => {
// `open_spacing` is ignored. We never print spaces after
// non-brace opening delims or before non-brace closing delims.
let token_str = self.token_kind_to_string(&delim.as_open_token_kind());
self.word(token_str);
let ib = self.ibox(0);
Expand Down Expand Up @@ -797,6 +810,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
has_bang,
Some(*ident),
macro_def.body.delim,
None,
&macro_def.body.tokens,
true,
sp,
Expand Down Expand Up @@ -844,9 +858,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.end(ib);
}

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

fn bclose(&mut self, span: rustc_span::Span, empty: bool, cb: BoxMarker) {
fn bclose(&mut self, span: rustc_span::Span, no_space: bool, cb: BoxMarker) {
let cb = Some(cb);
self.bclose_maybe_open(span, empty, cb)
self.bclose_maybe_open(span, no_space, cb)
}

fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
Expand Down Expand Up @@ -1423,8 +1437,8 @@ impl<'a> State<'a> {
}
}

let empty = !has_attrs && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, empty, cb);
let no_space = !has_attrs && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, no_space, cb);
self.ann.post(self, AnnNode::Block(blk))
}

Expand Down Expand Up @@ -1471,6 +1485,7 @@ impl<'a> State<'a> {
true,
None,
m.args.delim,
None,
&m.args.tokens,
true,
m.span(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ mod llvm_enzyme {
Spacing::Joint,
)];
let never_arg = ast::DelimArgs {
dspan: ast::tokenstream::DelimSpan::from_single(span),
dspan: DelimSpan::from_single(span),
delim: ast::token::Delimiter::Parenthesis,
tokens: ast::tokenstream::TokenStream::from_iter(ts2),
tokens: TokenStream::from_iter(ts2),
};
let inline_item = ast::AttrItem {
unsafety: ast::Safety::Default,
Expand Down
39 changes: 2 additions & 37 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use rustc_ast::InlineAsmOptions;
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::InlineAsmMacro;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
Expand All @@ -18,7 +16,6 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
use crate::constant::ConstantCx;
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
use crate::enable_verifier;
use crate::inline_asm::codegen_naked_asm;
use crate::prelude::*;
use crate::pretty_clif::CommentWriter;

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

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

if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
assert_eq!(mir.basic_blocks.len(), 1);
assert!(mir.basic_blocks[START_BLOCK].statements.is_empty());

match &mir.basic_blocks[START_BLOCK].terminator().kind {
TerminatorKind::InlineAsm {
asm_macro: InlineAsmMacro::NakedAsm,
template,
operands,
options,
line_spans: _,
targets: _,
unwind: _,
} => {
codegen_naked_asm(
tcx,
cx,
module,
instance,
mir.basic_blocks[START_BLOCK].terminator().source_info.span,
&symbol_name,
template,
operands,
*options,
);
}
_ => unreachable!(),
}

return None;
}

// Declare function
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap();
Expand Down Expand Up @@ -166,7 +131,7 @@ pub(crate) fn codegen_fn<'tcx>(
// Verify function
verify_func(tcx, &clif_comments, &func);

Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
}

pub(crate) fn compile_fn(
Expand Down
42 changes: 32 additions & 10 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
use rustc_metadata::EncodedMetadata;
use rustc_metadata::fs::copy_to_stdout;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{
CodegenUnit, Linkage as RLinkage, MonoItem, MonoItemData, Visibility,
};
use rustc_session::Session;
use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType};

use crate::CodegenCx;
use crate::base::CodegenedFunction;
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
use crate::debuginfo::TypeDebugContext;
use crate::global_asm::GlobalAsmConfig;
use crate::global_asm::{GlobalAsmConfig, GlobalAsmContext};
use crate::prelude::*;
use crate::unwind_module::UnwindModule;

Expand Down Expand Up @@ -530,19 +533,35 @@ fn codegen_cgu_content(
let mut type_dbg = TypeDebugContext::default();
super::predefine_mono_items(tcx, module, &mono_items);
let mut codegened_functions = vec![];
for (mono_item, _) in mono_items {
for (mono_item, item_data) in mono_items {
match mono_item {
MonoItem::Fn(inst) => {
if let Some(codegened_function) = crate::base::codegen_fn(
MonoItem::Fn(instance) => {
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED)
{
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
instance,
MonoItemData {
linkage: RLinkage::External,
visibility: if item_data.linkage == RLinkage::Internal {
Visibility::Hidden
} else {
item_data.visibility
},
..item_data
},
);
continue;
}
let codegened_function = crate::base::codegen_fn(
tcx,
&mut cx,
&mut type_dbg,
Function::new(),
module,
inst,
) {
codegened_functions.push(codegened_function);
}
instance,
);
codegened_functions.push(codegened_function);
}
MonoItem::Static(def_id) => {
let data_id = crate::constant::codegen_static(tcx, module, def_id);
Expand All @@ -551,7 +570,10 @@ fn codegen_cgu_content(
}
}
MonoItem::GlobalAsm(item_id) => {
crate::global_asm::codegen_global_asm_item(tcx, &mut cx.global_asm, item_id);
rustc_codegen_ssa::base::codegen_global_asm(
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
item_id,
);
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
module: &mut dyn Module,
instance: Instance<'tcx>,
) {
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
tcx.dcx()
.span_fatal(tcx.def_span(instance.def_id()), "Naked asm is not supported in JIT mode");
}

cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
tcx.prof.clone(),
)));
Expand All @@ -135,16 +140,15 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));

let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
if let Some(codegened_func) = crate::base::codegen_fn(
let codegened_func = crate::base::codegen_fn(
tcx,
cx,
&mut TypeDebugContext::default(),
cached_func,
module,
instance,
) {
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
}
);
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
});
}

Expand Down
Loading
Loading