Repository navigation
Conversation
This RFC proposes a refactor of the Patina component system to support more flexible component composition. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
✅ QEMU Validation PassedAll QEMU validation jobs completed successfully.
Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/46561296085 Boot Time to EFI Shell
EFI Test App ResultsPre-compiled test apps from the
Per-app results
Booted from an SSD. Time is QEMU power-on to guest power-off, so it includes OS shutdown. Dependencies
Binary Size Report
Compressed sizes use LZMA-alone format at preset 6 ( Shared QEMU integration: This comment was automatically generated by the Patina QEMU PR Validation Post workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| - A simple component has one entry point and does not register other components. All existing components today are | ||
| simple components. | ||
| - A composite component is made of constituents. | ||
| - A _static_ composite component declares several `#[entry_point]` methods in an `impl` block for a given Rust type. |
There was a problem hiding this comment.
If there can be multiple, I wonder if we should consider something other than entry_point, just to distance ourselves from the binary analogy if we are diverting from that expectation. Perhaps #[dispatch].
| simple components. | ||
| - A composite component is made of constituents. | ||
| - A _static_ composite component declares several `#[entry_point]` methods in an `impl` block for a given Rust type. | ||
| - A _dynamic_ composite component has an entry point that registers other components using `Commands::add_component` |
There was a problem hiding this comment.
Are these mutually exclusive? Could a component implement an entry_point that adds components and also implement other entry_points? If so, is that something the core can enforce?
|
|
||
| ## Goals | ||
|
|
||
| 1. Let one composite component represent a set of functionality regardless of how many constituents implement it. |
There was a problem hiding this comment.
Is it a goal to allow these dynamic components to able to be used individually? That is, is the composite a "default" setup, the only setup, or implementation defined?
|
|
||
| #[entry_point] | ||
| fn communicator( | ||
| self, |
There was a problem hiding this comment.
While the self makes sense as a copy, I suspect it may be an easy logical mistake for people to make with the introduction of multiple entry points. That is having one entry do self.setting = value and not realizing that doesn't persist to the other entries.
There was a problem hiding this comment.
ah yes this is a good call. These entry points will share the same "self" which is actually a nice side-effect beneifit of this. But because of this, they will need to be &self or &mut self.
With the current implementation of a StructComponent, the "self" is an Option<Self>. When we dispatch a component with &self and &mut self, we do a Option::borrow() or Option::borrow_mut() respectively. But for self, we do an Option::take(), which means when we go to dispatch the second entry point, we will panic.
| - The final public names for the new APIs, including `Commands::add_component`, the attribute that marks multiple entry | ||
| points in one `impl` block, and whether `IntoComponent` and the `Component` trait are renamed. The `Component` trait | ||
| is the dispatchable form of an entry point, and `IntoComponent` can now produce several of them. | ||
| - Whether multiple entry points that share `&self` or `&mut self` (rather than `self` by value) are worth supporting, |
There was a problem hiding this comment.
mentioned later, I think the self is a pitfall with multiple entry points. This could be solved with private config types to pass config between entry points, but it seems like a logic thing to store data between entries in self.
But that also does mean that there is some ordering assumptions potentially..
| `add.component` calls but not the limitation that the composition of a set of functionality is always public and always | ||
| static. | ||
|
|
||
| ## Rust Code Design |
There was a problem hiding this comment.
I like the general direction. My main concern is just the all the different ways it could be implemented. My hope from the "bundle" concept we had discussed was a simple prescribed method that the average consumer could use across every crate to create a well-prescribed and relatively standard was of including functionality. Perhaps one public composite component is that, but it seems we leave a lot of room for creativity still.
Perhaps this is a coding standard instead of a mechanism one.
| entry points require an interior mutability design. Some general guidance on storing state in a component is provided in | ||
| [Storing State for Later Use](../../component/storing_state.md). | ||
|
|
||
| ### Dynamic composition |
There was a problem hiding this comment.
Perhaps I'm missed it, but does this RFC cover why both dynamic and static are required? Would it be possible to solve all problems with just one of these mechanisms? It would be nice to keep crate design relatively consistent so the more high-level options we provide may cause design divergence.
| `Commands::add_component` (described below) both iterate the returned collection, so a registration call takes the same | ||
| path regardless of whether the component is simple or composite. | ||
|
|
||
| Each declared entry point receives a copy of `self`, so a type with more than one `#[entry_point]` method must implement |
There was a problem hiding this comment.
I'm not sure I agree with this. I actually think it would be way more beneficial to component writers to have &self and &mut self shared between the independently dispatchable portions of a component. I think either removing self to support this type of usage, or at least restrict self usage to components with only one dispatchable component.
I can think of multiple benefits of sharing mutable state between different dispatchable pieces of a statically composed component.
|
|
||
| ### Dynamic composition | ||
|
|
||
| Dynamic composition applies when a constituent's existence depends on information that is available only during |
There was a problem hiding this comment.
I think dynamic composition is necessary; but I don't like enabling that by adding functionality that allows components to register other components at runtime. I understand that there is a similar precedence in PI spec to allow drivers to dispatch other drivers themselves, but I would much rather enable this differently, in a way that gets all dispatchable pieces of code registered before beginning the runtime dispatch process.
I think a better approach is to define an entirely new component type - e.g. an alternative to StructComponent defined in struct_component.rs whose Component trait implementation has a registration-only interface that executes during the intialize() phase of the component registration and can only register (1) other components, (2) services, (3) configs. It specifically has no ability to retrieve anything, only add things.
A lightweight mockup could look something like this:
// All of this goes somewhere in patina crate
pub struct Add<'a> {
storage: &'a mut Storage,
components: &'a mut ComponentRegistry,
}
impl Add<'_> {
pub fn component<C: IntoComponent>(&mut self, component: C) {
// Register component
}
pub fn config<C: Default + 'static>(&mut self, config: C) {
self.storage.add_config(config);
}
pub fn service<S: IntoService + 'static>(&mut self, service: S) {
self.storage.add_service(service);
}
}
// A Component type that allows registration of components, services, and configs during its initialization before component dispatch begins.
pub struct DynamicComponent<F> {
initialize: Option<F>,
metadata: MetaData,
}
impl<F> Component for DynamicComponent<F>
where
F: FnOnce(Add<'_>) -> bool,
{
unsafe fn run_unsafe(
&mut self,
_storage: UnsafeStorageCell<'_>,
) -> Result<bool> {
Ok(true)
}
fn initialize(&mut self, storage: &mut Storage) -> bool {
let Some(initialize) = self.initialize.take() else {
return false;
};
let add = Add::new(
storage,
/* component registration sink */
);
initialize(add)
}
fn metadata(&self) -> &MetaData {
&self.metadata
}
}/// Now in the component writer crate, it goes somewhere like this
#[component]
fn my_dynamic_component(add: &mut Add) -> bool {
add.config(MyConfig(u32));
add.service(MyService::new());
for test in STATIC_TEST_LIST {
add.component(test)
}
true
}
impl ComponentInfo for MyPlatform {
fn components(mut add: Add) {
add.component(my_dynamic_component);
}
}
Description
This RFC proposes a refactor of the Patina component system to support more flexible component composition.
How This Was Tested
cargo make cspellIntegration Instructions