Skip to content
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

remove pref_align_of intrinsic #90877

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
dest.write_cvalue(fx, val);
};

pref_align_of | needs_drop | type_id | type_name | variant_count, () {
needs_drop | type_id | type_name | variant_count, () {
let const_val =
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
let val = crate::constant::codegen_const_value(
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.const_usize(bx.layout_of(tp_ty).align.abi.bytes())
}
}
sym::pref_align_of
| sym::needs_drop
| sym::type_id
| sym::type_name
| sym::variant_count => {
sym::needs_drop | sym::type_id | sym::type_name | sym::variant_count => {
let value = bx
.tcx()
.const_eval_instance(ty::ParamEnv::reveal_all(), instance, None)
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ crate fn eval_nullary_intrinsic<'tcx>(
ensure_monomorphic_enough(tcx, tp_ty)?;
ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env))
}
sym::pref_align_of => {
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
ConstValue::from_machine_usize(layout.align.pref.bytes(), &tcx)
}
sym::type_id => {
ensure_monomorphic_enough(tcx, tp_ty)?;
ConstValue::from_u64(tcx.type_id_hash(tp_ty))
Expand Down Expand Up @@ -155,14 +150,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.write_scalar(Scalar::from_machine_usize(result, self), dest)?;
}

sym::pref_align_of
| sym::needs_drop
| sym::type_id
| sym::type_name
| sym::variant_count => {
sym::needs_drop | sym::type_id | sym::type_name | sym::variant_count => {
let gid = GlobalId { instance, promoted: None };
let ty = match intrinsic_name {
sym::pref_align_of | sym::variant_count => self.tcx.types.usize,
sym::variant_count => self.tcx.types.usize,
sym::needs_drop => self.tcx.types.bool,
sym::type_id => self.tcx.types.u64,
sym::type_name => self.tcx.mk_static_str(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,6 @@ symbols! {
pre_dash_lto: "pre-lto",
precise_pointer_size_matching,
precision,
pref_align_of,
prefetch_read_data,
prefetch_read_instruction,
prefetch_write_data,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::abort => (0, Vec::new(), tcx.types.never),
sym::unreachable => (0, Vec::new(), tcx.types.never),
sym::breakpoint => (0, Vec::new(), tcx.mk_unit()),
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
sym::size_of | sym::min_align_of | sym::variant_count => {
(1, Vec::new(), tcx.types.usize)
}
sym::size_of_val | sym::min_align_of_val => {
Expand Down
5 changes: 0 additions & 5 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,6 @@ extern "rust-intrinsic" {
/// The stabilized version of this intrinsic is [`core::mem::align_of`].
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
pub fn min_align_of<T>() -> usize;
/// The preferred alignment of a type.
///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
pub fn pref_align_of<T>() -> usize;

/// The size of the referenced value in bytes.
///
Expand Down
21 changes: 4 additions & 17 deletions src/test/ui/intrinsics/intrinsic-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
pub fn min_align_of<T>() -> usize;
}
}
Expand All @@ -25,39 +24,27 @@ mod rusti {
mod m {
#[cfg(target_arch = "x86")]
pub fn main() {
unsafe {
assert_eq!(::rusti::pref_align_of::<u64>(), 8);
assert_eq!(::rusti::min_align_of::<u64>(), 4);
}
assert_eq!(::rusti::min_align_of::<u64>(), 4);
}

#[cfg(not(target_arch = "x86"))]
pub fn main() {
unsafe {
assert_eq!(::rusti::pref_align_of::<u64>(), 8);
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
}

#[cfg(target_env = "sgx")]
mod m {
#[cfg(target_arch = "x86_64")]
pub fn main() {
unsafe {
assert_eq!(::rusti::pref_align_of::<u64>(), 8);
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
}

#[cfg(target_os = "windows")]
mod m {
pub fn main() {
unsafe {
assert_eq!(::rusti::pref_align_of::<u64>(), 8);
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
assert_eq!(::rusti::min_align_of::<u64>(), 8);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/structs-enums/rec-align-u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::mem;

mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
pub fn min_align_of<T>() -> usize;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/structs-enums/rec-align-u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::mem;

mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
pub fn min_align_of<T>() -> usize;
}
}
Expand Down