kubkon opened PR #1412 from rc-entry
to master
:
This commit refactors the use of
Ref
s andRefMut
s inwasi-common
.
Now,Entry
is stored behind anRc
inside theEntryTable
. TheEntry
itself on the other hand now stores rights behind aRefCell
and the
descriptor asRc<RefCell<..>>
combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntry
fromWasiCtx
, and so all related methods
go away (get_entry_mut
, etc.).While here, I've also simplified handling and aggregating of rights on
theEntry
object. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rights
syscall, this object
is kept behind aRefCell
(note noRc
since we don't need to pass it
around anywhere).The descriptor field in
Entry
is now kept behindRc<RefCell<..>>
combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_file
andtry_clone
methods onDescriptor
struct
since they were adding more noise than necessary, and making them work
withRc
was unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handle
function into a
method attached to theOsHandle
itself, calleddir_stream
. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon requested alexcrichton and sunfishcode for a review on PR #1412.
kubkon requested alexcrichton and sunfishcode for a review on PR #1412.
kubkon updated PR #1412 from rc-entry
to master
:
This commit refactors the use of
Ref
s andRefMut
s inwasi-common
.
Now,Entry
is stored behind anRc
inside theEntryTable
. TheEntry
itself on the other hand now stores rights behind aRefCell
and the
descriptor asRc<RefCell<..>>
combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntry
fromWasiCtx
, and so all related methods
go away (get_entry_mut
, etc.).While here, I've also simplified handling and aggregating of rights on
theEntry
object. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rights
syscall, this object
is kept behind aRefCell
(note noRc
since we don't need to pass it
around anywhere).The descriptor field in
Entry
is now kept behindRc<RefCell<..>>
combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_file
andtry_clone
methods onDescriptor
struct
since they were adding more noise than necessary, and making them work
withRc
was unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handle
function into a
method attached to theOsHandle
itself, calleddir_stream
. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
This is a
Copy
type I think, so could this perhaps be aCell<types::Fdflags>
to entirely elimitate the possibility of panics?
alexcrichton created PR Review Comment:
So to prefix this, I'm not very familiar with what this
Descriptor
is and what it's used for. That being said I think it'd be great, if possible, to continue to push theRefCell
deeper here. The purpose of removing the ability to get&mut Entry
was all about making mutable borrows as small as possible to eliminate possibilities of panics, and I think the same might apply here as well. It may even be possible to haveDescriptor
only haveCell
fields, but ideally anyRefCell
fields would have very small borrows and no methods would have to return aRef
orRefMut
kubkon updated PR #1412 from rc-entry
to master
:
This commit refactors the use of
Ref
s andRefMut
s inwasi-common
.
Now,Entry
is stored behind anRc
inside theEntryTable
. TheEntry
itself on the other hand now stores rights behind aRefCell
and the
descriptor asRc<RefCell<..>>
combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntry
fromWasiCtx
, and so all related methods
go away (get_entry_mut
, etc.).While here, I've also simplified handling and aggregating of rights on
theEntry
object. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rights
syscall, this object
is kept behind aRefCell
(note noRc
since we don't need to pass it
around anywhere).The descriptor field in
Entry
is now kept behindRc<RefCell<..>>
combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_file
andtry_clone
methods onDescriptor
struct
since they were adding more noise than necessary, and making them work
withRc
was unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handle
function into a
method attached to theOsHandle
itself, calleddir_stream
. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon created PR Review Comment:
Yep, thanks!
kubkon submitted PR Review.
kubkon submitted PR Review.
kubkon created PR Review Comment:
I think you're right. Although making it work will require some bigger reorg to
OsHandle
especially on BSD platform. I have an idea for this and will investigate but given that this probably will be a bigger change, I'd prefer to have it as a subsequent PR. In short, if we makeOsHandle
a bit closer to the metal by replacingFile
withRawFd
, we can makeOsHandle
Copy
which would then make it possible to haveDescriptor
inside aCell
. There's a little bit more work involved with BSD since currentlyOsHandle
, in addition toFile
, also stores an optionalyanix::Dir
(which is non-Copy
since it's got a customDrop
impl) and it would probably make sense to split the handle into either representing an actual file, or a directory. Then, we wouldn't needOption
nor interior mutability, since we could easily makeyanix::Dir
Copy
calling it something likeyanix::UnsafeDir
and specifically mentioning that it is the user's responsibility to close the underlying dir stream withlibc::closedir
fn. Does that make sense?
kubkon submitted PR Review.
kubkon created PR Review Comment:
Oh, and the only reason we ever need to mutate the actual
Descriptor
inEntry
is because on Windows, setting fdstat flags requires reopening the file.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
Ah ok punting this to later seems fine, in any case looks like a great refactoring!
alexcrichton submitted PR Review.
kubkon updated PR #1412 from rc-entry
to master
:
This commit refactors the use of
Ref
s andRefMut
s inwasi-common
.
Now,Entry
is stored behind anRc
inside theEntryTable
. TheEntry
itself on the other hand now stores rights behind aRefCell
and the
descriptor asRc<RefCell<..>>
combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntry
fromWasiCtx
, and so all related methods
go away (get_entry_mut
, etc.).While here, I've also simplified handling and aggregating of rights on
theEntry
object. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rights
syscall, this object
is kept behind aRefCell
(note noRc
since we don't need to pass it
around anywhere).The descriptor field in
Entry
is now kept behindRc<RefCell<..>>
combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_file
andtry_clone
methods onDescriptor
struct
since they were adding more noise than necessary, and making them work
withRc
was unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handle
function into a
method attached to theOsHandle
itself, calleddir_stream
. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon merged PR #1412.
Last updated: Dec 23 2024 at 12:05 UTC