Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
return Ok(());
}

sym::amdgpu_dispatch_ptr => {
let val = self.call_intrinsic("llvm.amdgcn.dispatch.ptr", &[], &[]);
// Relying on `LLVMBuildPointerCast` to produce an addrspacecast
self.pointercast(val, self.type_ptr())
}

_ if name.as_str().starts_with("simd_") => {
// Unpack non-power-of-2 #[repr(packed, simd)] arguments.
// This gives them the expected layout of a regular #[repr(simd)] vector.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
| sym::unreachable
| sym::cold_path
| sym::breakpoint
| sym::amdgpu_dispatch_ptr
| sym::assert_zero_valid
| sym::assert_mem_uninitialized_valid
| sym::assert_inhabited
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4525,6 +4525,26 @@ impl ItemKind<'_> {
_ => return None,
})
}

pub fn recovered(&self) -> bool {
match self {
ItemKind::Struct(
_,
_,
VariantData::Struct { recovered: ast::Recovered::Yes(_), .. },
) => true,
ItemKind::Union(
_,
_,
VariantData::Struct { recovered: ast::Recovered::Yes(_), .. },
) => true,
ItemKind::Enum(_, _, def) => def.variants.iter().any(|v| match v.data {
VariantData::Struct { recovered: ast::Recovered::Yes(_), .. } => true,
_ => false,
}),
_ => false,
}
}
}

// The bodies for items are stored "out of line", in a separate
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
| sym::add_with_overflow
| sym::aggregate_raw_ptr
| sym::align_of
| sym::amdgpu_dispatch_ptr
| sym::assert_inhabited
| sym::assert_mem_uninitialized_valid
| sym::assert_zero_valid
Expand Down Expand Up @@ -286,6 +287,7 @@ pub(crate) fn check_intrinsic_type(
let (n_tps, n_cts, inputs, output) = match intrinsic_name {
sym::autodiff => (4, 0, vec![param(0), param(1), param(2)], param(3)),
sym::abort => (0, 0, vec![], tcx.types.never),
sym::amdgpu_dispatch_ptr => (0, 0, vec![], Ty::new_imm_ptr(tcx, tcx.types.unit)),
sym::unreachable => (0, 0, vec![], tcx.types.never),
sym::breakpoint => (0, 0, vec![], tcx.types.unit),
sym::size_of | sym::align_of | sym::variant_count => (1, 0, vec![], tcx.types.usize),
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,12 @@ fn report_bivariance<'tcx>(
const_param_help,
});
diag.code(E0392);
diag.emit()
if item.kind.recovered() {
// Silence potentially redundant error, as the item had a parse error.
diag.delay_as_bug()
} else {
diag.emit()
}
}

/// Detects cases where an ADT/LTA is trivially cyclical -- we want to detect this so
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ symbols! {
alu32,
always,
amdgpu,
amdgpu_dispatch_ptr,
analysis,
and,
and_then,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,30 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}

let Some(InferSource { span, kind }) = local_visitor.infer_source else {
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
let silence = if let DefKind::AssocFn = self.tcx.def_kind(body_def_id)
&& let parent = self.tcx.parent(body_def_id.into())
&& self.tcx.is_automatically_derived(parent)
&& let Some(parent) = parent.as_local()
&& let hir::Node::Item(item) = self.tcx.hir_node_by_def_id(parent)
&& let hir::ItemKind::Impl(imp) = item.kind
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = imp.self_ty.kind
&& let Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, def_id) = path.res
&& let Some(def_id) = def_id.as_local()
&& let hir::Node::Item(item) = self.tcx.hir_node_by_def_id(def_id)
{
// We have encountered an inference error within an automatically derived `impl`,
// from a `#[derive(..)]` on an item that had a parse error. Because the parse
// error might have caused the expanded code to be malformed, we silence the
// inference error.
item.kind.recovered()
} else {
false
};
let mut err = self.bad_inference_failure_err(failure_span, arg_data, error_code);
if silence {
err.downgrade_to_delayed_bug();
}
return err;
};

