Skip to content

Rollup of 8 pull requests #117387

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

Merged
merged 33 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
40cc891
Remove from cranelift codegen LLVM intrinsics that are no longer needed
eduardosm Oct 10, 2023
a302610
Merge commit '93a5433f17ab5ed48cc88f1e69b0713b16183373' into sync_cg_…
bjorn3 Oct 24, 2023
6d30a7d
Merge branch 'sync_from_rust'
bjorn3 Oct 24, 2023
2c1dbed
Print variadic argument pattern in HIR pretty printer
DaniPopes Oct 24, 2023
6aead74
Remove unnecessary CVarArgs name skipping logic
DaniPopes Oct 25, 2023
160b179
Allows `#[diagnostic::on_unimplemented]` attributes to have multiple
weiznich Oct 26, 2023
1e39bbf
Update Cranelift to 0.101.2 and disable host-arch feature of cranelif…
bjorn3 Oct 25, 2023
1cb7bdb
Update target-lexicon to 0.12.12
bjorn3 Oct 26, 2023
9e20870
Auto merge of #116609 - eduardosm:bump-stdarch, r=workingjubilee
bors Oct 28, 2023
da1ed4d
Auto merge of #81746 - bjorn3:cg_clif_rustup_component, r=Mark-Simula…
bors Oct 28, 2023
827a6d8
Use the LLVM rustc backend as external assembler
bjorn3 Oct 29, 2023
b1e7051
Unconditionally handle int $$0x29 using a shim
bjorn3 Oct 29, 2023
35453ac
Stabilize inline asm usage on all platforms
bjorn3 Oct 29, 2023
69c6aa5
Avoid infinite recursion when cranelift is the default codegen backend
bjorn3 Oct 29, 2023
9436eae
Merge pull request #1403 from rust-lang/use_llvm_backend_as_assembler
bjorn3 Oct 29, 2023
e281e6f
Sync from rust e5cfc55477eceed1317a02189fdf77a4a98f2124
bjorn3 Oct 29, 2023
dde5880
Rustup to rustc 1.75.0-nightly (e5cfc5547 2023-10-28)
bjorn3 Oct 29, 2023
a9b21bb
Merge commit 'dde58803fd6cbb270c7a437f36a8a3a29fbef679' into sync_cg_…
bjorn3 Oct 29, 2023
c561325
Ignore RPIT duplicated lifetimes in opaque_types_defined_by
compiler-errors Oct 29, 2023
6d69eb1
coverage: Replace manual debug indents with nested tracing spans
Zalathar Oct 29, 2023
2f1be08
coverage: Inline the "recursive" worker methods for assigning counters
Zalathar Oct 29, 2023
10c4734
coverage: Use a tracing span to group the parts of a sum-up expression
Zalathar Oct 29, 2023
441068b
Use ImageDataType for allocation type
Ayush1325 Oct 25, 2023
0c8bdd0
Fail typeck for illegal break-with-value
gurry Oct 30, 2023
3f7e506
deduce_param_attrs: explain a read-only case
RalfJung Oct 30, 2023
2915707
Rollup merge of #117147 - DaniPopes:pphir-fn-variadic, r=compiler-errors
fmease Oct 30, 2023
098bb37
Rollup merge of #117177 - Ayush1325:uefi-alloc-type, r=workingjubilee
fmease Oct 30, 2023
5eb76fa
Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemente…
fmease Oct 30, 2023
9a8d800
Rollup merge of #117350 - Zalathar:counters-indent, r=oli-obk
fmease Oct 30, 2023
fd5ffab
Rollup merge of #117365 - bjorn3:sync_cg_clif-2023-10-29, r=oli-obk
fmease Oct 30, 2023
12eb539
Rollup merge of #117371 - compiler-errors:unique-params, r=oli-obk
fmease Oct 30, 2023
4f4b38c
Rollup merge of #117382 - gurry:114529-ice-const-eval, r=oli-obk
fmease Oct 30, 2023
288ab16
Rollup merge of #117385 - RalfJung:deduce_param_attrs, r=oli-obk
fmease Oct 30, 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
9 changes: 1 addition & 8 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading