Skip to content

Commit 239cf98

Browse files
authored
Merge pull request #2648 from rust-lang/rustc-pull
Rustc pull update
2 parents 8564d67 + a76d78b commit 239cf98

File tree

35 files changed

+588
-118
lines changed

35 files changed

+588
-118
lines changed

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
codegen_llvm_autodiff_without_enable = using the autodiff feature requires -Z autodiff=Enable
2+
codegen_llvm_autodiff_without_lto = using the autodiff feature requires setting `lto="fat"` in your Cargo.toml
23
34
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
45

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
3232
}
3333
}
3434

35+
#[derive(Diagnostic)]
36+
#[diag(codegen_llvm_autodiff_without_lto)]
37+
pub(crate) struct AutoDiffWithoutLto;
38+
3539
#[derive(Diagnostic)]
3640
#[diag(codegen_llvm_autodiff_without_enable)]
3741
pub(crate) struct AutoDiffWithoutEnable;

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::abi::FnAbiLlvmExt;
2525
use crate::builder::Builder;
2626
use crate::builder::autodiff::{adjust_activity_to_abi, generate_enzyme_call};
2727
use crate::context::CodegenCx;
28-
use crate::errors::AutoDiffWithoutEnable;
28+
use crate::errors::{AutoDiffWithoutEnable, AutoDiffWithoutLto};
2929
use crate::llvm::{self, Metadata, Type, Value};
3030
use crate::type_of::LayoutLlvmExt;
3131
use crate::va_arg::emit_va_arg;
@@ -378,8 +378,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
378378
| sym::ctpop
379379
| sym::bswap
380380
| sym::bitreverse
381-
| sym::rotate_left
382-
| sym::rotate_right
383381
| sym::saturating_add
384382
| sym::saturating_sub
385383
| sym::unchecked_funnel_shl
@@ -424,19 +422,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
424422
sym::bitreverse => {
425423
self.call_intrinsic("llvm.bitreverse", &[llty], &[args[0].immediate()])
426424
}
427-
sym::rotate_left
428-
| sym::rotate_right
429-
| sym::unchecked_funnel_shl
430-
| sym::unchecked_funnel_shr => {
431-
let is_left = name == sym::rotate_left || name == sym::unchecked_funnel_shl;
425+
sym::unchecked_funnel_shl | sym::unchecked_funnel_shr => {
426+
let is_left = name == sym::unchecked_funnel_shl;
432427
let lhs = args[0].immediate();
433-
let (rhs, raw_shift) =
434-
if name == sym::rotate_left || name == sym::rotate_right {
435-
// rotate = funnel shift with first two args the same
436-
(lhs, args[1].immediate())
437-
} else {
438-
(args[1].immediate(), args[2].immediate())
439-
};
428+
let rhs = args[1].immediate();
429+
let raw_shift = args[2].immediate();
440430
let llvm_name = format!("llvm.fsh{}", if is_left { 'l' } else { 'r' });
441431

442432
// llvm expects shift to be the same type as the values, but rust
@@ -1146,6 +1136,9 @@ fn codegen_autodiff<'ll, 'tcx>(
11461136
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
11471137
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
11481138
}
1139+
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
1140+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1141+
}
11491142

11501143
let fn_args = instance.args;
11511144
let callee_ty = instance.ty(tcx, bx.typing_env());

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
333333
let r = self.read_immediate(&args[1])?;
334334
self.exact_div(&l, &r, dest)?;
335335
}
336-
sym::rotate_left | sym::rotate_right => {
337-
// rotate_left: (X << (S % BW)) | (X >> ((BW - S) % BW))
338-
// rotate_right: (X << ((BW - S) % BW)) | (X >> (S % BW))
339-
let layout_val = self.layout_of(instance_args.type_at(0))?;
340-
let val = self.read_scalar(&args[0])?;
341-
let val_bits = val.to_bits(layout_val.size)?; // sign is ignored here
342-
343-
let layout_raw_shift = self.layout_of(self.tcx.types.u32)?;
344-
let raw_shift = self.read_scalar(&args[1])?;
345-
let raw_shift_bits = raw_shift.to_bits(layout_raw_shift.size)?;
346-
347-
let width_bits = u128::from(layout_val.size.bits());
348-
let shift_bits = raw_shift_bits % width_bits;
349-
let inv_shift_bits = (width_bits - shift_bits) % width_bits;
350-
let result_bits = if intrinsic_name == sym::rotate_left {
351-
(val_bits << shift_bits) | (val_bits >> inv_shift_bits)
352-
} else {
353-
(val_bits >> shift_bits) | (val_bits << inv_shift_bits)
354-
};
355-
let truncated_bits = layout_val.size.truncate(result_bits);
356-
let result = Scalar::from_uint(truncated_bits, layout_val.size);
357-
self.write_scalar(result, dest)?;
358-
}
359336
sym::copy => {
360337
self.copy_intrinsic(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
361338
}

compiler/rustc_session/src/session.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,6 @@ impl Session {
594594

595595
/// Calculates the flavor of LTO to use for this compilation.
596596
pub fn lto(&self) -> config::Lto {
597-
// Autodiff currently requires fat-lto to have access to the llvm-ir of all (indirectly) used functions and types.
598-
// fat-lto is the easiest solution to this requirement, but quite expensive.
599-
// FIXME(autodiff): Make autodiff also work with embed-bc instead of fat-lto.
600-
// Don't apply fat-lto to proc-macro crates as they cannot use fat-lto without -Zdylib-lto
601-
if self.opts.autodiff_enabled() && !self.opts.crate_types.contains(&CrateType::ProcMacro) {
602-
return config::Lto::Fat;
603-
}
604-
605597
// If our target has codegen requirements ignore the command line
606598
if self.target.requires_lto {
607599
return config::Lto::Fat;

compiler/rustc_target/src/spec/base/motor.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ use crate::spec::{
44

55
pub(crate) fn opts() -> TargetOptions {
66
let pre_link_args = TargetOptions::link_args(
7-
LinkerFlavor::Gnu(Cc::No, Lld::No),
8-
&[
9-
"-e",
10-
"motor_start",
11-
"--no-undefined",
12-
"--error-unresolved-symbols",
13-
"--no-undefined-version",
14-
"-u",
15-
"__rust_abort",
16-
],
7+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
8+
&["-e", "motor_start", "-u", "__rust_abort"],
179
);
1810
TargetOptions {
1911
os: Os::Motor,
@@ -23,7 +15,7 @@ pub(crate) fn opts() -> TargetOptions {
2315
// We use "OS level" TLS (see thread/local.rs in stdlib).
2416
has_thread_local: false,
2517
frame_pointer: FramePointer::NonLeaf,
26-
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No),
18+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
2719
main_needs_argc_argv: true,
2820
panic_strategy: PanicStrategy::Abort,
2921
pre_link_args,

compiler/rustc_target/src/spec/targets/x86_64_unknown_motor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::{
2-
Arch, CodeModel, LinkSelfContainedDefault, LldFlavor, RelocModel, RelroLevel, Target, base,
2+
Arch, CodeModel, LinkSelfContainedDefault, RelocModel, RelroLevel, Target, base,
33
};
44

55
pub(crate) fn target() -> Target {
@@ -15,7 +15,6 @@ pub(crate) fn target() -> Target {
1515
base.relro_level = RelroLevel::Full;
1616
base.static_position_independent_executables = true;
1717
base.relocation_model = RelocModel::Pic;
18-
base.lld_flavor_json = LldFlavor::Ld;
1918
base.link_self_contained = LinkSelfContainedDefault::True;
2019
base.dynamic_linking = false;
2120
base.crt_static_default = true;

library/core/src/intrinsics/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
use crate::ffi::va_list::{VaArgSafe, VaListImpl};
5858
use crate::marker::{ConstParamTy, Destruct, DiscriminantKind, PointeeSized, Tuple};
59-
use crate::ptr;
59+
use crate::{mem, ptr};
6060

6161
mod bounds;
6262
pub mod fallback;
@@ -2013,7 +2013,14 @@ pub const unsafe fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
20132013
#[rustc_intrinsic_const_stable_indirect]
20142014
#[rustc_nounwind]
20152015
#[rustc_intrinsic]
2016-
pub const fn rotate_left<T: Copy>(x: T, shift: u32) -> T;
2016+
#[rustc_allow_const_fn_unstable(const_trait_impl, funnel_shifts)]
2017+
#[miri::intrinsic_fallback_is_spec]
2018+
pub const fn rotate_left<T: [const] fallback::FunnelShift>(x: T, shift: u32) -> T {
2019+
// Make sure to call the intrinsic for `funnel_shl`, not the fallback impl.
2020+
// SAFETY: we modulo `shift` so that the result is definitely less than the size of
2021+
// `T` in bits.
2022+
unsafe { unchecked_funnel_shl(x, x, shift % (mem::size_of::<T>() as u32 * 8)) }
2023+
}
20172024

20182025
/// Performs rotate right.
20192026
///
@@ -2028,7 +2035,14 @@ pub const fn rotate_left<T: Copy>(x: T, shift: u32) -> T;
20282035
#[rustc_intrinsic_const_stable_indirect]
20292036
#[rustc_nounwind]
20302037
#[rustc_intrinsic]
2031-
pub const fn rotate_right<T: Copy>(x: T, shift: u32) -> T;
2038+
#[rustc_allow_const_fn_unstable(const_trait_impl, funnel_shifts)]
2039+
#[miri::intrinsic_fallback_is_spec]
2040+
pub const fn rotate_right<T: [const] fallback::FunnelShift>(x: T, shift: u32) -> T {
2041+
// Make sure to call the intrinsic for `funnel_shr`, not the fallback impl.
2042+
// SAFETY: we modulo `shift` so that the result is definitely less than the size of
2043+
// `T` in bits.
2044+
unsafe { unchecked_funnel_shr(x, x, shift % (mem::size_of::<T>() as u32 * 8)) }
2045+
}
20322046

20332047
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
20342048
///

library/core/src/mem/manually_drop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ impl<T> ManuallyDrop<T> {
217217
///
218218
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
219219
#[stable(feature = "manually_drop_take", since = "1.42.0")]
220+
#[rustc_const_unstable(feature = "const_manually_drop_take", issue = "148773")]
220221
#[inline]
221-
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
222+
pub const unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
222223
// SAFETY: we are reading from a reference, which is guaranteed
223224
// to be valid for reads.
224225
unsafe { ptr::read(&slot.value) }

library/core/src/mem/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ pub const fn swap<T>(x: &mut T, y: &mut T) {
808808
/// ```
809809
#[inline]
810810
#[stable(feature = "mem_take", since = "1.40.0")]
811-
pub fn take<T: Default>(dest: &mut T) -> T {
811+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
812+
pub const fn take<T: [const] Default>(dest: &mut T) -> T {
812813
replace(dest, T::default())
813814
}
814815

0 commit comments

Comments
 (0)