Skip to content

Conversation

usamoi
Copy link
Contributor

@usamoi usamoi commented Jun 2, 2025

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Jun 2, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 2, 2025
@rustbot

This comment has been minimized.

fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 {
match typ.kind() {
ty::Float(FloatTy::F32) => 23,
ty::Float(FloatTy::F64) | ty::Infer(InferTy::FloatVar(_)) => 52,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty::Infer(InferTy::FloatVar(_)) => 52 should be unnecessary, is that right?

Comment on lines +6 to +26
pub(super) fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 {
match typ.kind() {
ty::Int(i) => match i {
IntTy::Isize => tcx.data_layout.pointer_size.bits(),
IntTy::I8 => 8,
IntTy::I16 => 16,
IntTy::I32 => 32,
IntTy::I64 => 64,
IntTy::I128 => 128,
},
ty::Uint(i) => match i {
UintTy::Usize => tcx.data_layout.pointer_size.bits(),
UintTy::U8 => 8,
UintTy::U16 => 16,
UintTy::U32 => 32,
UintTy::U64 => 64,
UintTy::U128 => 128,
},
_ => unreachable!(),
}
}
Copy link
Member

@samueltardieu samueltardieu Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are reverting (here and at other places) changes that were committed yesterday. Please don't do that. And please explain what your PR is doing, what it fixes, why it is necessary, and when you change existing things why your solution is better than the one in place. For example, why would panicking (through unreachable!()) be best than returning None here? The Option version lets us check if this is an integral type at the same time, which is almost always necessary from the caller point of view anyway. Also, it is shorter by using i.bit_width() rather than hard-coding every case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to your approach, how can we make use of int_ty_to_nbits, float_ty_to_nbits, and float_ty_to_mantissa_nbits at the same time? Should all three return Option, and then handle the None cases externally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you're trying to achieve, so this is a difficult question to answer.

@usamoi usamoi closed this Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants