Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Use lifetimed, type erased pointers in bevy_ecs #3001
[Merged by Bors] - Use lifetimed, type erased pointers in bevy_ecs #3001
Changes from 3 commits
feea9e0
40b1366
33d1844
6c887ad
3d936f4
feb49a3
9d1cfe8
ea83de9
0181c36
68b0903
ed70596
632c130
9b71e0b
c954cf7
7034c14
d13ad78
f3a1a89
0ea41a7
3e96ad9
379c614
77a6e15
c8801b2
163dbf4
36ec230
9a844f5
87dd80f
0908c90
344bbef
d72bd23
148d598
ef248cd
7adc7dd
75e1fa6
c03f937
cdb442a
d78c5aa
e7258ea
828e0c6
40c5ef2
6d21f3a
134e4ae
b76d47a
1a9d2b4
fa466a0
7df4761
e857b85
26d7c29
fcd4f9a
96c7a92
47d8fa6
5bedc37
53518a4
5eec29d
156f6bf
691874d
3b7baec
2704a34
57fbb7b
0ea1718
c72047d
4b0cf4f
47024d0
e3cc656
34167f2
18add0c
8bc292e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a latent problem, but this macro assumes it's being run inside of
bevy_ecs
(for good reason)Ideally, we'd have a way to document that, but I think the macro should at least be
#[doc(hidden)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but is this relevant in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, the two lifetimes,
x
andy
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'w
and's
are taken, sometimes'a
is also taken, I just wanted something I knew wouldn't cause any conflicts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that the bundle can only live as long as
ctx
? If we destroy the world, will this cause UB?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just give the
Bundle
trait a'world
lifetime?Edit: I don't think so, because we want tuple bundles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect
ctx
to exclusively borrow the world?How would we destroy the world in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't mean bundle can only live as long as
ctx
andBundle
doesnt need a'world
lifetime. This function is used when removing a bundle from world so we are taking data out ofctx
hence theOwningPtr<'_>
and moving it intoSelf
to construct the bundle. The only lifetimes involved are for the temporary borrow on world while we are removing the components to construct our bundle from.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lifetime is unbounded. I suspect we need an HRTB to properly constrain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected this an anonymous lifetime within the function, i.e. the only assumption the function can make is that it outlives the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same as
impl for<'a> FnMut(OwningPtr<'a>)
its not unbounded. If you look at the error message in this playground link https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b3f01da9fb82ca83e808a056801a79e you can see it saying it expects the typefor<'a> FnOnce(&'a u8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a particular type" could be read as universal here, which is clearly not what is meant.
Not sure how to deal with that though.
Additionally, this does kind of run into the 'ambiguity' of 'read', as
ptr::read
is consuming, but this means only 'reading', i.e. converting to a shared reference.We should probably just use that term here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Guaranteed" feels too strong to me, since this must be carefully constructed to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of these types is that they are supposed to be carefully constructed to uphold these guarantees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly "convert to a unique reference" could be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should be
its
here (and below)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems extremely dangerous to use due to inferred lifetimes: this is very easy to mess up and will result in UB lifetime extensions if you do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problem is repeated elsewhere, e.g. on
OwningPointer::make
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is nothing that can be done about this, its the same problem as dereferencing a raw pointer creating an unbounded lifetime which has to happen at some point anyway to turn it into a reference.