Skip to content

Commit 176780e

Browse files
committed
Auto merge of #156397 - JonathanBrouwer:rollup-JwcK6An, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - #155679 (rustdoc: Reify emission types) - #155982 (Fix closure HIR span context mismatch) - #156323 (Handle --print=backend-has-mnemonic in cg_clif) - #156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`) - #156365 (stream_send_recv_stress tests: wait for threads to finish) - #156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
2 parents 99eed20 + d33589d commit 176780e

29 files changed

Lines changed: 488 additions & 363 deletions

File tree

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ impl CodegenBackend for CraneliftCodegenBackend {
200200
println!("Cranelift version: {}", cranelift_codegen::VERSION);
201201
}
202202

203+
fn has_mnemonic(&self, sess: &Session, mnemonic: &str) -> bool {
204+
// All Cranelift supported targets support ret except for s390x
205+
mnemonic == "ret" && sess.target.arch != Arch::S390x
206+
}
207+
203208
fn target_cpu(&self, sess: &Session) -> String {
204209
// FIXME handle `-Ctarget-cpu=native`
205210
match sess.opts.cg.target_cpu {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ impl CodegenBackend for LlvmCodegenBackend {
314314
llvm::LLVMRustLLVMHasZstdCompression()
315315
}
316316

317+
fn has_mnemonic(&self, sess: &Session, mnemonic: &str) -> bool {
318+
llvm_util::target_has_mnemonic(sess, mnemonic)
319+
}
320+
317321
fn target_config(&self, sess: &Session) -> TargetConfig {
318322
target_config(sess)
319323
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,6 @@ pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) {
480480
match req.kind {
481481
PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out),
482482
PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out),
483-
PrintKind::BackendHasMnemonic => {
484-
let mnemonic = req.arg.as_deref().expect("BackendHasMnemonic requires arg");
485-
print_target_has_mnemonic(tm.raw(), mnemonic, out)
486-
}
487483
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
488484
}
489485
}
@@ -746,9 +742,9 @@ pub(crate) fn tune_cpu(sess: &Session) -> Option<&str> {
746742
Some(handle_native(name))
747743
}
748744

749-
fn print_target_has_mnemonic(tm: &llvm::TargetMachine, mnemonic: &str, out: &mut String) {
750-
use std::fmt::Write;
745+
pub(crate) fn target_has_mnemonic(sess: &Session, mnemonic: &str) -> bool {
746+
require_inited();
747+
let tm = create_informational_target_machine(sess, false);
751748
let cstr = SmallCStr::new(mnemonic);
752-
let has_mnemonic = unsafe { llvm::LLVMRustTargetHasMnemonic(tm, cstr.as_ptr()) };
753-
writeln!(out, "{}", has_mnemonic).unwrap();
749+
unsafe { llvm::LLVMRustTargetHasMnemonic(tm.raw(), cstr.as_ptr()) }
754750
}

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ pub trait CodegenBackend {
9292
false
9393
}
9494

95+
/// Value printed by `--print=backend-has-mnemonic:...`.
96+
///
97+
/// Used by compiletest to determine whether tests involving `asm!()` should
98+
/// be executed or skipped.
99+
fn has_mnemonic(&self, _sess: &Session, _mnemonic: &str) -> bool {
100+
false
101+
}
102+
95103
/// The metadata loader used to load rlib and dylib metadata.
96104
///
97105
/// Alternative codegen backends may want to use different rlib or dylib formats than the

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ fn print_crate_info(
802802
println_info!("{}", calling_conventions.join("\n"));
803803
}
804804
BackendHasMnemonic => {
805-
codegen_backend.print(req, &mut crate_info, sess);
805+
let has_mnemonic: bool =
806+
codegen_backend.has_mnemonic(sess, req.arg.as_ref().unwrap());
807+
println_info!("{has_mnemonic}");
806808
}
807809
BackendHasZstd => {
808810
let has_zstd: bool = codegen_backend.has_zstd();

compiler/rustc_middle/src/hir/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ impl<'tcx> TyCtxt<'tcx> {
980980
span,
981981
..
982982
}) => {
983-
// Ensure that the returned span has the item's SyntaxContext.
984-
fn_decl_span.find_ancestor_inside(*span).unwrap_or(*span)
983+
// Ensure that the returned span has the closure expression's SyntaxContext.
984+
fn_decl_span.find_ancestor_inside_same_ctxt(*span).unwrap_or(*span)
985985
}
986986
_ => self.hir_span_with_body(hir_id),
987987
};

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,8 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
363363
| UpvarRef { .. }
364364
| VarRef { .. }
365365
| ZstLiteral { .. }
366-
| Yield { .. } => true,
367-
ExprKind::Reborrow { .. } => {
368-
// FIXME(reborrow): matching on a Reborrow expression should be impossible
369-
// currently. Whether this remains to be true, and if the reborrow result then is a
370-
// known valid scrutinee requires further thought.
371-
unreachable!("Reborrow expression in match")
372-
}
366+
| Yield { .. }
367+
| Reborrow { .. } => true,
373368
}
374369
}
375370