let (source_kind, name, long_ty_path) = kind.ty_localized_msg(self);
Expand Down
23 changes: 23 additions & 0 deletions library/core/src/intrinsics/gpu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Intrinsics for GPU targets.
//!
//! Intrinsics in this module are intended for use on GPU targets.
//! They can be target specific but in general GPU targets are similar.

#![unstable(feature = "gpu_intrinsics", issue = "none")]

/// Returns a pointer to the HSA kernel dispatch packet.
///
/// A `gpu-kernel` on amdgpu is always launched through a kernel dispatch packet.
/// The dispatch packet contains the workgroup size, launch size and other data.
/// The content is defined by the [HSA Platform System Architecture Specification],
/// which is implemented e.g. in AMD's [hsa.h].
/// The intrinsic returns a unit pointer so that rustc does not need to know the packet struct.
/// The pointer is valid for the whole lifetime of the program.
///
/// [HSA Platform System Architecture Specification]: https://hsafoundation.com/wp-content/uploads/2021/02/HSA-SysArch-1.2.pdf
/// [hsa.h]: https://github.com/ROCm/rocm-systems/blob/rocm-7.1.0/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h#L2959
#[rustc_nounwind]
#[rustc_intrinsic]
#[cfg(target_arch = "amdgpu")]
#[must_use = "returns a pointer that does nothing unless used"]
pub fn amdgpu_dispatch_ptr() -> *const ();
1 change: 1 addition & 0 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use crate::{mem, ptr};

mod bounds;
pub mod fallback;
pub mod gpu;
pub mod mir;
pub mod simd;

Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ pub mod consts {

/// The golden ratio (φ)
#[unstable(feature = "f128", issue = "116909")]
// Also, #[unstable(feature = "more_float_constants", issue = "146939")]
pub const PHI: f128 = 1.61803398874989484820458683436563811772030917980576286213545_f128;
pub const GOLDEN_RATIO: f128 =
1.61803398874989484820458683436563811772030917980576286213545_f128;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "f128", issue = "116909")]
// Also, #[unstable(feature = "more_float_constants", issue = "146939")]
pub const EGAMMA: f128 = 0.577215664901532860606512090082402431042159335939923598805767_f128;
pub const EULER_GAMMA: f128 =
0.577215664901532860606512090082402431042159335939923598805767_f128;

/// π/2
#[unstable(feature = "f128", issue = "116909")]
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ pub mod consts {

/// The golden ratio (φ)
#[unstable(feature = "f16", issue = "116909")]
// Also, #[unstable(feature = "more_float_constants", issue = "146939")]
pub const PHI: f16 = 1.618033988749894848204586834365638118_f16;
pub const GOLDEN_RATIO: f16 = 1.618033988749894848204586834365638118_f16;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "f16", issue = "116909")]
// Also, #[unstable(feature = "more_float_constants", issue = "146939")]
pub const EGAMMA: f16 = 0.577215664901532860606512090082402431_f16;
pub const EULER_GAMMA: f16 = 0.577215664901532860606512090082402431_f16;

/// π/2
#[unstable(feature = "f16", issue = "116909")]
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ pub mod consts {
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;

/// The golden ratio (φ)
#[unstable(feature = "more_float_constants", issue = "146939")]
pub const PHI: f32 = 1.618033988749894848204586834365638118_f32;
#[stable(feature = "euler_gamma_golden_ratio", since = "CURRENT_RUSTC_VERSION")]
pub const GOLDEN_RATIO: f32 = 1.618033988749894848204586834365638118_f32;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "more_float_constants", issue = "146939")]
pub const EGAMMA: f32 = 0.577215664901532860606512090082402431_f32;
#[stable(feature = "euler_gamma_golden_ratio", since = "CURRENT_RUSTC_VERSION")]
pub const EULER_GAMMA: f32 = 0.577215664901532860606512090082402431_f32;

