Re: [PATCH 2/2] rust: drm: Add GPUVM abstraction
From: Benno Lossin
Date: Mon Mar 24 2025 - 16:24:15 EST
On Mon Mar 24, 2025 at 8:25 PM CET, Daniel Almeida wrote:
>> On 24 Mar 2025, at 14:36, Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>>
>> Hi Daniel,
>>
>> A few quick notes for future versions on style/docs to try to keep
>> things consistent upstream -- not an actual review.
>>
>> On Mon, Mar 24, 2025 at 4:14 PM Daniel Almeida
>> <daniel.almeida@xxxxxxxxxxxxx> wrote:
>>>
>>> +#[allow(type_alias_bounds)]
>>
>> The documentation says this is highly discouraged -- it may be good to
>> mention why it is OK in this instance in a comment or similar.
>
> Someone correct me here, but I see no issue with this warning. That’s
> because we need the bound to make `<T::Driver as drv::Driver>` work in the
> first place. Otherwise, we’d get a compiler error saying that there’s
> no `Driver` associated type (assuming the case where a random T gets
> passed in)
>
> So, for this to be a problem, we would need to mix this up with something that
> also has a `Driver` associated type, and this associated type would also need a
> drv::Driver bound.
>
> In other words, we would need a lot of things to align for this to actually
> have a chance of being misused. When you consider that this is then only used
> in a few places, the balance tips heavily in favor of the convenience of having
> the type alias IMHO.
>
> In fact, the docs point to the exact thing I am trying to do, i.e.:
>
>> these bounds may have secondary effects such as enabling the use of “shorthand” associated type paths
>
>> I.e., paths of the form T::Assoc where T is a type parameter bounded by trait Trait which defines an associated type called Assoc as opposed to a fully qualified path of the form <T as Trait>::Assoc.
You can avoid the allow by using:
type DriverObject<T> = <<T as DriverGpuVm>::Driver as drv::Driver>::Object;
That is more wordy, but avoids the allow (it still errors when you put
in something that doesn't implement `DriverGpuVm`).
---
Cheers,
Benno