Re: [PATCH 1/2] rust: sizes: add u64 variants of SZ_* constants
From: Danilo Krummrich
Date: Tue Mar 10 2026 - 12:53:22 EST
On Tue Mar 10, 2026 at 2:51 PM CET, Miguel Ojeda wrote:
> On Tue, Mar 10, 2026 at 3:31 AM John Hubbard <jhubbard@xxxxxxxxxx> wrote:
>>
>> +// CAST: every SZ_* value below fits in u64, so `as u64` is always lossless.
>
> Nit:
>
> // CAST: Every `SZ_*` value below fits in `u64`, so `as u64` is
> always lossless.
>
> One alternative could be something like `sizes::u64::SZ_1M`, but if
> you expect to mix `usize` and `u64` often then it may not be great.
I have a slight preference towards this. It also shoudn't be that bad if we need
both, as we could just keep the prefix, i.e. u64::SZ_1M.
> Regarding adding the constants or not, I am ambivalent. On one hand, I
> see the pain of repeating it; on the other hand, adding these only
> works for particular values (i.e. we still need the safe casts around
> anyway for other values).
In a lot of cases we won't need to go back and forth with those values, as all
of the DRM infrastructure works with u64. So, there'd be quite a lot of overhead
if everytime we want to initialize something in GPUVM, GPU Buddy, TTM, etc. with
one of the SZ_* constants, i.e. we'd need to repeat u64::from_safe_cast(SZ_*)
over and over again. This is the main reason why I proposed to have u64 variants
in the first place.
Technically, if they are not needed for anything else, we could also make them
GPU infrastructure, e.g. gpu::SZ_*. Additionally, we could have GPU specific
usize and isize types.