library/std/tests/sync/mpmc.rs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -419,34 +419,48 @@ fn oneshot_multi_thread_send_recv_stress() {
419419

420420
#[test]
421421
fn stream_send_recv_stress() {
422-
for _ in 0..stress_factor() {
423-
let (tx, rx) = channel();
424-
425-
send(tx, 0);
426-
recv(rx, 0);
422+
thread::scope(|s| {
423+
for _ in 0..stress_factor() {
424+
let (tx, rx) = channel();
425+
426+
send(tx, 0, s);
427+
recv(rx, 0, s);
428+
429+
fn send<'scope, 'env>(
430+
tx: Sender<Box<i32>>,
431+
i: i32,
432+
s: &'scope thread::Scope<'scope, 'env>,
433+
) where
434+
'env: 'scope,
435+
{
436+
if i == 10 {
437+
return;
438+
}
427439

428-
fn send(tx: Sender<Box<i32>>, i: i32) {
429-
if i == 10 {
430-
return;
440+
s.spawn(move || {
441+
tx.send(Box::new(i)).unwrap();
442+
send(tx, i + 1, s);
443+
});
431444
}
432445

433-
thread::spawn(move || {
434-
tx.send(Box::new(i)).unwrap();
435-
send(tx, i + 1);
436-
});
437-
}
446+
fn recv<'scope, 'env>(
447+
rx: Receiver<Box<i32>>,
448+
i: i32,
449+
s: &'scope thread::Scope<'scope, 'env>,
450+
) where
451+
'env: 'scope,
452+
{
453+
if i == 10 {
454+
return;
455+
}
438456

439-
fn recv(rx: Receiver<Box<i32>>, i: i32) {
440-
if i == 10 {
441-
return;
457+
s.spawn(move || {
458+
assert!(*rx.recv().unwrap() == i);
459+
recv(rx, i + 1, s);
460+
});
442461
}
443-
444-
thread::spawn(move || {
445-
assert!(*rx.recv().unwrap() == i);
446-
recv(rx, i + 1);
447-
});
448462
}
449-
}
463+
})
450464
}
451465

452466
#[test]

library/std/tests/sync/mpsc.rs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -382,34 +382,48 @@ fn oneshot_multi_thread_send_recv_stress() {
382382

383383
#[test]
384384
fn stream_send_recv_stress() {
385-
for _ in 0..stress_factor() {
386-
let (tx, rx) = channel();
387-
388-
send(tx, 0);
389-
recv(rx, 0);
385+
thread::scope(|s| {
386+
for _ in 0..stress_factor() {
387+
let (tx, rx) = channel();
388+
389+
send(tx, 0, s);
390+
recv(rx, 0, s);
391+
392+
fn send<'scope, 'env>(
393+
tx: Sender<Box<i32>>,
394+
i: i32,
395+
s: &'scope thread::Scope<'scope, 'env>,
396+
) where
397+
'env: 'scope,
398+
{
399+
if i == 10 {
400+
return;
401+
}
390402

391-
fn send(tx: Sender<Box<i32>>, i: i32) {
392-
if i == 10 {
393-
return;
403+
s.spawn(move || {
404+
tx.send(Box::new(i)).unwrap();
405+
send(tx, i + 1, s);
406+
});
394407
}
395408

396-
thread::spawn(move || {
397-
tx.send(Box::new(i)).unwrap();
398-
send(tx, i + 1);
399-
});
400-
}
409+
fn recv<'scope, 'env>(
410+
rx: Receiver<Box<i32>>,
411+
i: i32,
412+
s: &'scope thread::Scope<'scope, 'env>,
413+
) where
414+
'env: 'scope,
415+
{
416+
if i == 10 {
417+
return;
418+
}
401419

402-
fn recv(rx: Receiver<Box<i32>>, i: i32) {
403-
if i == 10 {
404-
return;
420+
s.spawn(move || {
421+
assert!(*rx.recv().unwrap() == i);
422+
recv(rx, i + 1, s);
423+
});
405424
}
406-
407-
thread::spawn(move || {
408-
assert!(*rx.recv().unwrap() == i);
409-
recv(rx, i + 1);
410-
});
411425
}
412-
}
426+
})
413427
}
414428

415429
#[test]

src/librustdoc/config.rs

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_session::{EarlyDiagCtxt, getopts};
1818
use rustc_span::edition::Edition;
1919
use rustc_span::{FileName, RemapPathScopeComponents};
2020
use rustc_target::spec::TargetTuple;
21+
use smallvec::SmallVec;
2122

2223
use crate::core::new_dcx;
2324
use crate::externalfiles::ExternalHtml;
@@ -293,7 +294,7 @@ pub(crate) struct RenderOptions {
293294
/// Note: this field is duplicated in `Options` because it's useful to have
294295
/// it in both places.
295296
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
296-
pub(crate) emit: Vec<EmitType>,
297+
pub(crate) emit: SmallVec<[EmitType; 2]>,
297298
/// If `true`, HTML source pages will generate links for items to their definition.
298299
pub(crate) generate_link_to_definition: bool,
299300
/// Set of function-call locations to include as examples
@@ -327,9 +328,22 @@ pub(crate) enum ModuleSorting {
327328
pub(crate) enum EmitType {
328329
HtmlStaticFiles,
329330
HtmlNonStaticFiles,
331+
// not explicitly nameable by the user for now
332+
JsonFiles,
330333
DepInfo(Option<OutFileName>),
331334
}
332335

336+
impl fmt::Display for EmitType {
337+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
338+
f.write_str(match self {
339+
Self::HtmlStaticFiles => "html-static-files",
340+
Self::HtmlNonStaticFiles => "html-non-static-files",
341+
Self::JsonFiles => "json-files",
342+
Self::DepInfo(_) => "dep-info",
343+
})
344+
}
345+
}
346+
333347
impl FromStr for EmitType {
334348
type Err = ();
335349

@@ -352,17 +366,11 @@ impl FromStr for EmitType {
352366
}
353367

354368
impl RenderOptions {
355-
pub(crate) fn should_emit_crate(&self) -> bool {
356-
self.emit.is_empty() || self.emit.contains(&EmitType::HtmlNonStaticFiles)
357-
}
358-
359369
pub(crate) fn dep_info(&self) -> Option<Option<&OutFileName>> {
360-
for emit in &self.emit {
361-
if let EmitType::DepInfo(file) = emit {
362-
return Some(file.as_ref());
363-
}
364-
}
365-
None
370+
self.emit.iter().find_map(|emit| match emit {
371+
EmitType::DepInfo(file) => Some(file.as_ref()),
372+
_ => None,
373+
})
366374
}
367375
}
368376

@@ -469,26 +477,6 @@ impl Options {
469477

470478
let should_test = matches.opt_present("test");
471479

472-
let mut emit = FxIndexMap::<_, EmitType>::default();
473-
for list in matches.opt_strs("emit") {
474-
if should_test {
475-
dcx.fatal("the `--test` flag and the `--emit` flag are not supported together");
476-
}
477-
for kind in list.split(',') {
478-
match kind.parse() {
479-
Ok(kind) => {
480-
// De-duplicate emit types and the last wins.
481-
// Only one instance for each type is allowed
482-
// regardless the actual data it carries.
483-
// This matches rustc's `--emit` behavior.
484-
emit.insert(std::mem::discriminant(&kind), kind);
485-
}
486-
Err(()) => dcx.fatal(format!("unrecognized emission type: {kind}")),
487-
}
488-
}
489-
}
490-
let emit = emit.into_values().collect::<Vec<_>>();
491-
492480
let show_coverage = matches.opt_present("show-coverage");
493481
let output_format_s = matches.opt_str("output-format");
494482
let output_format = match output_format_s {
@@ -527,15 +515,55 @@ impl Options {
527515
}
528516
}
529517

530-
if output_format == OutputFormat::Json {
531-
if let Some(emit_flag) = emit.iter().find_map(|emit| match emit {
532-
EmitType::HtmlStaticFiles => Some("html-static-files"),
533-
EmitType::HtmlNonStaticFiles => Some("html-non-static-files"),
534-
EmitType::DepInfo(_) => None,
535-
}) {
536-
dcx.fatal(format!(
537-
"the `--emit={emit_flag}` flag is not supported with `--output-format=json`",
538-
));
518+
let mut emit = FxIndexMap::default();
519+
for list in matches.opt_strs("emit") {
520+
if should_test {
521+
dcx.fatal("the `--test` flag and the `--emit` flag are not supported together");
522+
}
523+
if let OutputFormat::Doctest = output_format {
524+
dcx.fatal("the `--emit` flag is not supported with `--output-format=doctest`");
525+
}
526+
527+
for typ in list.split(',') {
528+
let Ok(typ) = typ.parse::<EmitType>() else {
529+
dcx.fatal(format!("unrecognized emission type: {typ}"))
530+
};
531+
532+
match typ {
533+
EmitType::DepInfo(_) => match output_format {
534+
OutputFormat::Json | OutputFormat::Html => {}
535+
OutputFormat::Doctest => unreachable!(),
536+
},
537+
EmitType::HtmlStaticFiles | EmitType::HtmlNonStaticFiles => match output_format
538+
{
539+
OutputFormat::Html => {}
540+
OutputFormat::Json => dcx.fatal(format!(
541+
"the `--emit={typ}` flag is not supported with `--output-format=json`",
542+
)),
543+
OutputFormat::Doctest => unreachable!(),
544+
},
545+
EmitType::JsonFiles => unreachable!(),
546+
}
547+
548+
// De-duplicate emit types and the last wins.
549+
// Only one instance for each type is allowed
550+
// regardless the actual data it carries.
551+
// This matches rustc's `--emit` behavior.
552+
emit.insert(std::mem::discriminant(&typ), typ);
553+
}
554+
}
555+
let mut emit: SmallVec<[_; 2]> = emit.into_values().collect();
556+
// If `--emit` is absent we'll register default emission types depending on the requested
557+
// output format. We can safely use `is_empty` for this since `--emit=` ("truly empty")
558+
// will have already been rejected above.
559+
if emit.is_empty() {
560+
match output_format {
561+
OutputFormat::Json => emit.push(EmitType::JsonFiles),
562+
OutputFormat::Html => {
563+
emit.push(EmitType::HtmlStaticFiles);
564+
emit.push(EmitType::HtmlNonStaticFiles);
565+
}
566+
OutputFormat::Doctest => {}
539567
}
540568
}
541569

0 commit comments

Comments
 (0)