Skip to content

Rollup of 7 pull requests #113885

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 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c67aea7
rustdoc: fix position of `default` in method rendering
wackbyte Apr 24, 2023
13f58a8
Add tests for default unsafe trait methods
wackbyte Jun 23, 2023
85a98b0
Add test of --print KIND=PATH
dtolnay Apr 25, 2023
2f01742
Store individual output file name with every PrintRequest
dtolnay Jul 17, 2023
6dbe5bc
Parse --print KIND=PATH command line syntax
dtolnay Jul 17, 2023
927a4d6
Disallow overlapping prints to the same location
dtolnay Jul 17, 2023
11a2b0b
Move OutFileName writing into rustc_session
dtolnay Jul 17, 2023
be9881a
Implement printing to file in print_crate_info
dtolnay Jul 17, 2023
74b24f3
Implement printing to file in codegen_backend.print
dtolnay Jul 17, 2023
7ea1d4c
Implement printing to file in llvm_util
dtolnay Jul 13, 2023
e8cd8c6
Implement printing to file in PassWrapper
dtolnay Jul 13, 2023
8d21674
Implement printing to file for link-args and native-static-libs
dtolnay Jul 17, 2023
5d84459
Add ui test of LLVM print-from-C++ changes
dtolnay Jul 14, 2023
4f5242e
Document --print KIND=PATH in Command-line Arguments documentation
dtolnay Jul 17, 2023
9e5a67e
Permit pre-evaluated constants in simd_shuffle
oli-obk Jul 10, 2023
9b32319
Add Foreign to SMIR
spastorino Jul 18, 2023
caa01ad
Add Never to SMIR
spastorino Jul 18, 2023
68077d5
Rename SMIR AdtSubsts to GenericArgs
spastorino Jul 18, 2023
e5c0b96
Add FnDef ty to SMIR
spastorino Jul 18, 2023
c5c38cd
Add Closure ty to SMIR
spastorino Jul 18, 2023
ed32347
Add Generator to SMIR
spastorino Jul 18, 2023
db35f1d
Extract generic_args function
spastorino Jul 19, 2023
c5819b2
Remove FIXMEs a lot of things need fixes
spastorino Jul 19, 2023
705e3e3
Add note about writing native-static-libs to file
dtolnay Jul 19, 2023
4d5134f
Create separate match arms for FileNames and CrateNames
dtolnay Jul 19, 2023
2009b4a
Remove adjustments that used to be necessary for search's crate selec…
steffahn Jul 20, 2023
c7428d5
Monomorphize constants before inspecting them
oli-obk Jul 20, 2023
fdaec57
XSimplifiedType to SimplifiedType::X
lcnr Jul 18, 2023
2d99f40
assembly: only consider blanket impls once
lcnr Jul 18, 2023
aa28b77
add FIXME
lcnr Jul 18, 2023
7c97a76
re-add comment
lcnr Jul 18, 2023
7de9b65
Avoid another gha group nesting
oli-obk Jul 17, 2023
2062f2c
review
lcnr Jul 20, 2023
5c75bc5
update doc comments
lcnr Jul 20, 2023
0959d5a
Rollup merge of #110765 - wackbyte:fix-defaultness-position, r=fmease…
matthiaskrgr Jul 20, 2023
8f7b890
Rollup merge of #113529 - oli-obk:simd_shuffle_evaluated, r=wesleywiser
matthiaskrgr Jul 20, 2023
be32e34
Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber
matthiaskrgr Jul 20, 2023
4497c9b
Rollup merge of #113800 - oli-obk:gha_ci_cycle, r=jyn514
matthiaskrgr Jul 20, 2023
c9bb194
Rollup merge of #113827 - spastorino:smir-types-4, r=oli-obk
matthiaskrgr Jul 20, 2023
d544734
Rollup merge of #113835 - lcnr:assemble-candidates-considering-self-t…
matthiaskrgr Jul 20, 2023
0de39bf
Rollup merge of #113883 - steffahn:rustdoc-search-crate-selector-padd…
matthiaskrgr Jul 20, 2023
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
37 changes: 19 additions & 18 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest};
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_session::Session;
use rustc_span::symbol::Symbol;

