-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Introduce NullOp::AlignOf #88839
Introduce NullOp::AlignOf #88839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -487,20 +487,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |||||
) | ||||||
} | ||||||
|
||||||
mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => { | ||||||
let ty = self.monomorphize(ty); | ||||||
assert!(bx.cx().type_is_sized(ty)); | ||||||
let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes()); | ||||||
let tcx = self.cx.tcx(); | ||||||
( | ||||||
bx, | ||||||
OperandRef { | ||||||
val: OperandValue::Immediate(val), | ||||||
layout: self.cx.layout_of(tcx.types.usize), | ||||||
}, | ||||||
) | ||||||
} | ||||||
|
||||||
mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => { | ||||||
let content_ty = self.monomorphize(content_ty); | ||||||
let content_layout = bx.cx().layout_of(content_ty); | ||||||
|
@@ -525,6 +511,27 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |||||
let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout }; | ||||||
(bx, operand) | ||||||
} | ||||||
|
||||||
mir::Rvalue::NullaryOp(null_op, ty) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let ty = self.monomorphize(ty); | ||||||
assert!(bx.cx().type_is_sized(ty)); | ||||||
let layout = bx.cx().layout_of(ty); | ||||||
let val = match null_op { | ||||||
mir::NullOp::SizeOf => layout.size.bytes(), | ||||||
mir::NullOp::AlignOf => layout.align.abi.bytes(), | ||||||
mir::NullOp::Box => unreachable!(), | ||||||
}; | ||||||
let val = bx.cx().const_usize(val); | ||||||
let tcx = self.cx.tcx(); | ||||||
( | ||||||
bx, | ||||||
OperandRef { | ||||||
val: OperandValue::Immediate(val), | ||||||
layout: self.cx.layout_of(tcx.types.usize), | ||||||
}, | ||||||
) | ||||||
} | ||||||
|
||||||
mir::Rvalue::ThreadLocalRef(def_id) => { | ||||||
assert!(bx.cx().tcx().is_static(def_id)); | ||||||
let static_ = bx.get_static(def_id); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,18 +270,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
M::box_alloc(self, &dest)?; | ||
} | ||
|
||
NullaryOp(mir::NullOp::SizeOf, ty) => { | ||
NullaryOp(null_op, ty) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please match There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about change the _ arm below matching null_op to a NullOp::Box arm instead? This way we still get exhaustive match and is IMO cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong opinion either way. |
||
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty); | ||
let layout = self.layout_of(ty)?; | ||
if layout.is_unsized() { | ||
// FIXME: This should be a span_bug (#80742) | ||
self.tcx.sess.delay_span_bug( | ||
self.frame().current_span(), | ||
&format!("SizeOf nullary MIR operator called for unsized type {}", ty), | ||
&format!("Nullary MIR operator called for unsized type {}", ty), | ||
); | ||
throw_inval!(SizeOfUnsizedType(ty)); | ||
} | ||
self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), &dest)?; | ||
let val = match null_op { | ||
mir::NullOp::SizeOf => layout.size.bytes(), | ||
mir::NullOp::AlignOf => layout.align.abi.bytes(), | ||
mir::NullOp::Box => unreachable!(), | ||
}; | ||
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?; | ||
} | ||
|
||
Cast(cast_kind, ref operand, cast_ty) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2278,6 +2278,8 @@ impl BinOp { | |
pub enum NullOp { | ||
/// Returns the size of a value of that type | ||
SizeOf, | ||
/// Returns the minimum alignment of a type | ||
AlignOf, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that preferred alignment is never used in the library and hardly used in the compiler (in fact the only usage of preferred alignment is in cg_clif), and the name we expose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, indeed. Should we remove preferred alignment then if it isn't used anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah it might be time to remove that intrinsic... @eddyb or do you think that will ever be useful again in the future? |
||
/// Creates a new uninitialized box for a value of that type | ||
Box, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- // MIR for `align_of` before LowerIntrinsics | ||
+ // MIR for `align_of` after LowerIntrinsics | ||
|
||
fn align_of() -> usize { | ||
let mut _0: usize; // return place in scope 0 at $DIR/lower_intrinsics.rs:18:25: 18:30 | ||
|
||
bb0: { | ||
- _0 = std::intrinsics::min_align_of::<T>() -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:42 | ||
- // mir::Constant | ||
- // + span: $DIR/lower_intrinsics.rs:19:5: 19:40 | ||
- // + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::min_align_of::<T>}, val: Value(Scalar(<ZST>)) } | ||
+ _0 = AlignOf(T); // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:42 | ||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:42 | ||
} | ||
|
||
bb1: { | ||
return; // scope 0 at $DIR/lower_intrinsics.rs:20:2: 20:2 | ||
} | ||
|
||
bb2 (cleanup): { | ||
resume; // scope 0 at $DIR/lower_intrinsics.rs:18:1: 20:2 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.