about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-09-06 r/4659 fix(tvix/eval): instantiate *new* closures from blueprints each timeVincent Ambo1-3/+6
The previous closure refactoring introduced a bug in which the same closure object would get mutated constantly for each instance of a closure, which is incorrect behaviour. This commit instead introduces an explicit new Value variant for the internal "blueprint" that the compiler generates (essentially just the lambda) and uses this variant to construct the closure at runtime. If the blueprint ever leaks out to a user somehow that is a critical bug and tvix-eval will panic. As a ~treat~ test for this, the fibonacci function is being used as it is a self-recursive closure (i.e. different instantiations of the same "blueprint") getting called with different values and it's good to have it around. Change-Id: I485de675e9bb0c599ed7d5dc0f001eb34ab4c15f Reviewed-on: https://cl.tvl.fyi/c/depot/+/6323 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-09-06 r/4658 fix(tvix/eval): correctly thread through dynamic upvaluesVincent Ambo1-1/+7
This puts together the puzzle pieces for threading dynamic upvalues (that is, upvalues resolved from the `with`-stack) all the way through. Reading the test case enclosed in this commit and walking through it is recommended to understand what problem is being tackled here. In short, because the compiler can not statically know *which* with-scope a dynamic argument is resolved from it needs to lay the groundwork for resolving from *all* possible scopes. There are multiple different approaches to doing this. The approach chosen in this commit is that if a dynamic upvalue is detected, the compiler will emit instructions to close over this dynamic value in *all* enclosing lambda contexts. It uses a new instruction for this that will leave around a sentinel value in case an identifier could not be resolved, and wire the location of this found value (or sentinel) up through the upvalues to the next level of nesting. In this tradeoff, tvix potentially closes over more upvalues than are needed (but in practice, how often do people create *really* deep `with`-stacks? and in *this* kind of code situation? maybe we should even warn for this!) but avoids keeping the entire attribute sets themselves around. Looking at the test case, each surrounding closure will close over *all* dynamic identifiers that are referenced later on visible to it, but only the last one for each identifier will actually end up being used. This also covers our bases for an additional edge-case this creates, in which an identifier potentially resolves to a dynamic upvalue *and* to a dynamic value within the function's own scope (again, would anyone really do this?) by introducing a resolution instruction for that particular case. There is likely some potential for cleaning up this code which is quite ugly in some parts, but as this implementation is now carefully calibrated to work I decided it is time to commit it and clean it up in subsequent commits. Change-Id: Ib701e3e6da39bd2c95938d1384036ff4f9fb3749 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6322 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-09-04 r/4635 feat(tvix/eval): implement upvalue resolution in `with` scopesVincent Ambo1-0/+11
These need to be handled specially by the runtime if the compiler determines that a given local must be resolved via `with`. Note that this implementation has a bug: It currently allows `with` inside of nested lambdas to shadow statically known identifiers. This will be cleaned up in the next commit. Change-Id: If196b99cbd1a0f2dbb4a40a0e88cdb09a009c6b9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6299 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-09-03 r/4626 feat(tvix/eval): add Value::to_closureVincent Ambo1-0/+11
... same as the others Change-Id: I9c8868388c10b0b6484c5bdd3799d801296c6979 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6292 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-09-03 r/4613 refactor(tvix/eval): rename Value::NotFound & OpAttrOrNotFoundVincent Ambo1-3/+3
grfn suggested clearer naming for these in cl/6166. Change-Id: I83164bf1d1902ebd42272e9d5d63819a0f6a72c5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6277 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
2022-09-03 r/4611 refactor(tvix/eval): get rid of Value::Blackhole variantVincent Ambo1-3/+1
This is no longer needed for anything and the extra clone here is not really more costly than constructing a blackhole value in a different place. Change-Id: I5c63085b1b4418b629ea58a42e3bfe9a9b586d76 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6275 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
2022-09-03 r/4605 refactor(tvix/eval): introduce Closure struct in Value typeVincent Ambo1-5/+5
This struct will carry the upvalue machinery in addition to the lambda itself. For now, all lambdas are wrapped in closures (though technically analysis of the environment can later remove innermost Closure wrapper, but this optimisation may not be worth it). Change-Id: If2b68549ec1ea4ab838fdc47a2181c694ac937f2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6269 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
2022-09-02 r/4585 feat(tvix/eval): add initial representation of builtinsVincent Ambo1-1/+5
Builtins are represented as a Rust function pointer that accepts a vector of arguments, which represents variable arity builtins. Change-Id: Ibab7e662a646caf1172695d876d2f55e187c03dd Reviewed-on: https://cl.tvl.fyi/c/depot/+/6251 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-09-01 r/4574 feat(tvix/eval): introduce initial `Lambda` typeVincent Ambo1-0/+6
Change-Id: Ifa9766f5ffeff99e926936bafd697e885e733b78 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6238 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-09-01 r/4571 feat(tvix/eval): carry optional SyntaxNode in error typeVincent Ambo1-11/+16
This starts paving the way for nicer, source-code based error reporting. Right now the code paths in the VM do not emit annotated errors, as we do not yet preserve that structure from the compiler. However, error emitting code paths in the compiler have been amended to include known nodes. Change-Id: I1b74410ffd891c40cd913361bd73c4336ec8aa5b Reviewed-on: https://cl.tvl.fyi/c/depot/+/6235 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-31 r/4555 feat(tvix/eval): add Value::as_attrs methodVincent Ambo1-0/+10
Change-Id: I2f39122ac85b67837335aab308d845907160e132 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6221 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
2022-08-30 r/4542 fix(tvix/eval): allow use of ? operator on non-set typesVincent Ambo1-1/+1
Nix allows this, but always returns false. Tvix needs to do the same. Change-Id: Ic9eec90834a0d0969eea5316d5c25032d3691d94 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6209 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
2022-08-30 r/4537 fix(tvix/eval): address various clippy lintsVincent Ambo1-8/+4
Change-Id: I3ea0f51475e80948adfeb5d1620c1f2665cc39bc Reviewed-on: https://cl.tvl.fyi/c/depot/+/6201 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-27 r/4516 chore(tvix/eval): add variant_size_differences warning to `Value`Vincent Ambo1-0/+1
Change-Id: I2f4719a81512a9a970edf22390afed490125bda7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6182 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-27 r/4515 feat(tvix/eval): add Path representation to Value enumVincent Ambo1-1/+4
Change-Id: I4827384201912131ea8fc2362188dcd862b94852 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6181 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-27 r/4514 refactor(tvix/eval): use `write!` macro instead of `f.write_fmt`Vincent Ambo1-5/+4
grfn pointed out in cl/6082 that this is actually the desugaring of the write! macro, so it doesn't make sense to write it out. Change-Id: If7c055b042ad22b034722aec1eaadba92736d684 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6180 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
2022-08-26 r/4499 feat(tvix/vm): add opcodes for new Value::NotFound sentinelVincent Ambo1-3/+5
This sentinel value is going to be used for certain nested accesses into attribute sets. There is a new instruction similar to `OpAttrsSelect` which leaves the sentinel on the stack if a key is not found, instead of raising an error. Additionally, a new jump instruction makes its jump operation conditional on finding such a sentinel value. Change-Id: I2642f0a0bcc85bbe0ead68ea09a7dd794dbedeac Reviewed-on: https://cl.tvl.fyi/c/depot/+/6166 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-26 r/4497 chore(tvix/eval): implement improved Display for internal valuesVincent Ambo1-1/+2
Having these visible more explicitly is useful while debugging. Change-Id: I86b497883063d32792b635eb4514b7aeae484af4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6164 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
2022-08-26 r/4491 fix(tvix/eval): add operation to assert boolean typeVincent Ambo1-0/+4
This operation is required because both sides of the logical operators are strictly evaluated by Nix, even if the resulting value is not used further. For example, in our implementation of `&&`, if the left-hand side is `true`, then the result of the expression is simply the right-hand side value. This value must be asserted to be a boolean for the semantics of the language to work correctly. Change-Id: I34f5364f2a444753fa1d8b0a1a2b2d9cdf7c6700 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6157 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
2022-08-25 r/4483 feat(tvix/eval): implement if/else expressionsVincent Ambo1-2/+2
These expressions use simple jumps to skip the correct expression conditionally in the bytecode by advancing the instruction pointer. Note that these expressions are already covered by a test behind the `nix_tests` feature flag, but adding more is probably sensible. Change-Id: Ibe0eba95d216321c883d3b6b5816e2ab6fe7eef1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6148 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-25 r/4479 feat(tvix/eval): implement list concatenationVincent Ambo1-0/+10
Change-Id: Icdf715d116371a9f139bdf95266410bf967bef25 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6144 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
2022-08-25 r/4475 feat(tvix/eval): implement attrset update (`//`) operatorVincent Ambo1-0/+10
The underlying implementation does a few tricks based on which pair of attrset representations is encountered. Particularly the effect of short-circuiting the empty cases might be relevant in nixpkgs/NixOS, due to the use of lib.optionalAttrs. Change-Id: I22b978b1c69af12926489a71087c6a6219c012f3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6140 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
2022-08-25 r/4469 fix(tvix/value): fix display representation of floatsVincent Ambo1-1/+7
Nix displays a maximum of 5 digits for floating points. Change-Id: Ifa3c0d96fa0b24e3be8f94dfebc99e602a258355 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6133 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-24 r/4454 refactor(tvix/value): encapsulate attrset logic within value::attrsVincent Ambo1-2/+3
The internal optimisations of the set representation were previously leaking into the VM, which is highly undesirable. Keeping it encapsulated allows us to do additional optimisations within value::attrs without being concerned about its use in the VM. Change-Id: I7e7020bb0983b9d355d3db747b049b2faa60131f Reviewed-on: https://cl.tvl.fyi/c/depot/+/6108 Reviewed-by: eta <tvl@eta.st> Tested-by: BuildkiteCI
2022-08-13 r/4441 refactor(tvix/value): explicitly implement PartialEq for valueVincent Ambo1-1/+26
There are some notions of equality (due to e.g. different backing variants for types, or Nix particularities) that don't work correctly when deriving PartialEq. Change-Id: Ide83ae67d051cc0b3ca89cefb283f17d0207acce Reviewed-on: https://cl.tvl.fyi/c/depot/+/6105 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 r/4439 feat(tvix/eval): construct internal attribute path representationVincent Ambo1-0/+10
This is required for constructing nested attribute sets at runtime. There'll be quite a lot of optimisation potential with this solution eventually, if it should turn out to be a bottleneck. This introduces a conceptual change, in that the `Value` enum is now an enum representing "all runtime values" instead of "all Nix language types". This makes sense in general, as this type will also contain Chunk representations etc. which are not exposed to users. Change-Id: Ic5f72b2a0965b146c6a451efad34c6a81ca1aad8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6103 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
2022-08-13 r/4429 feat(tvix/value): add runtime representation of simple listsVincent Ambo1-0/+5
There might be more logic in the future to encapsulate different backing implementations of lists as well. Change-Id: Ib7064fab48bf88b0c8913b0ecfa2108177c7c9fd Reviewed-on: https://cl.tvl.fyi/c/depot/+/6093 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: tazjin <tazjin@tvl.su>
2022-08-13 r/4425 feat(tvix/value): add some necessary helpers for stringsVincent Ambo1-2/+12
Deriving Ord/Eq is required for the ordered BTreeMaps. Once interning is implemented this will require some extra magic for the sort order, but that's fine. Change-Id: I0c654648eb3609a4a01d84868c25f43a4d35bc2e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6089 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 r/4423 feat(tvix/eval): add Value variants for strings & attrsetsVincent Ambo1-3/+12
Change-Id: Idebf663ab7fde3955aae50f635320f7eb6c353e8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6087 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 r/4422 feat(tvix/eval): add module for attribute set implementationsVincent Ambo1-0/+1
Change-Id: I6002bd5e5596b93325dea6c862370ba5235c0f08 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6086 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 r/4421 feat(tvix/eval): add module for string type implementationVincent Ambo1-0/+56
Change-Id: I5e4465acc4a676c10d7374b14f7a09240202b466 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6085 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>