or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Unified EntityPtr Types
TL;DR
We can reduce code duplication for the following sets of types because they differ only in semantics:
EntityRef
,EntityMut
, andEntityWorldMut
FilteredEntityRef
,FilteredEntityMut
EntityRefExcept
,EntityMutExcept
What they look like currently:
What they will look like afterwards:
Access Levels
These types do not differ memory-wise, but they do semantically. If we take a look at the three aforementioned types, we can see that there's three different "access levels" for safely accessing an
UnsafeEntityCell
:We can define some marker traits and structs to put these into rust:
The above set of traits and types should cover all the different kinds of access bounds:
L: ReadAccess
- for when some kind of read access is neededL = ReadOnly
- for when precisely read-only access is neededL: MutableAccess
- for when some kind of mutable access is neededL = Mutable
- for when precisely non-world-mutable access is neededL = WorldMutable
- for when precisely world-mutable access is neededDowngrading access
Because each higher level of access implies the levels below it, we can safely allow downgrading higher access level pointers to lower access level:
Minimum access level
When working generically with some pointer we are only given read access:
Downgrading arbitrary access levels
We can combine the two previous concepts for implementing conversions from
&EntityPtr<ANY>
->EntityPtr<ReadOnly>
with only oneFrom
implementation:Amendment: Consider adding
Immutable
access type +Deref
/DerefMut
impls for downgradingProposed by @bushRAT on the Bevy Discord, revised based on discussion with @quartermeister and @Diddykonga.
Originally proposed was to add
Deref
/DerefMut
implementations forWorldMutable
->Mutable
->ReadOnly
. However this would be unsound asReadOnly
is (currently)Copy
+Clone
, so someone could do:To combat this we could introduce a 4th access type,
Immutable
, alongside our three other access types (ReadOnly
,Mutable
, andWorldMutable
). This enables the removal of theReadAccess
andMutableAccess
traits and we would instead provideDeref
/DerefMut
impls, likely leading to a cleaner implementation overall.First a look at the types in code:
The first thing
We should be able to safely implement the following:
Tackling this change systematically
This changeset in its entirety will likely involve >3000 line changes when including file re-organization. Therefore it's prudent to make sure we push these changes incrementally in as small portions as reasonably possible.
Re-organization of entity_ref.rs
This is a big file (presently 4485 lines), and is a bit slow for Rust-Analyzer to process after an edit even on my (doot) well-specced machine, so we should take the following steps:
DynamicComponentFetch
toentity_fetch.rs
WorldEntityFetch
at some point, anyways.FilteredEntityRef
/FilteredEntityMut
,TryFromFilteredError
and associated tests into a new fileentity_ref_filtered.rs
EntityRefExcept
/EntityMutExcept
,fn bundle_contains_component
, and associated tests into a new fileentity_ref_except.rs
With all that done
entity_ref.rs
will be down to ~3180 lines.Change EntityWorldMut to hold just an
UnsafeEntityCell
In isolation this might seem like a downgrade as we'll go from holding an explicit
&mut World
to anUnsafeWorldCell
(contained in theUnsafeEntityCell
), but it's required for the next step / the overall plan.Finally, implement this document
EntityPtr<L: ReadAccess>
type and changeEntityRef
fromstruct
totype
alias.EntityMut
into atype
alias.EntityWorldMut
into atype
alias.FilteredEntityPtr<L: ReadAccess>
type and changeFilteredEntityRef
/FilteredEntityMut
into type aliases.EntityPtrExcept<L: ReadAccess>
type and changeEntityRefExcept
/EntityMutExcept
into type aliases.These can be done as separate PRs, but TBD which changes should be grouped together into individual PRs.