rust: pin-init: create self references safely
Status from this message: Applied to pin-init-next. Thanks all!
Get series with b4
b4 am [email protected] change-id 20261006-dev-selfref-27c37abfa849Versions newest first
- v2 Latest20 patches 2 repliesApplied
- v120 patches 2 repliesSuperseded
Changes in v2 from the cover letter
- Add where bounds to covariance check (Sashiko)
- Use NotVisible mechanism for with_project_ref instead of filtering (Sashiko)
- Drop pub from SelfRefSlot (Sashiko)
- Fixed some stale comments (Sashiko)
- Picked up Benno's Ack.
- Link to v1: https://patch.msgid.link/[email protected]
Patches in v2 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/20 | kbuild: rust: allow `clippy::comparison_chain` globallyMakefile | +2 | 1 reply | |
| 2/20 | rust: pin-init: internal: pin_data: infer self-referential structrust/ rust/ | +253 | 0 replies | |
| 3/20 | rust: pin-init: internal: pin_data: rewrite fields that borrow othersrust/ rust/ | +93 | 0 replies | |
| 4/20 | rust: pin-init: internal: pin_data: pin borrowed fields with wrapperrust/ rust/ | +38 | 0 replies | |
| 5/20 | rust: pin-init: internal: pin_data: teach drop check about generics that cannot danglerust/ | +29 | 0 replies | |
| 6/20 | rust: pin-init: internal: pin_data: self-referential drop order checksrust/ rust/ | +268 | 0 replies | |
| 7/20 | rust: pin-init: internal: pin_data: check covariance of self-referential fieldsrust/ rust/ | +96 | 0 replies | |
| 8/20 | rust: pin-init: internal: pin_data: implement initialization of borrowed structsrust/ rust/ rust/ +1 more | +305 | 0 replies | |
| 9/20 | rust: pin-init: internal: pin_data: project self-referential fieldsrust/ rust/ | +107 | 0 replies | |
| 10/20 | rust: pin-init: internal: pin_data: add `with_project` methodrust/ | +136 | 0 replies | |
| 11/20 | rust: pin-init: internal: pin_data: enable self-referential supportrust/ rust/ | +35 | 0 replies | |
| 12/20 | rust: pin-init: internal: pin_data: allow lifetime to be shortened per field drop orderrust/ | +40 | 0 replies | |
| 13/20 | rust: pin-init: internal: pin_data: parse explicit `#[borrowed]` annotationrust/ | +32 | 0 replies | |
| 14/20 | rust: pin-init: internal: pin_data: support mutable borrowsrust/ rust/ rust/ | +149 | 0 replies | |
| 15/20 | rust: pin-init: internal: pin_data: parse explicit `#[uses]` annotationrust/ | +95 | 0 replies | |
| 16/20 | rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariancerust/ rust/ | +174 | 0 replies | |
| 17/20 | rust: pin-init: internal: pin_data: complete invariant borrow supportrust/ rust/ | +30 | 0 replies | |
| 18/20 | rust: pin-init: internal: pin_data: perform AST lifetime replacement if possiblerust/ | +102 | 0 replies | |
| 19/20 | rust: pin-init: internal: pin_data: support shared projectionrust/ | +134 | 0 replies | |
| 20/20 | rust: pin-init: internal: pin_data: support existential lifetimesrust/ rust/ | +252 | 0 replies |
Reviews trailers per patch
11 of 20 patches have a Reviewed-by or Acked-by.
| Patch | Benno Lossin | Miguel Ojeda |
|---|---|---|
| 1/20 | A-b | A-b |
| 2/20 | A-b | |
| 3/20 | ||
| 4/20 | A-b | |
| 5/20 | A-b | |
| 6/20 | ||
| 7/20 | ||
| 8/20 | A-b | |
| 9/20 | ||
| 10/20 | ||
| 11/20 | A-b | |
| 12/20 | A-b | |
| 13/20 | A-b | |
| 14/20 | ||
| 15/20 | A-b | |
| 16/20 | A-b | |
| 17/20 | ||
| 18/20 | A-b | |
| 19/20 | ||
| 20/20 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 00/20] rust: pin-init: create self references safely
This is a big series that add support for one field to reference a sibling field in a safe and ergnonomic way. Unlike many other crates in the userspace Rust ecosystem, no additional allocation is required, thus it requires the struct to be pinned, which is exactly what pin-init provides.
This is a very powerful feature, and thus can raise concerns about whether it is sound. I spent a lot of time studying the rules to make this sound, and presented durirng Kangrejos [1].
The simple use case looks like this:
#[pin_data]
struct MyDriver<'bound> {
dev: &'bound Device,
#[pin]
irq: irq::Registration<'bound, MyIrqHandler<'bound, 'bar>>,
bar: Bar<'bound, BAR_SIZE>,
}You simply need to mention a lifetime that shares the name with the field. There are more advanced use cases which require annotations like
#[uses('bar: invariant)]to explicitly declare that the lifetime is used in invariant manner, and also
where
exists<'dev>: 'ato create new existential lifetimes as a way to erase invariant lifetimes that would otherwise bubble up to users. More info can be seen in my Plumbers slide [2]. Note that the syntax for explicit variance annotation has changed following discussions during Plumbers.
The initial plan was to upstream the simple use case only and iron out the advanced features subsequently; however it turns out that DRM jobqueue would need the variance annotation feature, and Nova Cmdq would need to use the existential lifetime feature.
During Plumbers the upstream schedule is discussed, and instead it was agreed that all the features should be upstreamed at once, but the usage of the advanced feature usage limited to the pre-agreed users only to limit the blast radius in case the feature needs to be reworked.
Detailed documentation about the pin-init self-reference feature would be added the following cycle, when the usage of them become more clear.
The pull request on GitHub [3] has a bunch of test suites, which are not synchronized to kernel tree.
---
Changes in v2:
- Add where bounds to covariance check (Sashiko)
- Use NotVisible mechanism for with_project_ref instead of filtering (Sashiko)
- Drop pub from SelfRefSlot (Sashiko)
- Fixed some stale comments (Sashiko)
- Picked up Benno's Ack.
- Link to v1: https://patch.msgid.link/[email protected]
---
Gary Guo (20):
kbuild: rust: allow clippy::comparison_chain globally
rust: pin-init: internal: pin_data: infer self-referential struct
rust: pin-init: internal: pin_data: rewrite fields that borrow others
rust: pin-init: internal: pin_data: pin borrowed fields with wrapper
rust: pin-init: internal: pin_data: teach drop check about generics that cannot dangle
rust: pin-init: internal: pin_data: self-referential drop order checks
rust: pin-init: internal: pin_data: check covariance of self-referential fields
rust: pin-init: internal: pin_data: implement initialization of borrowed structs
rust: pin-init: internal: pin_data: project self-referential fields
rust: pin-init: internal: pin_data: add with_project method
rust: pin-init: internal: pin_data: enable self-referential support
rust: pin-init: internal: pin_data: allow lifetime to be shortened per field drop order
rust: pin-init: internal: pin_data: parse explicit #[borrowed] annotation
rust: pin-init: internal: pin_data: support mutable borrows
rust: pin-init: internal: pin_data: parse explicit #[uses] annotation
rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance
rust: pin-init: internal: pin_data: complete invariant borrow support
rust: pin-init: internal: pin_data: perform AST lifetime replacement if possible
rust: pin-init: internal: pin_data: support shared projection
rust: pin-init: internal: pin_data: support existential lifetimes
Makefile | 2 + rust/pin-init/examples/selfref.rs | 60 ++ rust/pin-init/internal/src/init.rs | 42 +- rust/pin-init/internal/src/pin_data.rs | 1563 +++++++++++++++++++++++++++++++- rust/pin-init/internal/src/util.rs | 269 +++++- rust/pin-init/src/__internal.rs | 357 +++++++- rust/pin-init/src/lib.rs | 1 + 7 files changed, 2246 insertions(+), 48 deletions(-)
---
base-commit: 0d9aa4b994379c6e0099737221ed421deb7e1a31
change-id: 20261006-dev-selfref-27c37abfa849
Best regards,
Signature · 1 line
Gary Guo <[email protected]>