Expand Down Expand Up @@ -262,10 +262,10 @@ impl CodegenBackend for LlvmCodegenBackend {
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
}

fn print(&self, req: PrintRequest, sess: &Session) {
match req {
PrintRequest::RelocationModels => {
println!("Available relocation models:");
fn print(&self, req: &PrintRequest, out: &mut dyn PrintBackendInfo, sess: &Session) {
match req.kind {
PrintKind::RelocationModels => {
writeln!(out, "Available relocation models:");
for name in &[
"static",
"pic",
Expand All @@ -276,26 +276,27 @@ impl CodegenBackend for LlvmCodegenBackend {
"ropi-rwpi",
"default",
] {
println!(" {}", name);
writeln!(out, " {}", name);
}
println!();
writeln!(out);
}
PrintRequest::CodeModels => {
println!("Available code models:");
PrintKind::CodeModels => {
writeln!(out, "Available code models:");
for name in &["tiny", "small", "kernel", "medium", "large"] {
println!(" {}", name);
writeln!(out, " {}", name);
}
println!();
writeln!(out);
}
PrintRequest::TlsModels => {
println!("Available TLS models:");
PrintKind::TlsModels => {
writeln!(out, "Available TLS models:");
for name in &["global-dynamic", "local-dynamic", "initial-exec", "local-exec"] {
println!(" {}", name);
writeln!(out, " {}", name);
}
println!();
writeln!(out);
}
PrintRequest::StackProtectorStrategies => {
println!(
PrintKind::StackProtectorStrategies => {
writeln!(
out,
r#"Available stack protector strategies:
all
Generate stack canaries in all functions.
Expand All @@ -319,7 +320,7 @@ impl CodegenBackend for LlvmCodegenBackend {
"#
);
}
req => llvm_util::print(req, sess),
_other => llvm_util::print(req, out, sess),
}
}

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,12 @@ extern "C" {

pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;

pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine, cpu: *const c_char);
pub fn LLVMRustPrintTargetCPUs(
T: &TargetMachine,
cpu: *const c_char,
print: unsafe extern "C" fn(out: *mut c_void, string: *const c_char, len: usize),
out: *mut c_void,
);
pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
pub fn LLVMRustGetTargetFeature(
T: &TargetMachine,
Expand Down
47 changes: 30 additions & 17 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ use libc::c_int;
use rustc_codegen_ssa::target_features::{
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
};
use rustc_codegen_ssa::traits::PrintBackendInfo;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_fs_util::path_to_c_string;
use rustc_middle::bug;
use rustc_session::config::PrintRequest;
use rustc_session::config::{PrintKind, PrintRequest};
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use std::ffi::{CStr, CString};

use std::ffi::{c_char, c_void, CStr, CString};
use std::path::Path;
use std::ptr;
use std::slice;
Expand Down Expand Up @@ -350,7 +351,7 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
ret
}

fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &llvm::TargetMachine) {
let mut llvm_target_features = llvm_target_features(tm);
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
let mut rustc_target_features = supported_target_features(sess)
Expand Down Expand Up @@ -383,36 +384,48 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
.max()
.unwrap_or(0);

println!("Features supported by rustc for this target:");
writeln!(out, "Features supported by rustc for this target:");
for (feature, desc) in &rustc_target_features {
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
}
println!("\nCode-generation features supported by LLVM for this target:");
writeln!(out, "\nCode-generation features supported by LLVM for this target:");
for (feature, desc) in &llvm_target_features {
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
}
if llvm_target_features.is_empty() {
println!(" Target features listing is not supported by this LLVM version.");
writeln!(out, " Target features listing is not supported by this LLVM version.");
}
println!("\nUse +feature to enable a feature, or -feature to disable it.");
println!("For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
println!("Code-generation features cannot be used in cfg or #[target_feature],");
println!("and may be renamed or removed in a future version of LLVM or rustc.\n");
writeln!(out, "\nUse +feature to enable a feature, or -feature to disable it.");
writeln!(out, "For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
writeln!(out, "Code-generation features cannot be used in cfg or #[target_feature],");
writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n");
}

pub(crate) fn print(req: PrintRequest, sess: &Session) {
pub(crate) fn print(req: &PrintRequest, mut out: &mut dyn PrintBackendInfo, sess: &Session) {
require_inited();
let tm = create_informational_target_machine(sess);
match req {
PrintRequest::TargetCPUs => {
match req.kind {
PrintKind::TargetCPUs => {
// SAFETY generate a C compatible string from a byte slice to pass
// the target CPU name into LLVM, the lifetime of the reference is
// at least as long as the C function
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
unsafe extern "C" fn callback(out: *mut c_void, string: *const c_char, len: usize) {
let out = &mut *(out as *mut &mut dyn PrintBackendInfo);
let bytes = slice::from_raw_parts(string as *const u8, len);
write!(out, "{}", String::from_utf8_lossy(bytes));
}
unsafe {
llvm::LLVMRustPrintTargetCPUs(
tm,
cpu_cstring.as_ptr(),
callback,
&mut out as *mut &mut dyn PrintBackendInfo as *mut c_void,
);
}
}
PrintRequest::TargetFeatures => print_target_features(sess, tm),
PrintKind::TargetFeatures => print_target_features(out, sess, tm),
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ codegen_ssa_specify_libraries_to_link = use the `-l` flag to specify native libr

codegen_ssa_static_library_native_artifacts = Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.

codegen_ssa_static_library_native_artifacts_to_file = Native artifacts to link against have been written to {$path}. The order and any duplication can be significant on some platforms.

codegen_ssa_stripping_debug_info_failed = stripping debug info with `{$util}` failed: {$status}
.note = {$output}

Expand Down
39 changes: 28 additions & 11 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, OutFileName, Strip};
use rustc_session::config::{OutputFilenames, OutputType, PrintKind, SplitDwarfKind};
use rustc_session::cstore::DllImport;
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
use rustc_session::search_paths::PathKind;
Expand Down Expand Up @@ -596,8 +596,10 @@ fn link_staticlib<'a>(

all_native_libs.extend_from_slice(&codegen_results.crate_info.used_libraries);

if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
for print in &sess.opts.prints {
if print.kind == PrintKind::NativeStaticLibs {
print_native_static_libs(sess, &print.out, &all_native_libs, &all_rust_dylibs);
}
}

Ok(())
Expand Down Expand Up @@ -744,8 +746,11 @@ fn link_natively<'a>(
cmd.env_remove(k.as_ref());
}

if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
println!("{:?}", &cmd);
for print in &sess.opts.prints {
if print.kind == PrintKind::LinkArgs {
let content = format!("{:?}", cmd);
print.out.overwrite(&content, sess);
}
}

// May have not found libraries in the right formats.
Expand Down Expand Up @@ -1386,6 +1391,7 @@ enum RlibFlavor {

fn print_native_static_libs(
sess: &Session,
out: &OutFileName,
all_native_libs: &[NativeLib],
all_rust_dylibs: &[&Path],
) {
Expand Down Expand Up @@ -1459,11 +1465,22 @@ fn print_native_static_libs(
lib_args.push(format!("-l{}", lib));
}
}
if !lib_args.is_empty() {
sess.emit_note(errors::StaticLibraryNativeArtifacts);
// Prefix for greppability
// Note: This must not be translated as tools are allowed to depend on this exact string.
sess.note_without_error(format!("native-static-libs: {}", &lib_args.join(" ")));

match out {
OutFileName::Real(path) => {
out.overwrite(&lib_args.join(" "), sess);
if !lib_args.is_empty() {
sess.emit_note(errors::StaticLibraryNativeArtifactsToFile { path });
}
}
OutFileName::Stdout => {
if !lib_args.is_empty() {
sess.emit_note(errors::StaticLibraryNativeArtifacts);
// Prefix for greppability
// Note: This must not be translated as tools are allowed to depend on this exact string.
sess.note_without_error(format!("native-static-libs: {}", &lib_args.join(" ")));
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ pub struct LinkerFileStem;
#[diag(codegen_ssa_static_library_native_artifacts)]
pub struct StaticLibraryNativeArtifacts;

#[derive(Diagnostic)]
#[diag(codegen_ssa_static_library_native_artifacts_to_file)]
pub struct StaticLibraryNativeArtifactsToFile<'a> {
pub path: &'a Path,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_link_script_unavailable)]
pub struct LinkScriptUnavailable;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&self,
constant: &mir::Constant<'tcx>,
) -> Result<Option<ty::ValTree<'tcx>>, ErrorHandled> {
let uv = match constant.literal {
let uv = match self.monomorphize(constant.literal) {
mir::ConstantKind::Unevaluated(uv, _) => uv.shrink(),
mir::ConstantKind::Ty(c) => match c.kind() {
// A constant that came from a const generic but was then used as an argument to old-style
// simd_shuffle (passing as argument instead of as a generic param).
rustc_type_ir::ConstKind::Value(valtree) => return Ok(Some(valtree)),
other => span_bug!(constant.span, "{other:#?}"),
},
// We should never encounter `ConstantKind::Val` unless MIR opts (like const prop) evaluate
// a constant and write that value back into `Operand`s. This could happen, but is unlikely.
// Also: all users of `simd_shuffle` are on unstable and already need to take a lot of care
// around intrinsics. For an issue to happen here, it would require a macro expanding to a
// `simd_shuffle` call without wrapping the constant argument in a `const {}` block, but
// the user pass through arbitrary expressions.
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a real
// const generic.
other => span_bug!(constant.span, "{other:#?}"),
};
let uv = self.monomorphize(uv);
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use rustc_span::symbol::Symbol;
use rustc_target::abi::call::FnAbi;
use rustc_target::spec::Target;

use std::fmt;

pub trait BackendTypes {
type Value: CodegenObject;
type Function: CodegenObject;
Expand Down Expand Up @@ -61,7 +63,7 @@ pub trait CodegenBackend {
fn locale_resource(&self) -> &'static str;

fn init(&self, _sess: &Session) {}
fn print(&self, _req: PrintRequest, _sess: &Session) {}
fn print(&self, _req: &PrintRequest, _out: &mut dyn PrintBackendInfo, _sess: &Session) {}
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
vec![]
}
Expand Down Expand Up @@ -162,3 +164,19 @@ pub trait ExtraBackendMethods:
std::thread::Builder::new().name(name).spawn(f)
}
}

pub trait PrintBackendInfo {
fn infallible_write_fmt(&mut self, args: fmt::Arguments<'_>);
}

impl PrintBackendInfo for String {
fn infallible_write_fmt(&mut self, args: fmt::Arguments<'_>) {
fmt::Write::write_fmt(self, args).unwrap();
}
}

impl dyn PrintBackendInfo + '_ {
pub fn write_fmt(&mut self, args: fmt::Arguments<'_>) {
self.infallible_write_fmt(args);
}
}
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ mod write;

pub use self::abi::AbiBuilderMethods;
pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
pub use self::backend::{
Backend, BackendTypes, CodegenBackend, ExtraBackendMethods, PrintBackendInfo,
};
pub use self::builder::{BuilderMethods, OverflowOp};
pub use self::consts::ConstMethods;
pub use self::coverageinfo::CoverageInfoBuilderMethods;
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_driver_impl/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ driver_impl_rlink_rustc_version_mismatch = .rlink file was produced by rustc ver
driver_impl_rlink_unable_to_read = failed to read rlink file: `{$err}`

driver_impl_rlink_wrong_file_type = The input does not look like a .rlink file

driver_impl_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
Loading