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
Allow for stacks to have parents #11654
Conversation
Thanks a lot for this! I will probably be using parent stacks to refactor a bunch of other code later. If I might make a few suggestions: |
@IanManske is it possible you didn't hit "confirm" on your review? Not seeing any comments |
Thanks for pointing out I also renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out
Arc::into_inner
and handling ownership that way!
You're welcome!
I also renamed
stack
tostack_arc
when stack was actually anArc<Stack>
.
Great, this will help make things more clear, thanks!
Just a few more things to cleanup:
From a cursory look, the general idea seems fine. Just two comments:
|
Good point, maybe we could fall back to cloning the Arc::try_unwrap(stack).unwrap_or_else(|stack| {
// print error/warning or maybe just `debug_assert(false)` ?
(*stack).clone()
})
Personally, I would like to see more use of property based testing. But I guess it would be better to open a separate PR. |
Yeah, fallback cloning could work. We can definitely bring up the property-based testing, but it seems like a different topic than this PR. But yeah, more rigorous tests are always welcome. |
@kubouch the reasoning for the property tests:
The property test itself is fast, the dependency is only pulled in if you're working on EDIT: I would be OK sending in the proptest as a separate PR, but I would not want this PR to be merged without the proptest. I don't believe this changeset can be deemed any form of correct without it, absent some other refactoring of the variable storage. |
Regarding the panicking to avoid cloning... I do think we should treat an unintentional clone as a fatal error here. The performance is just so bad if you have cloning and anything big in the environment, that it's better for code that triggers a clone to be considered invalid from the first iteration. That's just my opinion though. I am OK putting in just an error message, though I think either a debug assert or a test-only assert (is that a thing?) so that it blows up in some circumstances feels very valuable to short circuit work that might be doomed to fail |
A debug assert should be fine (e.g., |
We talked with the core team about the proptest, and it would be better if you could extract useful unit tests for this PR and leave proptest for a further discussion. We used to have proptest but removed it, partially due to high execution time. More importantly, proptesting seems in principle similar to fuzzing, i.e., finding failure cases. As such, both fuzzing and proptest should run in a separate CI and discovered failure cases should be distilled as unit tests into the main test suite. We already have fuzzing in the nu-parser and nu-path crates. We could add proptest to the mix as well. And then set up a CI dedicated to these because we're not currently continuously fuzzing. But that is out of scope of this PR. |
Would you be against me checking in the property test into |
actually scratch that, I'll just delete the property test. Not that interested in fighting an uphill battle on this, and I've convinced myself the changes are OK. I'll generate some unit tests that should cover the problematic lines that I found through this. |
Adding the proptests into a separate file and putting it behind a feature (or env var, to me it seems feature would be cleaner) could be a good first step towards proptesting in Nushell in general, I wouldn't object that. |
OK I moved the property tests to a new file ( All the outstanding comments should be handled, and I've added 5 unit tests directly to |
OK, sounds good. Could you split the proptest itself into a separate PR? We can investigate there what happens with the |
Sorry, I was out and about last week. I'm trying to rebase off of the changes in #11860, and the entire control flow got changed up. Will ruminate on this a bit, but I think everything should still flow nicely. |
Actually it's not clear to me if stack parents are workable in this unwinding model. I want to checkpoint the stacks for potential unwinds, but I want to apply modifications to the stack. If we had a panic in between "I have modified the stack" and "I have completed the loop", then we need to recover the previous iteration. This seems to rule out the "simple" model in the current version of this branch (where we do a bunch of reads, then write at one point). I imagine this panicking is meant to catch issues with running commands, right? Not to speak too out of turn here but would we be against massively shrinking how much code is inside the (One idea: we just |
All good, thanks for working on this!
I think it should be possible. Here's one potential solution I have in mind:
|
Stacks with parents can avoid copying variables, so long as the parent is never mutated. This lets us avoid expensive cloning in the REPL
Alright, successfully rebased. This involved adding yet another Stack operation (
This involves a bit more fiddling around than before the panic catching tech, but I think it's still pretty reasonable, and at the end of the day less cloning than what we had before. Long term... the shell is still doing a lot of shuffling of stuff around in memory. In particular I hadn't really noticed the engine state copies before. But I feel like giant env vars are less ocmmon, for example. |
the test failure seems to be unrelated? I don't know how to retrigger a build for this kind of thing though
|
# Description Ignores some network tests that sometimes fail in CI. E.g., in [11953](#11953 (comment)) and [11654](#11654 (comment)).
Nice work! This looks good.
Yep, some network tests started to become unreliable recently, these tests have been disabled.
Yeah, there are a lot of clones throughout the code base for |
Co-authored-by: Ian Manske <ian.manske@pm.me>
Thanks for implementing this @rtpg ! Let's give it a go |
This is another attempt on #11288
This allows for a
Stack
to have a parent stack (behind anArc
). This is being added to avoid constant stack copying in REPL code.Concretely the following changes are included here:
Stack
can now have aparent_stack
, pointing to another stackStack
objects