refactor(completer)!: don't require Send on the Completer trait#1092
Open
kronberger-droid wants to merge 1 commit into
Open
refactor(completer)!: don't require Send on the Completer trait#1092kronberger-droid wants to merge 1 commit into
kronberger-droid wants to merge 1 commit into
Conversation
The `unsafe impl Send` on `HistoryCompleter` was sound (a pub(crate) stack-local, never sent across threads) but it revealed that `Completer: Send` is too tight: not every completer needs to be Send. Drop `Send` from the `Completer` trait and require it only on the owned completers stored in `Reedline` and `ReedlineMenu::WithCompleter`, now `Box<dyn Completer + Send>`. The `unsafe` falls away with no new bound on `History`, so `SqliteBackedHistory` (`!Sync` connection) stays untouched. Alternative to nushell#929, which fixed the same `unsafe` via `History: Sync` but broke the sqlite backend. Adds `reedline_is_send` as a compile-time guard. BREAKING CHANGE: `Completer` no longer requires `Send`. `with_completer` and `ReedlineMenu::WithCompleter` now take `Box<dyn Completer + Send>`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or 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.
The
unsafe impl SendonHistoryCompleterwas actually sound: it's apub(crate)type only ever created as a stack local and borrowed into menus, never sent across threads.But it pointed at a trait that's too tight, since
Completer: Sendforces every completer to beSend.So instead of asserting
Sendwhere it isn't required, this drops it from theCompletertrait and requires it only on the completers that are actually owned and stored, thus inReedlineandReedlineMenu::WithCompleter, nowBox<dyn Completer + Send>.The
unsafefalls away naturally, with no new bound onHistory, soSqliteBackedHistory(whoserusqlite::Connectionis!Sync) is untouched.This is an alternative to #929, which tightened
History: Syncto fix the sameunsafebut broke the sqlite backend as a result.Added
reedline_is_sendas a compile-time guard on the relocated bound.API note:
with_completerandReedlineMenu::WithCompleternow takeBox<dyn Completer + Send>. Source-compatible (the oldCompleter: Sendalready required it), but visible in signatures.