Skip to content

Insert FileDescription instead of FileDescriptor in insert_fd #3763

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
merged 1 commit into from
Jul 26, 2024

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Jul 25, 2024

This PR moves the creation of FileDescriptor inside insert_fd, and insert_fd now takes in FileDescription instead of FileDescriptor. This change is needed by #3712.

@tiif tiif mentioned this pull request Jul 25, 2024
@tiif
Copy link
Contributor Author

tiif commented Jul 25, 2024

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Jul 25, 2024
@tiif tiif changed the title Add file description ID and give ecx access to FileDescription's close Insert FileDescription instead of FileDescriptor in insert_fd Jul 26, 2024
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit then we can land this

@oli-obk
Copy link
Contributor

oli-obk commented Jul 26, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 26, 2024

📌 Commit 79285bb has been approved by oli-obk

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 26, 2024

⌛ Testing commit 79285bb with merge 43ab65e...

@bors
Copy link
Contributor

bors commented Jul 26, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 43ab65e to master...

@bors bors merged commit 43ab65e into rust-lang:master Jul 26, 2024
8 checks passed
@tiif tiif deleted the global-fd-id branch July 26, 2024 14:10
}

pub fn insert_fd(&mut self, file_handle: FileDescriptor) -> i32 {
/// Insert a file descriptor to the FdTable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment seems to contradict the signature? This is a file description, isn't it?

}

pub fn insert_fd(&mut self, file_handle: FileDescriptor) -> i32 {
/// Insert a file descriptor to the FdTable.
pub fn insert_fd<T: FileDescription>(&mut self, fd: T) -> i32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the motivation is for this API change, but it seems odd to me. Note that insert_fd_with_min_fd wasn't changed, so now we have two equally-named APIs doing very different things. And insert_fd_with_min_fd can't be changed since indeed it is used to insert duplicates of existing file descriptions that shouldn't be wrapped in a new Rc.

This change is needed by #3712.

I don't understand how it is possible for this change to be needed. This change means that the API is now strictly less powerful than it was before. The only argument I can currently imagine for this change is ergonomics, and I don't agree that's worth it given the API inconsistencies this introduces.

IMO this should be reverted, both insert_fd and insert_fd_with_min_fd should take a FileDescriptionRef.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API didn't need to be as powerful as it was, so this seems good (restricting to the use case we need). It's also the only sane design I see for having each FileDescriptionrRef carry a unique id that we can use instead of its address.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We considered do it in FileDescriptionRef::new, but then that needs access to the InterpCx or at least the FdTable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is pure coincidence that we have no operation which creates a 2nd file descriptor for an existing file description, and calls this function. In fact arguably this here should just call insert_fd.

And having two insert_fd functions that don't even take the same kind of argument seems like an obviously bad API to me, way worse than an API that is slightly more general than what we happen to need right now.

Creating a FileDescriptionRef from a FileDescription should be a completely independent operation from inserting a FileDescriptionRef into the FD table.

Copy link
Member

@RalfJung RalfJung Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also the only sane design I see for having each FileDescriptionrRef carry a unique id that we can use instead of its address.

Just have FileDescriptionRef::new take a reference like ecx: &mut MiriInterpCx<'tcx> and then it can do the ID assignment.

Then we can maybe have fd.insert_new_fd for the common pattern of "create new ref and insert it".

Copy link
Member

@RalfJung RalfJung Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could call the functions insert_new_fd and insert_existing_fd where only the latter supports a "minimum file description" and then we don't even have to change their implementation. (Though i think factoring FileDescriptionRef::new into a separate operation, even if it remains private, would still help to make the conceptual structure more clear.)

The PR description should have mentioned the point about FileDescriptionRef::new needing access to global state in #3712, that would have avoided some confusion. :)

bors added a commit that referenced this pull request Jul 30, 2024
Some FileDescriptor/FileDescription refactorings

follow-up to #3763 (comment)

I opted not to change the method names, as I think they are already pretty good (and the common one is the short name), and the docs should explain what they actually do, but if you feel like the names you proposed would be better, I'll just do that.
RalfJung pushed a commit to RalfJung/rust that referenced this pull request Aug 5, 2024
Some FileDescriptor/FileDescription refactorings

follow-up to rust-lang/miri#3763 (comment)

I opted not to change the method names, as I think they are already pretty good (and the common one is the short name), and the docs should explain what they actually do, but if you feel like the names you proposed would be better, I'll just do that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants