Skip to content

Sync from rust 2024/03/04 #464

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 22 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6ff147b
Add "algebraic" versions of the fast-math intrinsics
saethlin Feb 6, 2024
7a991d5
Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercote
bors Feb 21, 2024
a9b5c08
make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not…
RalfJung Feb 18, 2024
0abd3b7
remove simd_reduce_{min,max}_nanless
RalfJung Feb 18, 2024
a06a87b
rename 'try' intrinsic to 'catch_unwind'
RalfJung Feb 25, 2024
7f34119
remove useless lifetime of ArchiveBuilder
823984418 Feb 26, 2024
b4b180c
Auto merge of #121635 - 823984418:remove_archive_builder_lifetime_a, …
bors Feb 27, 2024
7d086c7
always use gep inbounds i8 (ptradd) for field offsets
erikdesjardins Feb 24, 2024
19a6482
remove struct_gep, use manual layout calculations for va_arg
erikdesjardins Feb 24, 2024
70346fe
introduce and use ptradd/inbounds_ptradd instead of gep
erikdesjardins Feb 24, 2024
7005ef9
Rename `DiagnosticBuilder` as `Diag`.
nnethercote Feb 22, 2024
427d617
Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`.
nnethercote Feb 23, 2024
8dd96ba
Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Prim…
tgross35 Feb 28, 2024
27b669a
Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compile…
bors Mar 1, 2024
1abbf61
Auto merge of #121665 - erikdesjardins:ptradd, r=nikic
bors Mar 3, 2024
1605928
Merge branch 'master' into sync_from_rust_2024_03_04
antoyo Mar 5, 2024
b765157
Workaround for linker error about missing -lLLVM-18-rust-1.78.0-nightly
antoyo Mar 5, 2024
cd75da1
Fix formatting
antoyo Mar 5, 2024
499d3c2
Fix CI
antoyo Mar 5, 2024
42a0d63
Ignore rand tests warnings
GuillaumeGomez Mar 5, 2024
86a2bb7
Fix CI
antoyo Mar 5, 2024
3b4c58d
Fix rand tests
antoyo Mar 5, 2024
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
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TODO: remove this file and deps/libLLVM-18-rust-1.78.0-nightly.so when
// https://github.com/rust-lang/rust/pull/121967 is merged.
fn main() {
println!("cargo:rerun-if-changed=deps/libLLVM-18-rust-1.78.0-nightly.so");
println!("cargo:rustc-link-search=deps");
}
26 changes: 26 additions & 0 deletions build_system/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ fn prepare_libcore(
)?;
}
println!("Successfully prepared libcore for building");

Ok(())
}

// TODO: remove when we can ignore warnings in rustdoc tests.
fn prepare_rand() -> Result<(), String> {
// Apply patch for the rand crate.
let file_path = "patches/crates/0001-Remove-deny-warnings.patch";
let rand_dir = Path::new("build/rand");
println!("[GIT] apply `{}`", file_path);
let path = Path::new("../..").join(file_path);
run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?;
run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?;
run_command_with_output(
&[
&"git",
&"commit",
&"--no-gpg-sign",
&"-m",
&format!("Patch {}", path.display()),
],
Some(rand_dir),
)?;

Ok(())
}

Expand Down Expand Up @@ -241,6 +265,8 @@ pub fn run() -> Result<(), String> {
for (repo_url, checkout_commit, cb) in to_clone {
clone_and_setup(repo_url, checkout_commit, *cb)?;
}

prepare_rand()?;
}

println!("Successfully ran `prepare`");
Expand Down
20 changes: 15 additions & 5 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,11 +771,19 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
println!("Not using GCC master branch. Skipping `extended_rand_tests`.");
return Ok(());
}
let mut env = env.clone();
// newer aho_corasick versions throw a deprecation warning
let rustflags = format!(
"{} --cap-lints warn",
env.get("RUSTFLAGS").cloned().unwrap_or_default()
);
env.insert("RUSTFLAGS".to_string(), rustflags);

let path = Path::new(crate::BUILD_DIR).join("rand");
run_cargo_command(&[&"clean"], Some(&path), env, args)?;
run_cargo_command(&[&"clean"], Some(&path), &env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-random/rand");
run_cargo_command(&[&"test", &"--workspace"], Some(&path), env, args)?;
run_cargo_command(&[&"test", &"--workspace"], Some(&path), &env, args)?;
Ok(())
}

Expand Down Expand Up @@ -911,9 +919,9 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
continue;
}
if [
"// error-pattern:",
"// build-fail",
"// run-fail",
"//@ error-pattern:",
"//@ build-fail",
"//@ run-fail",
"-Cllvm-args",
"//~",
"thread",
Expand Down Expand Up @@ -1007,6 +1015,8 @@ where
// Tests generating errors.
remove_file(&rust_path.join("tests/ui/consts/issue-94675.rs"))?;
remove_file(&rust_path.join("tests/ui/mir/mir_heavy_promoted.rs"))?;
remove_file(&rust_path.join("tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.rs"))?;
remove_file(&rust_path.join("tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.rs"))?;

walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?;

Expand Down
1 change: 1 addition & 0 deletions deps/libLLVM-18-rust-1.78.0-nightly.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INPUT(libLLVM.so.18.1-rust-1.78.0-nightly)
24 changes: 24 additions & 0 deletions patches/crates/0001-Remove-deny-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From f4a31d2c57cdbd578b778ab70eb2a0cfb248652c Mon Sep 17 00:00:00 2001
From: Antoni Boucher <[email protected]>
Date: Tue, 5 Mar 2024 12:39:44 -0500
Subject: [PATCH] Remove #[deny(warnings)]

---
src/lib.rs | 1 -
1 file changed, 1 deletion(-)

diff --git a/src/lib.rs b/src/lib.rs
index 8ade2881d5..e26c595e38 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,7 +47,6 @@
)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
-#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#![no_std]
#![cfg_attr(feature = "simd_support", feature(stdsimd, portable_simd))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
--
2.44.0

2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-02-20"
channel = "nightly-2024-03-05"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
2 changes: 1 addition & 1 deletion src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_session::cstore::DllImport;
pub(crate) struct ArArchiveBuilderBuilder;

impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
}

Expand Down
65 changes: 32 additions & 33 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,31 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
result
}

fn fadd_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
lhs + rhs
}

fn fsub_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
lhs - rhs
}

fn fmul_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
lhs * rhs
}

fn fdiv_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
lhs / rhs
}

fn frem_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
self.frem(lhs, rhs)
}

fn checked_binop(
&mut self,
oop: OverflowOp,
Expand Down Expand Up @@ -983,10 +1008,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
OperandValue::Immediate(self.to_immediate(load, place.layout))
} else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
let b_offset = a.size(self).align_to(b.align(self).abi);
let pair_type = place.layout.gcc_type(self);

let mut load = |i, scalar: &abi::Scalar, align| {
let llptr = self.struct_gep(pair_type, place.llval, i as u64);
let llptr = if i == 0 {
place.llval
} else {
self.inbounds_ptradd(place.llval, self.const_usize(b_offset.bytes()))
};
let llty = place.layout.scalar_pair_element_gcc_type(self, i);
let load = self.load(llty, llptr, align);
scalar_load_metadata(self, load, scalar);
Expand Down Expand Up @@ -1157,35 +1185,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
result.get_address(self.location)
}

fn struct_gep(&mut self, value_type: Type<'gcc>, ptr: RValue<'gcc>, idx: u64) -> RValue<'gcc> {
// FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.
assert_eq!(idx as usize as u64, idx);
let value = ptr.dereference(self.location).to_rvalue();

if value_type.dyncast_array().is_some() {
let index = self
.context
.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
let element = self.context.new_array_access(self.location, value, index);
element.get_address(self.location)
} else if let Some(vector_type) = value_type.dyncast_vector() {
let array_type = vector_type.get_element_type().make_pointer();
let array = self.bitcast(ptr, array_type);
let index = self
.context
.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
let element = self.context.new_array_access(self.location, array, index);
element.get_address(self.location)
} else if let Some(struct_type) = value_type.is_struct() {
// NOTE: due to opaque pointers now being used, we need to bitcast here.
let ptr = self.bitcast_if_needed(ptr, value_type.make_pointer());
ptr.dereference_field(self.location, struct_type.get_field(idx as i32))
.get_address(self.location)
} else {
panic!("Unexpected type {:?}", value_type);
}
}

/* Casts */
fn trunc(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
// TODO(antoyo): check that it indeed truncate the value.
Expand Down Expand Up @@ -2078,7 +2077,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
self.vector_reduce(src, |a, b, context| context.new_binary_op(loc, op, a.get_type(), a, b))
}

pub fn vector_reduce_fadd_fast(
pub fn vector_reduce_fadd_reassoc(
&mut self,
_acc: RValue<'gcc>,
_src: RValue<'gcc>,
Expand Down Expand Up @@ -2109,7 +2108,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
unimplemented!();
}

pub fn vector_reduce_fmul_fast(
pub fn vector_reduce_fmul_reassoc(
&mut self,
_acc: RValue<'gcc>,
_src: RValue<'gcc>,
Expand Down
10 changes: 3 additions & 7 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level};
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span;

Expand Down Expand Up @@ -90,12 +90,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
pub(crate) struct MissingFeatures;

impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let mut diag = DiagnosticBuilder::new(
dcx,
level,
fluent::codegen_gcc_target_feature_disable_or_enable,
);
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable);
if let Some(span) = self.span {
diag.span(span);
};
Expand Down
4 changes: 2 additions & 2 deletions src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_middle::ty::layout::LayoutOf;
#[cfg(feature = "master")]
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
use rustc_middle::ty::{self, Instance, Ty};
use rustc_span::{sym, symbol::kw, Span, Symbol};
use rustc_span::{sym, Span, Symbol};
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
use rustc_target::abi::HasDataLayout;
#[cfg(feature = "master")]
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
let res = self.context.new_call(None, builtin, &[a]);
self.icmp(IntPredicate::IntEQ, res, self.const_i32(0))
}
kw::Try => {
sym::catch_unwind => {
try_intrinsic(
self,
args[0].immediate(),
Expand Down
7 changes: 2 additions & 5 deletions src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,14 +1171,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(

arith_red!(
simd_reduce_add_unordered: BinaryOp::Plus,
vector_reduce_fadd_fast,
vector_reduce_fadd_reassoc,
false,
add,
0.0 // TODO: Use this argument.
);
arith_red!(
simd_reduce_mul_unordered: BinaryOp::Mult,
vector_reduce_fmul_fast,
vector_reduce_fmul_reassoc,
false,
mul,
1.0
Expand Down Expand Up @@ -1223,9 +1223,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(

minmax_red!(simd_reduce_min: vector_reduce_min, vector_reduce_fmin);
minmax_red!(simd_reduce_max: vector_reduce_max, vector_reduce_fmax);
// TODO(sadlerap): revisit these intrinsics to generate more optimal reductions
minmax_red!(simd_reduce_min_nanless: vector_reduce_min, vector_reduce_fmin);
minmax_red!(simd_reduce_max_nanless: vector_reduce_max, vector_reduce_fmax);

macro_rules! bitwise_red {
($name:ident : $op:expr, $boolean:expr) => {
Expand Down
10 changes: 10 additions & 0 deletions src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

pub fn type_float_from_ty(&self, t: ty::FloatTy) -> Type<'gcc> {
match t {
ty::FloatTy::F16 => self.type_f16(),
ty::FloatTy::F32 => self.type_f32(),
ty::FloatTy::F64 => self.type_f64(),
ty::FloatTy::F128 => self.type_f128(),
}
}
}
Expand Down Expand Up @@ -118,6 +120,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.isize_type
}

fn type_f16(&self) -> Type<'gcc> {
unimplemented!("f16_f128")
}

fn type_f32(&self) -> Type<'gcc> {
self.float_type
}
Expand All @@ -126,6 +132,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.double_type
}

fn type_f128(&self) -> Type<'gcc> {
unimplemented!("f16_f128")
}

fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
self.context.new_function_pointer_type(None, return_type, params, false)
}
Expand Down
27 changes: 3 additions & 24 deletions src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
use rustc_target::abi::{
self, Abi, Align, FieldsShape, Int, Integer, PointeeInfo, Pointer, Size, TyAbiInterface,
Variants, F32, F64,
Variants, F128, F16, F32, F64,
};

use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType};
Expand Down Expand Up @@ -171,7 +171,6 @@ pub trait LayoutGccExt<'tcx> {
cx: &CodegenCx<'gcc, 'tcx>,
index: usize,
) -> Type<'gcc>;
fn gcc_field_index(&self, index: usize) -> u64;
fn pointee_info_at<'gcc>(
&self,
cx: &CodegenCx<'gcc, 'tcx>,
Expand Down Expand Up @@ -284,8 +283,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
match scalar.primitive() {
Int(i, true) => cx.type_from_integer(i),
Int(i, false) => cx.type_from_unsigned_integer(i),
F16 => cx.type_f16(),
F32 => cx.type_f32(),
F64 => cx.type_f64(),
F128 => cx.type_f128(),
Pointer(address_space) => {
// If we know the alignment, pick something better than i8.
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) {
Expand Down Expand Up @@ -327,24 +328,6 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
self.scalar_gcc_type_at(cx, scalar, offset)
}

fn gcc_field_index(&self, index: usize) -> u64 {
match self.abi {
Abi::Scalar(_) | Abi::ScalarPair(..) => {
bug!("TyAndLayout::gcc_field_index({:?}): not applicable", self)
}
_ => {}
}
match self.fields {
FieldsShape::Primitive | FieldsShape::Union(_) => {
bug!("TyAndLayout::gcc_field_index({:?}): not applicable", self)
}

FieldsShape::Array { .. } => index as u64,

FieldsShape::Arbitrary { .. } => 1 + (self.fields.memory_index(index) as u64) * 2,
}
}

fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option<PointeeInfo> {
if let Some(&pointee) = cx.pointee_infos.borrow().get(&(self.ty, offset)) {
return pointee;
Expand Down Expand Up @@ -374,10 +357,6 @@ impl<'gcc, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
layout.is_gcc_scalar_pair()
}

fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64 {
layout.gcc_field_index(index)
}

fn scalar_pair_element_backend_type(
&self,
layout: TyAndLayout<'tcx>,
Expand Down
Loading