-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
refactor: Add Value
types, use std::span
for list iteration
#9370
Conversation
**`Value` and `const`** These two deserve some explanation. We'll get to lists later. Values can normally be thought of as immutable, except they are are also the vehicle for call by need, which must be implemented using mutation. This circumstance makes a `const Value` a rather useless thing: - If it's a thunk, you can't evaluate it, except by copying, but that would not be call by need. - If it's not a thunk, you know the type, so the method that acquired it for you should have returned something more specific, such as a `const Bindings &` (which actually does make sense because that's an immutable span of pointers to mutable `Value`s. - If you don't care about the type yet, you might establish the convention that `const Value` means `deepSeq`-ed data, but this is hardly useful and not actually as safe as you would supposedly want to trust it to be - just convention. **Lists** `std::span` is a tuple of pointer and size - just what we need. We don't return them as `const Value`, because considering the first bullet point we discussed before, we'd have to force all the list values, which isn't what we want. So what we end up with is a nice representation of a list in weak head normal form: the spine is immutable, but the items may need some evaluation later.
(But @tomberek is reviewing it too :)) |
A while ago we had to revert a use of |
I don't think we need to support that anymore. We have GCC 12.2 for aarch64-linux, in the flake here and in NixOS 23.05. |
Yeah the 23.05 bump solved that. |
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.
This should help make further improvements easier.
Motivation
I've done some work on exception safety in the evaluator that's resulting in some refactoring. I'm not done with it yet, but I believe these commits should be uncontroversial and I figured
StringWithContext
might be semi-useful for @tomberek's work on string performance.Changes:
Value
union
. They aren't used yet, but can be used to write more type safe helper functions.std::span
for accessing list values. That's a view of a contiguous memory region a dynamic number of instances of a certain type.string_view
is like aspan<char>
.const
is used. I've explained it in the second to last commit message.nix-env
is also basically a no-op, but makes it so that all list initialization happens through EvalState, which will be useful later.Context
Reasons why I'm looking into exception safety:
Priorities
Add 👍 to pull requests you find important.