Skip to content

Conversation

@ecoskey
Copy link
Contributor

@ecoskey ecoskey commented Dec 4, 2025

Objective

  • Allow reborrowing for SystemParam types. The end goal here is to work towards a fast System::scope api, to run a system many times with different inputs with low overhead

Blocked on: #22025

Next steps:

  • This diff would be smaller with a proc-macro for internal implementations: impl_reborrow_system_param!(...). I decided not to at least at first, though it wouldn't be too hard.
  • Could also combine with ReborrowQueryData in theory, but it might be controversial:
trait EcsBorrow {
    type Item<'w, 's>;
}

trait EcsReborrow {
    pub fn reborrow(...)
}

trait SystemParam: EcsBorrow {}
trait QueryData: EcsBorrow {}
  • Add System::scope

Solution

  • Add a optional ReborrowSystemParam subtrait, almost identical to ReborrowQueryData

  • While most system params should implement this trait, there's a few exceptions like ParamSet types with invariant lifetimes, which we can't shorten AFAICT. Maybe if we changed ParamSet::Item to shorten the inner lifetime as well?

/// A [`SystemParam`] whose lifetime can be shortened via
/// [`reborrow`](ReborrowSystemParam::reborrow)-ing. This should be implemented
/// for most system params, except in the case of non-covariant lifetimes.
pub trait ReborrowSystemParam: SystemParam {
    /// Returns a `SystemParam` item with a smaller lifetime.
    fn reborrow<'wlong: 'short, 'slong: 'short, 'short>(
        item: &'short mut Self::Item<'wlong, 'slong>,
    ) -> Self::Item<'short, 'short>;
}

@ecoskey ecoskey added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events S-Blocked This cannot move forward until something else changes D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Dec 4, 2025
@ecoskey ecoskey force-pushed the feature/param_reborrow branch 2 times, most recently from b446118 to b5f2187 Compare December 6, 2025 21:52
@ecoskey ecoskey force-pushed the feature/param_reborrow branch from b5f2187 to 6bc764e Compare December 9, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Blocked This cannot move forward until something else changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant