Auto merge of #86091 - JohnTitor:rollup-wceot6d, r=JohnTitor
Rollup of 6 pull requests Successful merges: - #84262 (Fix ICE during type layout when there's a `[type error]`) - #85973 (Replace a `match` with an `if let`) - #85996 (rustbuild: take changes to the standard library into account for `download-rustc`) - #86016 (Unify duplicate linker_and_flavor methods in rustc_codegen_{cranelift,ssa}.) - #86025 (Remove the install prefix from the rpath set when using -Crpath) - #86081 (Use `try_into` instead of asserting manually) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
022720bfcc
@ -2,9 +2,8 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_middle::bug;
|
||||
use rustc_codegen_ssa::back::link::linker_and_flavor;
|
||||
use rustc_session::Session;
|
||||
use rustc_target::spec::LinkerFlavor;
|
||||
|
||||
/// Tries to infer the path of a binary for the target toolchain from the linker name.
|
||||
pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {
|
||||
@ -30,90 +29,3 @@ pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {
|
||||
|
||||
linker
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_codegen_ssa/back/link.rs#L848-L931
|
||||
fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
||||
fn infer_from(
|
||||
sess: &Session,
|
||||
linker: Option<PathBuf>,
|
||||
flavor: Option<LinkerFlavor>,
|
||||
) -> Option<(PathBuf, LinkerFlavor)> {
|
||||
match (linker, flavor) {
|
||||
(Some(linker), Some(flavor)) => Some((linker, flavor)),
|
||||
// only the linker flavor is known; use the default linker for the selected flavor
|
||||
(None, Some(flavor)) => Some((
|
||||
PathBuf::from(match flavor {
|
||||
LinkerFlavor::Em => {
|
||||
if cfg!(windows) {
|
||||
"emcc.bat"
|
||||
} else {
|
||||
"emcc"
|
||||
}
|
||||
}
|
||||
LinkerFlavor::Gcc => {
|
||||
if cfg!(any(target_os = "solaris", target_os = "illumos")) {
|
||||
// On historical Solaris systems, "cc" may have
|
||||
// been Sun Studio, which is not flag-compatible
|
||||
// with "gcc". This history casts a long shadow,
|
||||
// and many modern illumos distributions today
|
||||
// ship GCC as "gcc" without also making it
|
||||
// available as "cc".
|
||||
"gcc"
|
||||
} else {
|
||||
"cc"
|
||||
}
|
||||
}
|
||||
LinkerFlavor::Ld => "ld",
|
||||
LinkerFlavor::Msvc => "link.exe",
|
||||
LinkerFlavor::Lld(_) => "lld",
|
||||
LinkerFlavor::PtxLinker => "rust-ptx-linker",
|
||||
LinkerFlavor::BpfLinker => "bpf-linker",
|
||||
}),
|
||||
flavor,
|
||||
)),
|
||||
(Some(linker), None) => {
|
||||
let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| {
|
||||
sess.fatal("couldn't extract file stem from specified linker")
|
||||
});
|
||||
|
||||
let flavor = if stem == "emcc" {
|
||||
LinkerFlavor::Em
|
||||
} else if stem == "gcc"
|
||||
|| stem.ends_with("-gcc")
|
||||
|| stem == "clang"
|
||||
|| stem.ends_with("-clang")
|
||||
{
|
||||
LinkerFlavor::Gcc
|
||||
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
|
||||
LinkerFlavor::Ld
|
||||
} else if stem == "link" || stem == "lld-link" {
|
||||
LinkerFlavor::Msvc
|
||||
} else if stem == "lld" || stem == "rust-lld" {
|
||||
LinkerFlavor::Lld(sess.target.lld_flavor)
|
||||
} else {
|
||||
// fall back to the value in the target spec
|
||||
sess.target.linker_flavor
|
||||
};
|
||||
|
||||
Some((linker, flavor))
|
||||
}
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
// linker and linker flavor specified via command line have precedence over what the target
|
||||
// specification specifies
|
||||
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), sess.opts.cg.linker_flavor) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if let Some(ret) = infer_from(
|
||||
sess,
|
||||
sess.target.linker.clone().map(PathBuf::from),
|
||||
Some(sess.target.linker_flavor),
|
||||
) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bug!("Not enough information provided to determine how to invoke the linker");
|
||||
}
|
||||
|
@ -1147,7 +1147,8 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
|
||||
&& (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
|
||||
}
|
||||
|
||||
fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
||||
// This functions tries to determine the appropriate linker (and corresponding LinkerFlavor) to use
|
||||
pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
||||
fn infer_from(
|
||||
sess: &Session,
|
||||
linker: Option<PathBuf>,
|
||||
@ -1714,24 +1715,14 @@ fn add_rpath_args(
|
||||
) {
|
||||
// FIXME (#2397): At some point we want to rpath our guesses as to
|
||||
// where extern libraries might live, based on the
|
||||
// addl_lib_search_paths
|
||||
// add_lib_search_paths
|
||||
if sess.opts.cg.rpath {
|
||||
let target_triple = sess.opts.target_triple.triple();
|
||||
let mut get_install_prefix_lib_path = || {
|
||||
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
|
||||
let tlib = rustc_target::target_rustlib_path(&sess.sysroot, target_triple).join("lib");
|
||||
let mut path = PathBuf::from(install_prefix);
|
||||
path.push(&tlib);
|
||||
|
||||
path
|
||||
};
|
||||
let mut rpath_config = RPathConfig {
|
||||
used_crates: &codegen_results.crate_info.used_crates_dynamic,
|
||||
out_filename: out_filename.to_path_buf(),
|
||||
has_rpath: sess.target.has_rpath,
|
||||
is_like_osx: sess.target.is_like_osx,
|
||||
linker_is_gnu: sess.target.linker_is_gnu,
|
||||
get_install_prefix_lib_path: &mut get_install_prefix_lib_path,
|
||||
};
|
||||
cmd.args(&rpath::get_rpath_flags(&mut rpath_config));
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ pub struct RPathConfig<'a> {
|
||||
pub is_like_osx: bool,
|
||||
pub has_rpath: bool,
|
||||
pub linker_is_gnu: bool,
|
||||
pub get_install_prefix_lib_path: &'a mut dyn FnMut() -> PathBuf,
|
||||
}
|
||||
|
||||
pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec<String> {
|
||||
@ -63,24 +62,13 @@ fn get_rpaths(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
|
||||
// Use relative paths to the libraries. Binaries can be moved
|
||||
// as long as they maintain the relative relationship to the
|
||||
// crates they depend on.
|
||||
let rel_rpaths = get_rpaths_relative_to_output(config, libs);
|
||||
let rpaths = get_rpaths_relative_to_output(config, libs);
|
||||
|
||||
// And a final backup rpath to the global library location.
|
||||
let fallback_rpaths = vec![get_install_prefix_rpath(config)];
|
||||
|
||||
fn log_rpaths(desc: &str, rpaths: &[String]) {
|
||||
debug!("{} rpaths:", desc);
|
||||
for rpath in rpaths {
|
||||
debug!(" {}", *rpath);
|
||||
}
|
||||
debug!("rpaths:");
|
||||
for rpath in &rpaths {
|
||||
debug!(" {}", rpath);
|
||||
}
|
||||
|
||||
log_rpaths("relative", &rel_rpaths);
|
||||
log_rpaths("fallback", &fallback_rpaths);
|
||||
|
||||
let mut rpaths = rel_rpaths;
|
||||
rpaths.extend_from_slice(&fallback_rpaths);
|
||||
|
||||
// Remove duplicates
|
||||
minimize_rpaths(&rpaths)
|
||||
}
|
||||
@ -113,13 +101,6 @@ fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
|
||||
diff_paths(path, base)
|
||||
}
|
||||
|
||||
fn get_install_prefix_rpath(config: &mut RPathConfig<'_>) -> String {
|
||||
let path = (config.get_install_prefix_lib_path)();
|
||||
let path = env::current_dir().unwrap().join(&path);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
path.to_str().expect("non-utf8 component in rpath").to_owned()
|
||||
}
|
||||
|
||||
fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
|
||||
let mut set = FxHashSet::default();
|
||||
let mut minimized = Vec::new();
|
||||
|
@ -40,7 +40,6 @@ fn test_rpath_relative() {
|
||||
is_like_osx: true,
|
||||
linker_is_gnu: false,
|
||||
out_filename: PathBuf::from("bin/rustc"),
|
||||
get_install_prefix_lib_path: &mut || panic!(),
|
||||
};
|
||||
let res = get_rpath_relative_to_output(config, Path::new("lib/libstd.so"));
|
||||
assert_eq!(res, "@loader_path/../lib");
|
||||
@ -48,7 +47,6 @@ fn test_rpath_relative() {
|
||||
let config = &mut RPathConfig {
|
||||
used_crates: &[],
|
||||
out_filename: PathBuf::from("bin/rustc"),
|
||||
get_install_prefix_lib_path: &mut || panic!(),
|
||||
has_rpath: true,
|
||||
is_like_osx: false,
|
||||
linker_is_gnu: true,
|
||||
|
@ -367,7 +367,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
for &i in &inverse_memory_index {
|
||||
let field = fields[i as usize];
|
||||
if !sized {
|
||||
bug!("univariant: field #{} of `{}` comes after unsized field", offsets.len(), ty);
|
||||
self.tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
&format!(
|
||||
"univariant: field #{} of `{}` comes after unsized field",
|
||||
offsets.len(),
|
||||
ty
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if field.is_unsized() {
|
||||
|
@ -16,32 +16,29 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
|
||||
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
|
||||
for block in basic_blocks.iter_mut() {
|
||||
for statement in block.statements.iter_mut() {
|
||||
match statement.kind {
|
||||
StatementKind::Assign(box (place, _)) => {
|
||||
let place_ty = place.ty(local_decls, tcx).ty;
|
||||
if !maybe_zst(place_ty) {
|
||||
continue;
|
||||
}
|
||||
let layout = match tcx.layout_of(param_env.and(place_ty)) {
|
||||
Ok(layout) => layout,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if !layout.is_zst() {
|
||||
continue;
|
||||
}
|
||||
if involves_a_union(place, local_decls, tcx) {
|
||||
continue;
|
||||
}
|
||||
if tcx.consider_optimizing(|| {
|
||||
format!(
|
||||
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
||||
place, statement.source_info
|
||||
)
|
||||
}) {
|
||||
statement.make_nop();
|
||||
}
|
||||
if let StatementKind::Assign(box (place, _)) = statement.kind {
|
||||
let place_ty = place.ty(local_decls, tcx).ty;
|
||||
if !maybe_zst(place_ty) {
|
||||
continue;
|
||||
}
|
||||
let layout = match tcx.layout_of(param_env.and(place_ty)) {
|
||||
Ok(layout) => layout,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if !layout.is_zst() {
|
||||
continue;
|
||||
}
|
||||
if involves_a_union(place, local_decls, tcx) {
|
||||
continue;
|
||||
}
|
||||
if tcx.consider_optimizing(|| {
|
||||
format!(
|
||||
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
||||
place, statement.source_info
|
||||
)
|
||||
}) {
|
||||
statement.make_nop();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -753,11 +753,7 @@ impl FieldsShape {
|
||||
match *self {
|
||||
FieldsShape::Primitive => 0,
|
||||
FieldsShape::Union(count) => count.get(),
|
||||
FieldsShape::Array { count, .. } => {
|
||||
let usize_count = count as usize;
|
||||
assert_eq!(usize_count as u64, count);
|
||||
usize_count
|
||||
}
|
||||
FieldsShape::Array { count, .. } => count.try_into().unwrap(),
|
||||
FieldsShape::Arbitrary { ref offsets, .. } => offsets.len(),
|
||||
}
|
||||
}
|
||||
@ -791,11 +787,7 @@ impl FieldsShape {
|
||||
unreachable!("FieldsShape::memory_index: `Primitive`s have no fields")
|
||||
}
|
||||
FieldsShape::Union(_) | FieldsShape::Array { .. } => i,
|
||||
FieldsShape::Arbitrary { ref memory_index, .. } => {
|
||||
let r = memory_index[i];
|
||||
assert_eq!(r as usize as u32, r);
|
||||
r as usize
|
||||
}
|
||||
FieldsShape::Arbitrary { ref memory_index, .. } => memory_index[i].try_into().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -648,18 +648,20 @@ class RustBuild(object):
|
||||
rev_parse = ["git", "rev-parse", "--show-toplevel"]
|
||||
top_level = subprocess.check_output(rev_parse, universal_newlines=True).strip()
|
||||
compiler = "{}/compiler/".format(top_level)
|
||||
library = "{}/library/".format(top_level)
|
||||
|
||||
# Look for a version to compare to based on the current commit.
|
||||
# Only commits merged by bors will have CI artifacts.
|
||||
merge_base = ["git", "log", "--author=bors", "--pretty=%H", "-n1"]
|
||||
commit = subprocess.check_output(merge_base, universal_newlines=True).strip()
|
||||
|
||||
# Warn if there were changes to the compiler since the ancestor commit.
|
||||
status = subprocess.call(["git", "diff-index", "--quiet", commit, "--", compiler])
|
||||
# Warn if there were changes to the compiler or standard library since the ancestor commit.
|
||||
status = subprocess.call(["git", "diff-index", "--quiet", commit, "--", compiler, library])
|
||||
if status != 0:
|
||||
if download_rustc == "if-unchanged":
|
||||
return None
|
||||
print("warning: `download-rustc` is enabled, but there are changes to compiler/")
|
||||
print("warning: `download-rustc` is enabled, but there are changes to \
|
||||
compiler/ or library/")
|
||||
|
||||
if self.verbose:
|
||||
print("using downloaded stage1 artifacts from CI (commit {})".format(commit))
|
||||
|
@ -636,8 +636,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
|
||||
cargo
|
||||
.env("CFG_RELEASE", builder.rust_release())
|
||||
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
|
||||
.env("CFG_VERSION", builder.rust_version())
|
||||
.env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default());
|
||||
.env("CFG_VERSION", builder.rust_version());
|
||||
|
||||
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
|
||||
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
|
||||
|
14
src/test/ui/layout/issue-84108.rs
Normal file
14
src/test/ui/layout/issue-84108.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// See issue #84108 -- this is a test to ensure we do not ICE
|
||||
// on this invalid code.
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
|
||||
//~^ ERROR cannot find type `OsStr` in this scope
|
||||
|
||||
const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
//~^ ERROR cannot find type `Path` in this scope
|
||||
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
|
||||
|
||||
static BAZ: ([u8], usize) = ([], 0);
|
||||
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
|
44
src/test/ui/layout/issue-84108.stderr
Normal file
44
src/test/ui/layout/issue-84108.stderr
Normal file
@ -0,0 +1,44 @@
|
||||
error[E0412]: cannot find type `OsStr` in this scope
|
||||
--> $DIR/issue-84108.rs:6:24
|
||||
|
|
||||
LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
|
||||
| ^^^^^ not found in this scope
|
||||
|
|
||||
help: consider importing this struct
|
||||
|
|
||||
LL | use std::ffi::OsStr;
|
||||
|
|
||||
|
||||
error[E0412]: cannot find type `Path` in this scope
|
||||
--> $DIR/issue-84108.rs:9:14
|
||||
|
|
||||
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
| ^^^^ not found in this scope
|
||||
|
|
||||
help: consider importing this struct
|
||||
|
|
||||
LL | use std::path::Path;
|
||||
|
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:9:12
|
||||
|
|
||||
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u8]`
|
||||
= note: only the last element of a tuple may have a dynamically sized type
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:13:13
|
||||
|
|
||||
LL | static BAZ: ([u8], usize) = ([], 0);
|
||||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u8]`
|
||||
= note: only the last element of a tuple may have a dynamically sized type
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0412.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
Loading…
x
Reference in New Issue
Block a user