Skip to content

Commit

Permalink
Auto merge of rust-lang#117387 - fmease:rollup-5958nsf, r=fmease
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#117147 (Print variadic argument pattern in HIR pretty printer)
 - rust-lang#117177 (Use ImageDataType for allocation type)
 - rust-lang#117205 (Allows `#[diagnostic::on_unimplemented]` attributes to have multiple)
 - rust-lang#117350 (coverage: Replace manual debug indents with nested tracing spans in `counters`)
 - rust-lang#117365 (Stabilize inline asm usage with rustc_codegen_cranelift)
 - rust-lang#117371 (Ignore RPIT duplicated lifetimes in `opaque_types_defined_by`)
 - rust-lang#117382 (Fail typeck for illegal break-with-value)
 - rust-lang#117385 (deduce_param_attrs: explain a read-only case)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 30, 2023
2 parents 91bbdd9 + 288ab16 commit e324cf0
Show file tree
Hide file tree
Showing 32 changed files with 386 additions and 459 deletions.
9 changes: 1 addition & 8 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -1742,14 +1742,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
// as they are not explicit in HIR/Ty function signatures.
// (instead, the `c_variadic` flag is set to `true`)
let mut inputs = &decl.inputs[..];
if decl.c_variadic() {
inputs = &inputs[..inputs.len() - 1];
}
self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind {
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
PatKind::Ident(_, ident, _) => self.lower_ident(ident),
_ => Ident::new(kw::Empty, self.lower_span(param.pat.span)),
}))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Expand Up @@ -35,9 +35,9 @@ smallvec = "1.8.1"

[features]
# Enable features not ready to be enabled when compiling as part of rustc
unstable-features = ["jit", "inline_asm"]
unstable-features = ["jit", "inline_asm_sym"]
jit = ["cranelift-jit", "libloading"]
inline_asm = []
inline_asm_sym = []

[package.metadata.rust-analyzer]
rustc_private = true
17 changes: 0 additions & 17 deletions compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml
Expand Up @@ -40,22 +40,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"

[[package]]
name = "auxv"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e50430f9beb8effb02399fa81c76eeaa26b05e4f03b09285cad8d079c1af5a3d"
dependencies = [
"byteorder",
"gcc",
]

