Commit graph

19796 commits

Author SHA1 Message Date
Peter Ammon
36d7049749
Minor cleanup of other unsafe impl 2024-12-27 14:46:46 -08:00
Peter Ammon
4b9767ce83
Remove as_ptr from IoData
We don't need this. Also improve IoChain::remove().
2024-12-27 14:36:55 -08:00
Peter Ammon
f6d76d2057
Remove some unsafe impls of Send / Sync
We no longer have C++ so we don't need these; Rust does the right thing by
default.
2024-12-27 14:14:47 -08:00
Peter Ammon
659c926dbd
Additional cleanup of io buffering
Eliminate some ugly bits. No functional change expected.
2024-12-27 14:09:07 -08:00
Peter Ammon
56da15d11f Rework the file descriptor monitor
[Do NOT cherry-pick to 4.0 - this needs more time to be tested]

fish sometimes needs to capture the output of a command or block of
commands. Examples include fish_prompt or any command substitution
("cmdsubs"). It does this the obvious way: by creating a pipe, using dup2
to replace stdout of the command with the write end of the pipe, and then
reading from the read end into a buffer, until EOF or the command
substitution completes. Importantly, this task also overlaps with waiting
for the process to exit; that is when executing:

    set var (some_cmd)

fish needs to both wait on `some_cmd` and ALSO read its output into memory.
This is awkward to do in a portable way in a single thread (though maybe
doable on Linux with pidfd). So we wait and read on different threads.

To make things worse, command substitutions may themselves create
additional command substitutions (recursion, etc). Creating a read thread
for every command substitution would result in excessive threads. So rather
than a thread per cmdsub, we have a single dedicated thread that handles
ALL command substitutions, by multiplexing multiple file descriptors via
select/poll. This is the "fd monitor." You hand it a file descriptor and it
lets you know when it's readable, and then you can read from it (via a
callback). Also, it has a "wakeup" fd: if you write to that then the fd
monitor wakes up, figures out what it has to do, and resumes.

When the command substitution ends, we need to remove the fd from the fd
monitor, because we intend to close it. You might object "the commands in
the cmdsub have all completed so the write end of the pipe has been closed
so the fd monitor can just notice that the pipe is closed" but it's not so:
consider the horrible case of `set var (yes &)` and abandon all hope.

The current mechanism for removing the fd from the monitor is called a
"poke." We tell the fd monitor (through a "control" self-pipe) to
explicitly wake up the item. It then invokes the callback ("pokes") the
item on the dedicated fd monitor thread. The item notices that the command
substitution is complete, and it returns a value meaning "remove me" and
the fd monitor does so. The client thread is stuck waiting for this process
to complete.

So basically removing a fd from the monitor requires a round trip to its
dedicated thread. This is slow and also complicated (Rust doesn't have
futures)!

So let's not do that.

The big idea is to remove this round-trip synchronization. That is, when we
intend to remove the fd from the fd monitor, we _just do it_ and then close
the fd. Use a lock rather than a round-trip to the thread. Crucially that
lock is unlocked while the monitor thread waits in select/poll.

This invites all sorts of races:

1. fish might remove and close the fd right before the monitor polls it. It
   will thus attempt to poll a closed fd.
2. fish might remove and close the fd, and then something else opens a file
   and receives the same fd. Now the fd monitor will poll an fd that was
   never added.
3. fish might remove and close the fd _while the fd monitor is polling it_.
   What happens then? (Turns out on macOS we get EBADF, and on Linux the fd is
   marked readable).

The Big Idea is that *all of these races are benign*. As long as
poll/select doesn't crash or hang, we don't care *what* it returns, because
the source of truth are the set of items stored in the fd monitor and these
item IDs are never recycled. (This also assumes that it's OK to select/poll
on random file descriptors; there ought to be no side effects).

