tvl-depot/tvix/eval/docs
sterni fcd5e53703 fix(tvix/eval/builtins): force acc not list element in foldl'
When investigating discrepancies between foldl' in tvix and C++ Nix,
I discovered that C++ Nix's foldl' doesn't seem to be strict at all.
Since this seemed wrong, I looked into Haskell's foldl' implementation
which doesn't force the list elements (`val` in our code), but the
accumulation value (`res` in our code). You can look at the code here:
https://hackage.haskell.org/package/base-4.17.0.0/docs/src/GHC.List.html#foldl%27

This actually makes a lot of sense: If `res` is not forced after each
application of `op`, we'll end up thunks nested as deeply as the list is
long, potentially taking up a lot of space. This can be limited by
forcing the `res` thunk before applying `op` again (and creating a new
thunk).

I've also PR-ed an equivalent change for C++ Nix at
https://github.com/NixOS/nix/pull/7158. Since this is not merged nor
backported to our Nix 2.3 fork, I've not copied the eval fail test yet,
since it wouldn't when checking our tests against C++ Nix in depot.

Change-Id: I34edf6fc3031fc1485c3e714f2280b4fba8f004b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6947
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-10-11 15:53:29 +00:00
..
builtins.md docs(tvix/eval): pad pure column so it can fit "false" 2022-09-04 21:05:57 +00:00
known-optimisation-potential.md docs(tvix/eval): propose builtin "inlining" optimisation 2022-09-11 20:02:46 +00:00
language-issues.md fix(tvix/eval/builtins): force acc not list element in foldl' 2022-10-11 15:53:29 +00:00
opcodes-attrsets.md docs(tvix/eval): add design documentation for attrset opcodes 2022-08-13 15:31:50 +00:00
recursive-attrs.md docs(tvix/eval): note C++ implementation details for C++ Nix 2022-09-18 15:01:34 +00:00