/// π/2
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ pub mod consts {
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;

/// The golden ratio (φ)
#[unstable(feature = "more_float_constants", issue = "146939")]
pub const PHI: f64 = 1.618033988749894848204586834365638118_f64;
#[stable(feature = "euler_gamma_golden_ratio", since = "CURRENT_RUSTC_VERSION")]
pub const GOLDEN_RATIO: f64 = 1.618033988749894848204586834365638118_f64;

/// The Euler-Mascheroni constant (γ)
#[unstable(feature = "more_float_constants", issue = "146939")]
pub const EGAMMA: f64 = 0.577215664901532860606512090082402431_f64;
#[stable(feature = "euler_gamma_golden_ratio", since = "CURRENT_RUSTC_VERSION")]
pub const EULER_GAMMA: f64 = 0.577215664901532860606512090082402431_f64;

/// π/2
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
50 changes: 0 additions & 50 deletions library/coretests/tests/floats/f128.rs

This file was deleted.

35 changes: 0 additions & 35 deletions library/coretests/tests/floats/f16.rs

This file was deleted.

78 changes: 75 additions & 3 deletions library/coretests/tests/floats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ macro_rules! float_test {
};
}

mod f128;
mod f16;

float_test! {
name: num,
attrs: {
Expand Down Expand Up @@ -1582,3 +1579,78 @@ float_test! {
assert_biteq!((flt(-3.2)).mul_add(2.4, neg_inf), neg_inf);
}
}

float_test! {
name: from,
attrs: {
f16: #[cfg(any(miri, target_has_reliable_f16))],
f128: #[cfg(any(miri, target_has_reliable_f128))],
},
test<Float> {
assert_biteq!(Float::from(false), Float::ZERO);
assert_biteq!(Float::from(true), Float::ONE);

assert_biteq!(Float::from(u8::MIN), Float::ZERO);
assert_biteq!(Float::from(42_u8), 42.0);
assert_biteq!(Float::from(u8::MAX), 255.0);

assert_biteq!(Float::from(i8::MIN), -128.0);
assert_biteq!(Float::from(42_i8), 42.0);
assert_biteq!(Float::from(i8::MAX), 127.0);
}
}

float_test! {
name: from_u16_i16,
attrs: {
f16: #[cfg(false)],
const f16: #[cfg(false)],
f128: #[cfg(any(miri, target_has_reliable_f128))],
},
test<Float> {
assert_biteq!(Float::from(u16::MIN), Float::ZERO);
assert_biteq!(Float::from(42_u16), 42.0);
assert_biteq!(Float::from(u16::MAX), 65535.0);
assert_biteq!(Float::from(i16::MIN), -32768.0);
assert_biteq!(Float::from(42_i16), 42.0);
assert_biteq!(Float::from(i16::MAX), 32767.0);
}
}

float_test! {
name: from_u32_i32,
attrs: {
f16: #[cfg(false)],
const f16: #[cfg(false)],
f32: #[cfg(false)],
const f32: #[cfg(false)],
f128: #[cfg(any(miri, target_has_reliable_f128))],
},
test<Float> {
assert_biteq!(Float::from(u32::MIN), Float::ZERO);
assert_biteq!(Float::from(42_u32), 42.0);
assert_biteq!(Float::from(u32::MAX), 4294967295.0);
assert_biteq!(Float::from(i32::MIN), -2147483648.0);
assert_biteq!(Float::from(42_i32), 42.0);
assert_biteq!(Float::from(i32::MAX), 2147483647.0);
}
}

// FIXME(f16_f128): Uncomment and adapt these tests once the From<{u64,i64}> impls are added.
// float_test! {
// name: from_u64_i64,
// attrs: {
// f16: #[cfg(false)],
// f32: #[cfg(false)],
// f64: #[cfg(false)],
// f128: #[cfg(any(miri, target_has_reliable_f128))],
// },
// test<Float> {
// assert_biteq!(Float::from(u64::MIN), Float::ZERO);
// assert_biteq!(Float::from(42_u64), 42.0);
// assert_biteq!(Float::from(u64::MAX), 18446744073709551615.0);
// assert_biteq!(Float::from(i64::MIN), -9223372036854775808.0);
// assert_biteq!(Float::from(42_i64), 42.0);
// assert_biteq!(Float::from(i64::MAX), 9223372036854775807.0);
// }
// }
Loading
Loading