[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"

[[package]]
name = "cc"
version = "1.0.79"
Expand Down Expand Up @@ -388,7 +372,6 @@ dependencies = [
name = "std_detect"
version = "0.1.5"
dependencies = [
"auxv",
"cfg-if",
"compiler_builtins",
"cupid",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-10-21"
channel = "nightly-2023-10-29"
components = ["rust-src", "rustc-dev", "llvm-tools"]
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_cranelift/scripts/setup_rust_fork.sh
Expand Up @@ -4,7 +4,9 @@ set -e
# Compiletest expects all standard library paths to start with /rustc/FAKE_PREFIX.
# CG_CLIF_STDLIB_REMAP_PATH_PREFIX will cause cg_clif's build system to pass
# --remap-path-prefix to handle this.
CG_CLIF_STDLIB_REMAP_PATH_PREFIX=/rustc/FAKE_PREFIX ./y.sh build
# CG_CLIF_FORCE_GNU_AS will force usage of as instead of the LLVM backend of rustc as we
# the LLVM backend isn't compiled in here.
CG_CLIF_FORCE_GNU_AS=1 CG_CLIF_STDLIB_REMAP_PATH_PREFIX=/rustc/FAKE_PREFIX ./y.sh build

echo "[SETUP] Rust fork"
git clone https://github.com/rust-lang/rust.git || true
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_cranelift/scripts/test_bootstrap.sh
Expand Up @@ -11,5 +11,7 @@ rm -r compiler/rustc_codegen_cranelift/{Cargo.*,src}
cp ../Cargo.* compiler/rustc_codegen_cranelift/
cp -r ../src compiler/rustc_codegen_cranelift/src

./x.py build --stage 1 library/std
# CG_CLIF_FORCE_GNU_AS will force usage of as instead of the LLVM backend of rustc as we
# the LLVM backend isn't compiled in here.
CG_CLIF_FORCE_GNU_AS=1 ./x.py build --stage 1 library/std
popd
113 changes: 80 additions & 33 deletions compiler/rustc_codegen_cranelift/src/global_asm.rs
Expand Up @@ -46,6 +46,13 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
global_asm.push_str(&string);
}
InlineAsmOperand::SymFn { anon_const } => {
if cfg!(not(feature = "inline_asm_sym")) {
tcx.sess.span_err(
item.span,
"asm! and global_asm! sym operands are not yet supported",
);
}

let ty = tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
let instance = match ty.kind() {
&ty::FnDef(def_id, args) => Instance::new(def_id, args),
Expand All @@ -57,6 +64,13 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
global_asm.push_str(symbol.name);
}
InlineAsmOperand::SymStatic { path: _, def_id } => {
if cfg!(not(feature = "inline_asm_sym")) {
tcx.sess.span_err(
item.span,
"asm! and global_asm! sym operands are not yet supported",
);
}

let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
let symbol = tcx.symbol_name(instance);
global_asm.push_str(symbol.name);
Expand All @@ -81,22 +95,23 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
}
}

pub(crate) fn asm_supported(tcx: TyCtxt<'_>) -> bool {
cfg!(feature = "inline_asm") && !tcx.sess.target.is_like_windows
}

#[derive(Debug)]
pub(crate) struct GlobalAsmConfig {
asm_enabled: bool,
assembler: PathBuf,
target: String,
pub(crate) output_filenames: Arc<OutputFilenames>,
}

impl GlobalAsmConfig {
pub(crate) fn new(tcx: TyCtxt<'_>) -> Self {
GlobalAsmConfig {
asm_enabled: asm_supported(tcx),
assembler: crate::toolchain::get_toolchain_binary(tcx.sess, "as"),
target: match &tcx.sess.opts.target_triple {
rustc_target::spec::TargetTriple::TargetTriple(triple) => triple.clone(),
rustc_target::spec::TargetTriple::TargetJson { path_for_rustdoc, .. } => {
path_for_rustdoc.to_str().unwrap().to_owned()
}
},
output_filenames: tcx.output_filenames(()).clone(),
}
}
Expand All @@ -111,21 +126,6 @@ pub(crate) fn compile_global_asm(
return Ok(None);
}

if !config.asm_enabled {
if global_asm.contains("__rust_probestack") {
return Ok(None);
}

if cfg!(not(feature = "inline_asm")) {
return Err(
"asm! and global_asm! support is disabled while compiling rustc_codegen_cranelift"
.to_owned(),
);
} else {
return Err("asm! and global_asm! are not yet supported on Windows".to_owned());
}
}

// Remove all LLVM style comments
let mut global_asm = global_asm
.lines()
Expand All @@ -134,20 +134,67 @@ pub(crate) fn compile_global_asm(
.join("\n");
global_asm.push('\n');

let output_object_file = config.output_filenames.temp_path(OutputType::Object, Some(cgu_name));
let global_asm_object_file = add_file_stem_postfix(
config.output_filenames.temp_path(OutputType::Object, Some(cgu_name)),
".asm",
);

// Assemble `global_asm`
let global_asm_object_file = add_file_stem_postfix(output_object_file, ".asm");
let mut child = Command::new(&config.assembler)
.arg("-o")
.arg(&global_asm_object_file)
.stdin(Stdio::piped())
.spawn()
.expect("Failed to spawn `as`.");
child.stdin.take().unwrap().write_all(global_asm.as_bytes()).unwrap();
let status = child.wait().expect("Failed to wait for `as`.");
if !status.success() {
return Err(format!("Failed to assemble `{}`", global_asm));
if option_env!("CG_CLIF_FORCE_GNU_AS").is_some() {
let mut child = Command::new(&config.assembler)
.arg("-o")
.arg(&global_asm_object_file)
.stdin(Stdio::piped())
.spawn()
.expect("Failed to spawn `as`.");
child.stdin.take().unwrap().write_all(global_asm.as_bytes()).unwrap();
let status = child.wait().expect("Failed to wait for `as`.");
if !status.success() {
return Err(format!("Failed to assemble `{}`", global_asm));
}
} else {
let mut child = Command::new(std::env::current_exe().unwrap())
.arg("--target")
.arg(&config.target)
.arg("--crate-type")
.arg("staticlib")
.arg("--emit")
.arg("obj")
.arg("-o")
.arg(&global_asm_object_file)
.arg("-")
.arg("-Abad_asm_style")
.arg("-Zcodegen-backend=llvm")
.stdin(Stdio::piped())
.spawn()
.expect("Failed to spawn `as`.");
let mut stdin = child.stdin.take().unwrap();
stdin
.write_all(
br####"
#![feature(decl_macro, no_core, rustc_attrs)]
#![allow(internal_features)]
#![no_core]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
macro global_asm() { /* compiler built-in */ }
global_asm!(r###"
"####,
)
.unwrap();
stdin.write_all(global_asm.as_bytes()).unwrap();
stdin
.write_all(
br####"
"###);
"####,
)
.unwrap();
std::mem::drop(stdin);
let status = child.wait().expect("Failed to wait for `as`.");
if !status.success() {
return Err(format!("Failed to assemble `{}`", global_asm));
}
}

Ok(Some(global_asm_object_file))
Expand Down

0 comments on commit e324cf0

Please sign in to comment.