Not only is this a large simplification since we no longer need that round
trip, it's a substantial performance improvement as well. The
"aliases.fish" benchmark goes from 164 to 154 msec on my Mac, and from 124
to 112 msec on my Linux machine - nearly 10%.

Add some tests to verify our assumptions about the behavior of closing or
replacing a file descriptor during poll. But even if these fail, all we
care about is that poll/select doesn't crash or hang.
2024-12-27 13:23:11 -08:00
Peter Ammon
5e59762117 FdMonitor: Use a HashMap instead of Vec of items
Preparing for a substantial optimization.
2024-12-27 13:23:11 -08:00
Peter Ammon
69fdbc89d6 Refactor FdMonitorItem readability checks
No functional change. Preparing for an optimization.
2024-12-27 13:21:44 -08:00
Peter Ammon
244c55f9ce FdMonitor: change_signaller to be held strongly not weakly
There's no reason to use Weak here, especially since we just unwrap it. There's
no reference cycles, so just share the data via Arc.
2024-12-27 13:21:44 -08:00
Peter Ammon
b7ae159824
Remove the ability for FdMonitorItems to have timeouts
FdMonitor is used to monitor a set of file descriptors and invoke a callback
when one becomes readable. Prior to this commit, they coudl also have the
callback invoked on timeout. fish used to use this feature but no longer does;
remove it.
2024-12-27 13:03:49 -08:00
Peter Ammon
6dad396498
Clean up some stale comments 2024-12-27 13:03:49 -08:00
Fabian Boehm
f5a02e590d Fix tmux-multiline-prompt check 2024-12-27 21:02:38 +01:00
Fabian Boehm
36c632889b pexpects: Fix some escapes
Python has become stricter about unknown `\x` in strings, firing a
SyntaxWarning right now.

