REPL looses local variables after :edit #1195
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
awaiting
author
awaiting
contributors
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
diagnostics
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
Feature/S3
Importance
High
Importance
Low
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
Release Blocking
Non-urgent
Release Blocking
Urgent
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
Urgency
High
Urgency
Low
ux
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lix-project/lix#1195
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
After running a simple
:editcommand, I lost all my local variables, seemingly because the REPL is reloading.Steps To Reproduce
Note that when using repl-overlays, this displays
Loading 'repl-overlays'...andAdded 114 variables.which means it's actually reloading the REPL every time.Expected behavior
Local variables like
fnare still available after edit, and no reload is performed.nix --versionoutputAdditional context
I quickly tested CppNix 2.31.3 and it also happens, so this is not because of one of our changes and there's a lower chance it's a regression (though it's still possible, I haven't checked).
My vibe is that this is intentional: the workflow I think :e expects you to be using is to be doing nix repl -f . in nixpkgs and then it will reload after each of your changes so that you can re-run whatever expression you had again against your edited version.
We maybe should document that it's intended to reload (or test it somehow? maybe set a fucked up thing in $EDITOR? idk).
maybe it shouldn't reload if the file in question is in the nix store already since it would thus be immutable? dunno how useful that would actually be.
Personally I mostly use
:eto see the code of the function I'm calling, or to look around in a file, so while I'm just exploring and trying expressions out it's very annoying to loose all local variables.Since most of the time, the code i'm looking at is in the system's pinned nixpkgs, it might be fine if it only reloaded if the file is read-only/in the nix store, but it's still surprising behavior to me. Would it be possible to extend that to checking that the file being edited has the same hash before and after spawning the editor?
Ideally, the local bindings would still be in scope but their evaluator cache would be cleared so that they'd be recomputed; I'm just not sure how doable that is since i don't know much about the evaluator's internals. but if we can do that, all workflows would work as expected; we might have some performance hits in theory, but only in scenarios that weren't allowed before, so it's better than nothing.
But as it stands right now it's mildly/very annoying if you're trying to test more than just one expression (and/or you're not doing nixpkgs-hacking, which i suspect a large part of our users are not doing, and i'm not sure the "nixlang tutorial/exploratory entry point" that the REPL is should be geared towards nixpkgs maintainers).
not sure that's actually helpful because you may have navigated around in your editor session and changed other files instead, also influencing the reëvaluation result. but we could add a dedicated command for browsing sources instead without causing a reload, because that does sound pretty useful?
it's completely impossible in the current setup and will remain so for at least quite a while to come
i hear you, but i think that represents a fraction of a fraction of users, so doing a "best effort" solution is better than nothing in my opinion, and worse case scenario the user just has to do a
:rafter exiting the editor, which isn't too hard an ask imo.as for a hypothetical "viewing-only" command: i'm unsure how doable it might be to open
$EDITORin read-only mode without special-casing them (and then what do we do if it's one we don't don't special-case for?), and honestly I think it's too close to:eto really merit a separate command when we could instead ensure that:ereloads less oftenPersonally I would be rather surprised if people regularly use :e to ferret around random other files, edit them, then reload because that sounds like terrible ergonomics vs having a terminal multiplexer and hitting :r, so I would totally stamp a "don't reload if there's no changes" CL. Seems to improve the ergonomics of the common case, improving the overall average experience.
Worst case users who are doing that just hit :r, because I do find the reading case is way more common from my own experience.
Oh btw random idea, what if we supported
:h :eto surface better help text for commands? I'll file a ticket. e: #1201