On Thu May 1, 2025 at 9:22 AM JST, Joel Fernandes wrote: > Hi Alex, > > On 4/30/2025 8:09 PM, Alexandre Courbot wrote: >>>> I am just not seeing the benefits of not using dyn for >>>> this use case and only drawbacks. IMHO, we should try to not be doing the >>>> compiler's job. >>>> >>>> Maybe the only benefit is you don't need an Arc or Kbox wrapper? >>> That's not a huge concern for me, it's only one single allocation per >>> Engine, >>> correct? >> Correct. Note that for other engines we will be able to store the HALs as >> static singletons instead of building them on the heap like I am >> currently doing. The reason for doing this on falcon is that the >> dual-dimension of the instances makes it more complex to build and look >> them up. >> >> ... or maybe I could just use a macro? Let me try that and see whether >> it works. > > Do you mean a macro for create_falcon_hal which adds an entry to this? > > let hal = match chipset { > Chipset::GA102 | Chipset::GA103 | Chipset::GA104 | Chipset::GA106 > |Chipset::GA107 => { .. } > > > Actually it would be nice if a single macro defined both a chipset and created > the hal together in the above list, that way the definition of a "chipset" is > in > a singe place. Kind of like what I did in the vbios patch for various > BiosImage. > But not sure how easy it is to do for Falcon. > > Or perhaps you meant a macro that statically allocates the Engine + HAL > combination, and avoids need for Arc/KBox and their corresponding allocations?
I was thinking of a macro to create all the Chipset * Engine static instances of HALs, and generate the body of a lookup function to return the right one for a given Chipset at runtime. But trying to write it, I realized it wasn't as easy as I thought since generics cannot be used as macro parameters - i.e. if you have <E: Engine> as a generic and pass `E` to the macro, it will see... `E` and not whatever was bound to `E` when the code is monomorphized (macros are expanded before generics it seems). A solution to that would involve new traits and a bunch of boilerplate, which I have decided is not worth the trouble to save one 8-bytes object on the heap per falcon instance. :) I'll keep things as they currently are for now.