They need to be `\\x`.
2024-12-27 20:05:10 +01:00
Dmitry Gerasimov
c473aa60a7 completions/dnf: Fix completions for DNF5 (#9862)
Since DNF5 there's no implicit \n in repoquery output. For DNF4 this change
leaves blank lines in the output, but they are ignored anyway.
2024-12-26 12:01:49 -08:00
David Adam
6515862095 Debian packaging: move comments to their own lines 2024-12-26 14:53:04 +08:00
phanium
94dfe1b053
Fix alt-e cursor position restore on Vim <= 8 (#10946) 2024-12-26 06:35:37 +01:00
David Adam
0b52b72ebc Debian packaging: comment on reason for runtime dependencies 2024-12-26 13:22:30 +08:00
David Adam
eade6a5672 Debian packaging: add some missing runtime dependencies 2024-12-26 13:21:33 +08:00
David Adam
044cea1bf3 update CMake requirement
find_rust uses LIST(POP_BACK), which was added in 3.15.
2024-12-26 13:20:00 +08:00
David Adam
74b1247461 Debian packaging: reformat dependencies 2024-12-26 13:19:41 +08:00
Fabian Boehm
9b8793a2df
docs: Use grid in the CSS (#10942)
Instead of hardcoded 230px margin.

This also makes the ToC only take up a third of the screen when
narrow, and lets you scroll the rest.

Without, you'd have to scroll past the *entire* ToC, which is awkward

Remaining issue is the search box up top. Since this disables the one
in the sidebar once the window gets too narrow, that one is important,
and it isn't *great*
2024-12-25 14:50:27 +01:00
Blair Noctis
6c63139d23 refactor: macroize SIGNAL_TABLE entries
reducing boilerplate and chance of typo
2024-12-24 15:25:10 +01:00
Mahmoud Al-Qudsi
f3dd4ee022 Fix typo in hard-coded name of SIGSTKFLT 2024-12-23 14:29:00 -06:00
Mahmoud Al-Qudsi
7bafb0d1ae CHANGELOG: Fix Sphinx error on unnamed section 2024-12-23 13:54:21 -06:00
Mahmoud Al-Qudsi
46072e0fd6 completions/llm: Add completions for all subcommands 2024-12-23 13:50:10 -06:00
Mahmoud Al-Qudsi
c09a9246a1 completions/llm: Fix broken completion 2024-12-23 13:47:19 -06:00
Fabian Boehm
e2596d13cd Remove SIGUNUSED
It is, as the name implies, unused - it became SIGSYS, which we
already check.

Since it is entirely undefined on some architectures it causes a build
failure there, see discussion in #10633
2024-12-23 17:06:22 +01:00
Johannes Altmanninger
0153579a4c Fix build in non-colocated jj workspaces 2024-12-23 15:14:13 +01:00
Johannes Altmanninger
c1b460525c Temporary workaround for BSD WEXITSTATUS libc bug
The libc crate has a bug on BSD where WEXITSTATUS is not an 8-bit
value, causing assertion failures.

Any libc higher than our 0.2.155 would increase our MSRV, see libc
commit 5ddbdc29f (Bump MSRV to 1.71, 2024-01-07), so we want to
woraround this anyway.  It's probably not worth using a patched
version of libc since it's just one line.

While at it, tighten some types I guess.

Upstream fix: https://github.com/rust-lang/libc/pull/4213

Closes #10919
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
5de6f4bb3d Provide old implementation of cancel-commandline as fallback
__fish_cancel_commandline was unused (even before) and has some issues
on multiline commandlines. Make it use the previously active logic.

Closes #10935
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
54cc932215 Attempt to fix clippy lints 2024-12-23 14:34:59 +01:00
Johannes Altmanninger
e3864c752a Changelog: move integration branch entries there
See f237fb7b on the integration branch.
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
03a9f4a775 sourcehut builds: remove obsolete "env"
As of efe4083dce (fish.spec/.builds: drop SHOW_INTERACTIVE_LOG,
2022-06-08) this is no longer necessary.
2024-12-23 08:40:02 +01:00
Johannes Altmanninger
7e5af914be Remove interactive-only completion hacks
I don't think these characters cause problems in filenames?
2024-12-23 08:40:02 +01:00
Johannes Altmanninger
ab4606430e Sort parser keywords 2024-12-23 08:40:02 +01:00
Fabian Boehm
774b7c7b5b staticbuilds: Make mac builds statically linked
This is the default on musl, but not other libcen
2024-12-22 22:25:27 +01:00
Fabian Boehm
6b1a9ef7ce staticbuilds: Add macos job 2024-12-22 22:21:42 +01:00
Fabian Boehm
c74afd4198 CHANGELOG 2024-12-22 18:16:07 +01:00
Fabian Boehm
3dc49d9d93 Allow installable builds to be installed into a specific path (#10923)
* Pass path to install()

It was dirty that it would re-get $HOME there anyway.

* Import wcs2osstring

* Allow installable builds to use a relocatable tree

If you give a path to `--install`, it will install fish into a
relocatable tree there, so

PATH/share/fish contains the datafiles
PATH/bin/fish contains the fish executable
PATH/etc/fish is sysconf

I am absolutely not sold on that last one - the way I always used
sysconfdir is that it is always /etc. This would be easy to fix but
should probably also be fixed for "regular" relocatable builds (no
idea who uses them).

An attempt at #10916

* Move install path into "install/" subdir

* Disable --install harder if not installable
2024-12-22 18:16:07 +01:00
Integral
b19a467ea6
Replace some PathBuf with Path avoid unnecessary heap allocation (#10929) 2024-12-21 12:34:27 -06:00
Johannes Altmanninger
381b38af0a Skip tmux multiline prompt test for BusyBox less
BusyBox less is present on alpine CI; it doesn't support the "+q"
command passing style, so it's not directly usable by this test.
2024-12-21 14:41:41 +01:00
Johannes Altmanninger
965bc78d33 Work around weird CI failures due to missing pre-execute \r\n
I forgot that 610338cc70 (On undo after execute, restore the cursor
position, 2024-12-21) would cause a fallout to tests:

It makes us reuse in another place our usual cursor-movement sequences.

This causes failures like this (linebreaks added for readability):

	Testing file pexpects/bind.py:Failed to match pattern: (?:\r\n|\x1b\[2 q)[^\n]*def abc\r\n
	bind.py:45: timeout from expect_prompt(TO_END + "def abc\r\n")  # emacs transpose words, default timeout: no delay

	Escaped buffer:
	\x1b[?2004h\x1b[>4;1m\x1b[=5u\x1b=\rprompt 2>echo \rprompt 2>echo abc \rprompt 2>echo def abc\r
	prompt 2>echo def abc\x1b[?2004l\x1b[>4;0m\x1b[=0u\x1b>\x1b]133;C\x07def abc\r\n\x1b]133;D;0\x07\x1b[?25h⏎
	\r⏎ \r\rprompt 3>\x1b[?2004h\x1b[>4;1m\x1b[=5u\x1b=

It seems that we don't print anything where we should print something
like "\r\n" or "\e[2 q" to move the cursor below the command line.

I haven't gotten to the bottom of this but it might be related to
terminfo. Once we get rid of that, we can unconditionally print
our canonical movement sequences.

This issue seems to only affect tests, since fish operates fine in
a sourcehut CI system. Let's ignore it for now.
2024-12-21 14:37:57 +01:00
Johannes Altmanninger
610338cc70 On undo after execute, restore the cursor position
Ever since 149594f974 (Initial revision, 2005-09-20), we move the
cursor to the end of the commandline just before executing it.

This is so we can move the cursor to the line below the command line,
so moving the cursor is relevant if one presses enter on say, the
first line of a multi-line commandline.

As mentioned in #10838 and others, it can be useful to restore the
cursor position when recalling commandline from history. Make undo
restore the position where enter was pressed, instead of implicitly
moving the cursor to the end. This allows to quickly correct small
mistakes in large commandlines that failed recently.

This requires a new way of moving the cursor below the command line.
Test changes include unrelated cleanup of history.py.
2024-12-21 13:10:34 +01:00
Johannes Altmanninger
f9fb026085 Document possible CMake/Rust versions usable for Git bisect
rustc and CMake are usually backwards compatible but with Corrosion
in the mix this is often not the case.
Here's the canonical place to document it.
2024-12-21 13:07:01 +01:00
Johannes Altmanninger
1e7de063bd Fix regression of builtin read not exiting on ctrl-c
Commit 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30) stopped
ctrl-c from exiting without a motivation. Unfortunately this was
only noticeable on terminals that speak the kitty keyboard protocol,
which is probably no one had noticed so far.

Closes #10928
2024-12-21 05:54:52 +01:00
David Adam
541f8b47bf Revert "Add completions for dust"
This reverts commit 27c7578760.

dust generates its own completions (which are shipped in the wrong spot
in the Debian packages, but which are also more up-to-date).

Closes #10922.
2024-12-19 19:49:01 +08:00
David Adam
6eec2db292 fish.spec: update dependencies for the terminfo database
RH/Fedora and openSUSE use different package names.

Closes #10920.
2024-12-19 14:48:01 +08:00
Johannes Altmanninger
039011bc81 Make full autosuggestions case-correcting again
Fixes ca21872d14 (Clean up the accept-autosuggestion code path a
little bit, 2024-11-14).
Fixes #10915
2024-12-18 19:02:27 +01:00
metamuffin
9abec243a4
Completions for mksquashfs (#10909) 2024-12-18 10:36:30 -06:00
Fabian Boehm
f89e26b06e installable: Reword $HOME error 2024-12-18 17:26:25 +01:00
David Adam
80d53b129f macOS codesigning: use stable Rust
The apple-codesign crate has a fairly aggressive MSRV policy, and the
compiler itself still targets 10.12 which is well below the minimum
version of macOS for aarch64. Just use stable.
2024-12-18 23:38:13 +08:00