Skip to content

Heightenize - #12681

Closed
Nahor wants to merge 2 commits into
fish-shell:masterfrom
Nahor:heightenize
Closed

Heightenize#12681
Nahor wants to merge 2 commits into
fish-shell:masterfrom
Nahor:heightenize

Conversation

@Nahor

@Nahor Nahor commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

TODOs:

  • If addressing an issue, a commit message mentions Fixes issue #<issue-number>
  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@krobelus krobelus added this to the fish 4.7 milestone Apr 28, 2026
Comment thread src/bin/fish.rs
res = reader_read(parser, libc::STDIN_FILENO, &IoChain::new());
} else {
let n = wcs2bytes(&args[my_optind]);
let filename = &args[my_optind];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to put unrelated changes like this and the cwd_fd if-let cleanup in separate commits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this one is a leftover from a different attempt where I had replaced File::open with wopen_cloexec to have an implicit heightenization. Then I changed my mind and reverted back to File::open and didn't realize this made this filename stuff unnecessary.

And for the cwd_fd cleanup, it didn't feel worthwhile to have a separate commit for it, especially since you usually ask me to squash commits instead😊

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had replaced File::open

I was gonna comment that we should probably extract a version of File::open that heightenizes implicitly.
So yeah, something like that would make sense.

And for the cwd_fd cleanup, it didn't feel worthwhile to have a separate commit for it, especially since you usually ask me to squash commits instead😊

oh. if it's unrelated changes then separating is usually good

Comment thread src/fds.rs
/// Return the fd, which always has CLOEXEC set; or an invalid fd on failure, in
/// which case an error will have been printed, and the input fd closed.
fn heightenize_fd(fd: OwnedFd, input_has_cloexec: bool) -> nix::Result<OwnedFd> {
pub fn heightenize_fd(fd: OwnedFd, input_has_cloexec: bool) -> nix::Result<OwnedFd> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lsof -p $fish_pid shows that we also have some long-lived fds in inotify/kqueue/notifyd code.
I'll add fixes for those.
Except for notifyd because as I understand https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/notify_register_file_descriptor.3.html,
notify_cancel closes the file descriptor we obtained from notify_register_file_descriptor (even though LLM disagrees),
so I'm not sure if we can safely dup and close that one.

Grepping for File::open also shows fish_indent, which may be a builtin, so it shares fds with fish.
I guess that one we can count as short-lived enough for now because there's no concurrent execution of builtins yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I expect they are other cases that need to be solved. I didn't do a deep dive. I only fixed the one I could see by just running fish. And by doing it fish_open, I figured it would fix a few I wasn't seeing. And I only dived beyond that just enough to get a couple tests.

Comment thread src/parser.rs

/// A file descriptor holding the current working directory, for use in openat().
/// This is never null and never invalid.
pub cwd_fd: Option<Arc<OwnedFd>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah I guess 6637ccd (Keep an fd for the cwd in the parser, 2019-06-10) was mainly for future use of openat().
Keeping cwd_fd open also means the OS will keep the inode valid (even when the associated path is removed/moved) but since we don't use it anywhere, I don't think there's a point in keeping it.

Comment thread src/parser.rs
}
if let Err(err) = open_dir(c".", BEST_O_SEARCH) {
perror_nix("Unable to open the current working directory", err);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems also unnecessary now. Will remove.
Of course in future we might want to behave like bash, i.e. mv $PWD /some/where does not change the output of ls etc. Not sure how much work that will be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this seems also unnecessary now

I had noticed but I left it in out of caution, in case this resulted in some extra checks (e.g. file permissions). But yes, I'm perfectly happy with it gone (and it gets rid of an untranslated string 😊).

Of course in future we might want to behave like bash, i.e. mv $PWD /some/where does not change the output of ls etc.

Bash does not keep $PWD opened either. ls works because it's equivalent to ls . not ls $PWD, i.e. relative path, resolved by the OS, rather than an absolute path, resolved by ls. And the OS can resolve because it keeps track of the pwd (/proc/pid/cwd) on its own. So this should still work fine with fish.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ockham's razor says this open_dir was just added for the reason given in 6637ccd (Keep an fd for the cwd in the parser, 2019-06-10), and not for any other extra checks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this should still work fine with fish.

right but cd . works in bash after $PWD has been renamed but not in fish. Maybe because fish tries to canonicalize paths.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

completion doesn't work in fish either, while it does in Bash (cat ./<tab>)

krobelus pushed a commit that referenced this pull request Apr 28, 2026
@krobelus krobelus closed this in 27fb4d6 Apr 28, 2026
@Nahor
Nahor deleted the heightenize branch April 28, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants