|
|
Subscribe / Log in / New account

Not a big fan of #vtable

Not a big fan of #vtable

Posted Jun 29, 2025 0:18 UTC (Sun) by Cyberax (✭ supporter ✭, #52523)
Parent article: How to write Rust in the kernel: part 2

Hm. I'm not a big fan of #vtable and the autoregistration. The C code with its manual tables was easier to understand.


to post comments

Not a big fan of #vtable

Posted Jun 29, 2025 3:20 UTC (Sun) by iabervon (subscriber, #722) [Link] (4 responses)

I don't think the registration is more automatic than in the C code; the call to module_phy_driver is just at the top of the file instead of at the bottom.

The "impl Driver for PhyAX88772C" thing is the usual way to associate a bunch of functions that are related together in Rust with what they're used for, and the odd "#[vtable]" thing is just making the idiomatic Rust code produce what the C code needs.

Not a big fan of #vtable

Posted Jun 29, 2025 3:23 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (3 responses)

What will happen if I mis-spell `resume` as `resum`? I haven't checked the macro source, but I think it'll just silently ignore this function?

Not a big fan of #vtable

Posted Jun 29, 2025 3:56 UTC (Sun) by iabervon (subscriber, #722) [Link] (2 responses)

That'll produce an error even before you get to the macro; you can't put anything in "impl Driver for Something" that isn't part of the Driver trait.

Not a big fan of #vtable

Posted Jun 29, 2025 7:31 UTC (Sun) by tialaramex (subscriber, #21167) [Link]

Indeed there's an opportunity (at least as of the nightly on Compiler Explorer) for a small diagnostic improvement

error[E0407]: method `resum` is not a member of trait `Driver`

... but it has no suggestions for how to fix this, whereas in some other contexts it looks for similar symbols and would have suggested we meant `resume` instead, meaning it spells out what we got wrong.

In my experience improving error diagnostics in rustc is very achievable for a person who has some Rust but maybe isn't yet comfortable writing scary bit-banging code with it, and it's a huge confidence boost when the tests pass (rustc has lots of tests for this stuff) and the reviewers send your work to be integrated into a future compiler version. Unlike fiddling with a hardware driver, no reboots are required and people don't need identical hardware to test it.

Not a big fan of #vtable

Posted Jun 29, 2025 9:02 UTC (Sun) by NYKevin (subscriber, #129325) [Link]

Before anyone asks: You also cannot omit any item that the trait declares, unless the trait provides a (default) definition. Otherwise, the implementation is considered incomplete and you get a compile error.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds