-
Notifications
You must be signed in to change notification settings - Fork 3k
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
file descriptor rewrite #18790
Draft
paperclover
wants to merge
2
commits into
main
Choose a base branch
from
chloe/file-descriptor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
file descriptor rewrite #18790
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I've wanted to do this fix since Bun 1.1
FileDescriptor and FDImpl are currently two separate structures. Originally, the former was an integer type and the latter was a packed struct introduced for Windows. With improvements to the Zig language (equality operator on packed struct and decl literals), it is now time to make FDImpl the actual file descriptor struct. This PR merges the two into
bun.FD
In exchange for this, bun.FD has new helpful methods:
Migration Guide
bun.STDIN_FD
->bun.FD.stdin()
bun.STDOUT_FD
->bun.FD.stdout()
bun.STDERR_FD
->bun.FD.stderr()
bun.toFD(value)
FD.fromNative(value)
(i32 on posix, HANDLE on windows)FD.fromUV(value)
(i32 on posix, uv_file on windows)FD.fromStdFile(value)
from std.fs.FileFD.fromStdDir(value)
from std.fs.Dirbun.uvfdcast(fd)
->fd.uv()
fd.asFile()
->fd.stdFile()
fd.asDir()
->fd.stdDir()
bun.FDTag
->bun.FD.Stdio
bun.FDTag.get(fd)
->fd.stdioTag()
orbun.FD.Stdio.fromInt(fd)
bun.stdio(i)
/bun.{posix,win32}.stdio(i)
->bun.FD.Stdio.fromInt(i).?.fd()
bun.sys.close
and friendsfd.close()
to assert the fd is validfd.closeAllowingBadFileDescriptor()
if EBADF is allowedThe following are deprecated but left in to reduce diff size:
bun.FileDescriptor
->bun.FD
bun.StoredFileDescriptorType
->bun.FD
fd.cast()
->fd.native()
std.fs.cwd()
->bun.FD.cwd()
std.fs.File
andstd.fs.Dir
andstd.posix
should be avoided.bun.sys.File
will be deprecated in favor ofbun.FD
's methods. potentially addbun.FD.Dir
bun.invalid_fd
->bun.FD.invalid
->bun.FD.Optional.none
The following patterns are banned
std.fs.Dir
bun.invalid_fd
std.fs.cwd
std.fs.File
.stdFile()
.stdDir()
Why Now
This is a part of the usingnamespace / incremental compilation effort. Currently,
bun.STD*_FD
is usingnamespaced to a var declaration on windows and a const declaration on posix. This PR cleans this up to be where it should be: methods onbun.FD