Commit graph

859 commits

Author SHA1 Message Date
Vincent Ambo
712f1167ad feat(tvix/eval): display function names in documentation
... if they are known. We currently do not propagate names correctly
for curried functions.

Change-Id: I19d57fb30a5c0000ccdf690b91076f6b2191de23
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7596
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-22 19:09:40 +00:00
Vincent Ambo
e3f81e8d3b feat(tvix/cli): add :d REPL-prefix to print explanations of values
Change-Id: I1dd8de8d996e07840f9b0aaebf932b812103a43a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7593
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-22 19:09:40 +00:00
Vincent Ambo
e306d1d1a1 feat(tvix/eval): add Value::explain method
This value creates a human-readable explanation of a value. This can
be used to implement documentation related functionality.

For some values, the amount of information displayed can be expanded
quite a bit.

Change-Id: Ie8c400feae909e7680af163596f99060262e4241
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7592
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-22 19:09:40 +00:00
Vincent Ambo
ea7d63e177 feat(tvix/cli): implement NixCompatIO helper type
This type allows for temporarily compatibility with the C++ Nix store,
specifically (for now) it gives us the store directory used by Nix and
imports files the same way.

Change-Id: I4767794ef2863eba49661315c63c4e17de946d60
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7587
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-22 19:09:40 +00:00
Florian Klink
40a17acdc1 feat(tvix): add crate2nixGenerate target
`mg run //tvix:crate2nixGenerate --` runs crate2nix generate and
depotfmt's it afterwards.

This removes a frequent point of friction, because the Cargo.nix emitted
by crate2nix needs another formatter.

Change-Id: I649495980718cd3847d4cff77c9d4bfcb599387c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7612
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-22 15:26:41 +00:00
Florian Klink
2e04f68df8 feat(tvix/proto): add rpc_directory.proto
This provides an interface to retrieve and upload single Directory
messages, or a DAG of them.

Change-Id: Id9e7084bd697d843649a122da2c992a3e36d808c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7137
Tested-by: BuildkiteCI
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-12-22 14:35:32 +00:00
Florian Klink
870cd533dd feat(tvix/proto): add rpc_pathinfo
This defines a service that can be used to upload and retrieve metadata
of nix paths.

Change-Id: Id86eb531ce4ae316adb15934b0d1386a14ba2132
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7136
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-12-22 14:35:32 +00:00
Vincent Ambo
22ed59fabd chore(tvix/eval): fix a broken comment
Change-Id: I0a6edb51685f94d4712089ae805170da3fb7faae
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7609
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-21 23:29:26 +00:00
Vincent Ambo
908cebf35c fix(tvix/builtin-macros): parse multi-line docstrings correctly
Having a multi-line docstring yields multiple doc-attributes in order,
however we were previously discarding all but the first one.

This reduces them into a single string instead, which can then be
displayed as multi-line documentation.

Change-Id: I1f237956cdea2e4c746d3f13744e0373c1c645a6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7594
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-21 23:05:22 +00:00
Vincent Ambo
270b1084e8 feat(tvix/eval): use EvalIO::import_path when coercing paths
This "ties the knot" of importing files into a store when referring
to them through path literals, e.g. inside of strings.

I'm not yet sure if this interface is sufficient for
builtins.path (which we haven't implemented at all yet), but it's
enough to wire up eval & store initially.

In the default implementations nothing interesting happens in this
function at all.

Change-Id: Ie01ff4161617d1e743a68dbd1a5e54c1b40c0990
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7582
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:59:18 +00:00
Vincent Ambo
edd13573f5 refactor(tvix/eval): use light spans in builtins.import
Change-Id: I05732073155b430575babb6f076bf465aef98857
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7581
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 22:59:18 +00:00
Adam Joseph
947a56c4b6 feat(tvix/eval): builtins.storeDir
Returns the store directory through EvalIO::store_dir.

Note that this is _optional_ in Tvix, as an evaluation can occur in a
context where there simply is no store directory. In those contexts,
`builtins.storeDir` returns `null` in Tvix.

This would only happen in contexts like Tvixbolt (or completely
unrelated use-cases) in practice.

Co-Authored-By: Vincent Ambo <tazjin@tvl.su>
Change-Id: I5a752c7e89b2f75bd7efb082dbfa5b25e3b1ff3b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7452
Autosubmit: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 22:59:18 +00:00
Vincent Ambo
4cb9ada0df refactor(tvix/eval): use EvalIO::read_dir for equivalent builtin
Change-Id: I6d782c07166f51587d2f1d06607823268debb5d5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7574
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:59:18 +00:00
Vincent Ambo
51deadd983 refactor(tvix/eval): use EvalIO::path_exists for the builtin
Change-Id: I49822ce30137777865e7370ee86666636e277b35
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7573
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 22:53:02 +00:00
Vincent Ambo
ec3e38c2d6 chore(tvix/eval): gate tvix_eval::StdIO behind the impure feature
This shouldn't be available if we've built a "pure" crate.

Change-Id: I7c85827ee212890252ff7e0b6242e2c52618cba5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7572
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 22:53:02 +00:00
Vincent Ambo
29790147b6 fix(tvix/cli): use tvix_eval::StdIO in CLI
... until we have a store-I/O layer, or something that intercepts the
store-related stuff appropriately.

Change-Id: I22f63435b3f9e118e3faeb2924fda8373a23ea7f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7568
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:37:11 +00:00
Vincent Ambo
0ef3c2fc2b refactor(tvix/eval): use EvalIO::read_to_string in impure builtins
With this change, the behaviour of reading a string from a file path
is controlled by the provided `EvalIO` structure.

This is a huge step towards abstracting away I/O behaviour correctly.

Change-Id: Ifde8e46cd863b16e0301dca45a434ad27560399f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7567
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 22:37:11 +00:00
Vincent Ambo
c3c4d752c9 feat(tvix/eval): add EvalIO to public crate API
This lets users set the `io_handle` field on an `Evaluation`, which is
then propagated to the VM.

Change-Id: I616d7140724fb2b4db47c2ebf95451d5303a487a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7566
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:37:11 +00:00
Vincent Ambo
25fc6b7c25 feat(tvix/eval): introduce initial EvalIO trait
This trait is going to be used to abstract filesystem interactions in
Tvix.

For now, it only contains a `read_to_string` method that closely
mirrors `std::fs::read_to_string`.

As a first step, to see how this works in practice, we will thread
through only this function to the various relevant parts.

Two implementations are provided in tvix-eval itself: A dummy
implementation (which just returns ErrorKind::NotImplemented for all
operations), and a std implementation which delegates to `std`
functions.

Change-Id: Ied3e3bf4bd0e874dd84e166190e3873a0f923ddb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7565
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:37:11 +00:00
Vincent Ambo
bf286a54bc refactor(tvix/eval): add a LightSpan type for lighter span tracking
This type carries the information required for calculating a
span (i.e. the chunk and offset), instead of the span itself. The span
is then only calculated in cases where it is required (when throwing
errors).

This reduces the eval time for
`builtins.length (builtins.attrNames (import <nixpkgs> {}))` by *one
third*!

The data structure in chunks that carries span information reduces
in-memory size by trading off the speed of retrieving span
information. This is because the span information is only actually
required when throwing errors (or emitting warnings).

However, somewhere along the way we grew a dependency on carrying span
information in thunks (for correctly reporting error chains). Hitting
the code paths for span retrieval was expensive, and carrying the
spans in a different way would still be less cache-efficient. This
change is the best tradeoff I could come up with.

Refs: b/229.
Change-Id: I27d4c4b5c5f9be90ac47f2db61941e123a78a77b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7558
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 22:21:25 +00:00
Vincent Ambo
8b3d03db92 chore(tvix/cli): rename binary to just 'tvix'
Change-Id: If735c81a04f60dcd77f1c40b595b52ed88bbbe95
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7580
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: flokli <flokli@flokli.de>
2022-12-21 21:48:08 +00:00
Adam Joseph
da7c331d2c feat(tvix/eval): add thunks with suspended native Rust code
Having thunks which, when forced, execute native Rust code rather
than interpreted opcodes lets us avoid having to bundle
`src/libexpr/primops/derivation.nix` like cppnix does by implementing
it in Rust instead.

Change-Id: If91d77a6736234321eee87ba4b4777eed5a3fe1c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7450
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 21:48:08 +00:00
Vincent Ambo
87995ed355 refactor(tvix/eval): add name-based index over compiler's locals
Instead of finding locals by doing 2x O(n) walks over the compiler's
locals list, use a secondary name-based index for resolving locals by
name.

Previously, almost 60% (!!) of eval time on some expressions over
nixpkgs was spent in `Local::has_name`. This function doesn't even
exist anymore now, and eval speed about doubles as a result.

Note that this doesn't exactly make the locals code easier to read,
but I'm also not sure what we can simplify in there in general.

This fixes b/227.

Change-Id: I29ce5eb9452b02d3b358c673e1f5cf8082e2fef9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7560
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 21:48:08 +00:00
Adam Joseph
922bf7aca9 feat(tvix/eval): remove derive(Copy) from Upvalues
Change-Id: I0fa069fbeff6718a765ece948c2c1bce285496f7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7449
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 14:50:04 +00:00
Adam Joseph
e04b1697e4 feat(tvix/eval): wrap Closure in Rc<> to match cppnix semantics
Change-Id: I595087eff943d38a9fc78a83d37e207bb2ab79bc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7443
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 14:50:04 +00:00
Vincent Ambo
b3c34c3c61 docs(tvix/nar): document how to use NAR writer
This is done in the form of some comments on the functions, as well as
a functional doctest that writes a single file to a NAR.

Change-Id: Ic97ebd439e91d6b076685807fe70de098ec02575
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7599
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
2022-12-21 14:31:54 +00:00
Vincent Ambo
a95dea719f chore(tvix/nar): add CI build target
Change-Id: Ic73a391da9a733cade26114ab1127907c8d62a57
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7598
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-21 14:08:30 +00:00
Vincent Ambo
f467df06dc chore(tvix/cli): re-add observer flags
Users can again pass flags for dumping the AST, bytecode, and runtime
trace.

With this commit the CLI is at feature-parity with what we had before,
but entirely through the new API.

Change-Id: I30fe26f243224b25d1e4f828fec607325ef88306
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7550
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 13:23:38 +00:00
Vincent Ambo
60d9fba56d chore(tvix/cli): re-add NIX_PATH handling
Change-Id: I5595d6f5141ed4a533ca44a46264dc604fca6be1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7549
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 13:23:38 +00:00
Vincent Ambo
36eaa9b3b3 chore(tvix/cli): re-add --raw argument
Change-Id: I82f469f7f186c754c40bd941587b30aa3fc48045
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7548
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 13:23:38 +00:00
Vincent Ambo
6d3d237923 refactor(tvix/eval): consume self in Evaluation::evaluate
This simplifies lifetime management for observers in callers of tvix_eval.

Change-Id: I2f47c8d89f22b1c766526e5d1483c0d026b500ae
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7546
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 13:23:38 +00:00
Vincent Ambo
59e695a9d9 feat(tvix/eval): add observer configuration to public API
With this change, it should be possible to have both existing
use-cases (CLI & Tvixbolt) use the same API.

Change-Id: I2195264f08cc892177b559a28660dc5f98e48e41
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7545
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 13:23:38 +00:00
Vincent Ambo
9bc1e6ef05 feat(tvix/eval): add configuration of Nix search path to public API
This is required for passing through NIX_PATH from the CLI.

Change-Id: If129df79ef9c3ffab31408adb85679909276c4f0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7544
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-21 13:23:38 +00:00
Vincent Ambo
9d6ee5b6a6 fix(tvix/eval): use test-generator fork that supports workspaces
This should make no difference in Nix builds, but allows running tests
locally again with `cargo test` for //tvix/eval.

Change-Id: I97d61840143d5c14db61d5862781bf635f9a28e7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7590
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
2022-12-21 13:23:38 +00:00
Vincent Ambo
257c67f204 chore(tvix): upgrade to clap 4.0
In //tvix/eval:

* criterion bumped to 4.0, which at least depends on clap 3.x instead
  of 2.x, which is less incompatible

In //tvix/cli:

* no changes required

In //tvix/nix_cli:

* some minor changes for compatibility with clap 4.0, no functionality
  changes

Change-Id: If793f64b59fcaa2402d3d483ddbab4092f32df03
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7588
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 13:23:38 +00:00
Vincent Ambo
d9e2bec953 refactor(tvix): split binary (REPL etc.) out from evaluator library
The tvix-eval project is independent from any *uses* of the evaluator,
such as the tvix-repl.

This functionality has been split out into a separate "tvix-cli"
crate. Note that this doesn't have to mean that this CLI crate is the
"final" CLI crate for tvix, the point of this is not "getting the CLI
structure right" but rather "getting the evaluator structure right".

This reshuffling is part of restructuring the way that functionality
like store communication is injected into language evaluation.

Note that at this commit the new CLI crate is not at feature-parity.

Change-Id: Id0af03dc8e07ef09a9f882a89612ad555eca8f93
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7541
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-12-21 13:09:29 +00:00
Vincent Ambo
1138fbcaad refactor(tvix/eval): use new public API in test code
This removes internal uses of the previous crate::eval module, which
is being removed.

Change-Id: I5fb3c53460a9c5381853d0258f9ed074ab23c630
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7543
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-12-21 13:09:28 +00:00
Vincent Ambo
d101151fc5 feat(tvix/eval): begin introducing new public API
A step towards something more like how I imagine the future public API
for tvix-eval. Please note that this is definitely not the final
version yet, but it's better than the previous API that either exposed
a side-effecting blackbox, or a very low-level "interface".

The basic idea is that an evaluation of some Nix code is requested by
a caller with various parameters, but not all callers are interested
in all of these parameters.

There are also some bits of information that are returned from an
evaluation that are not necessarily relevant to all callers.

To support this somewhat ergonomically, the API is built around an
`Evaluation` struct that is configured by the caller with the various
parameters and then "executed".

Change-Id: I71826f3897126898adc2873d31c44d3eaf5c2be0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7542
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-21 13:09:27 +00:00
edef
15e98314cc feat(tvix/nar): init writer
Change-Id: I101f35840cb14c58af708c91e59f997f6d167f75
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7505
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
2022-12-20 15:59:44 +00:00
Florian Klink
5f9796cf94 feat(tvix/proto): add rpc_blobstore
This defines a service that can be used to get and put content-addressed
chunks of data.

Change-Id: I36cf2278ed1daf71848c04fdfd14450b2268c5de
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7135
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-12-15 19:10:26 +00:00
Vincent Ambo
64f812b2f0 refactor(tvix): provide a combined //tvix:shell mkShell target
Manually maintained shell target based on the previous "loose"
`shell.nix` file.

We might want to have a function that combines the dependencies of all
the targets automatically, but at a quick glance that was actually
non-trivial so I'm leaving it as an exercise for someone else.

Change-Id: I74754940088f1b58e3b6754fb782470c80ea4292
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7540
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-12-15 17:26:45 +00:00
Vincent Ambo
3aca3d3bba refactor(tvix): build Rust projects using crate2nix
Introduces granular dependency builds using crate2nix, bootstrapped
off the generated configuration from the newly introduced
workspace (see cl/7533).

This commit checks in the generated Cargo.nix file which can be
regenerated with a parameterless invocation of `crate2nix generate` in
`//tvix`. I tried generating this in IFD, but it turned out to be
harder than what seemed worthwhile for now.

In this setup, the various build targets for Rust projects end up
being attributes of the imported `Cargo.nix` file at the `tvix.crates`
attribute. These still lack configuration, however, which has been
fixed in the various `default.nix` files of individual projects.

Note that we (temporarily) lose the ability to build tvix-eval's
benchmarks in CI. I haven't figured out what magic incantation summons
them from the void again ...

The `eval-okay-readDir` tests from both test suites have been disabled
because they fail for unknown reasons when run in this new derivation.
Somebody will have to debug it!

Change-Id: I2014614ccb9c8951aedbd71df7966ca191a13695
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7538
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
2022-12-15 17:26:45 +00:00
Vincent Ambo
d9d627cdf0 refactor(tvix): share a Cargo.lock file between Rust projects
This relates to the (abandoned) cl/7256.

Introduces a Cargo workspace at //tvix that is primarily intended to
be used as a workaround for the annoying Nix+Rust tooling while having
a consistent set of dependencies.

This is driven in part by a desire to adopt crate2nix and get more
granular Nix builds for Tvix's Rust projects, and in part by a need to
split //tvix/eval into something providing the CLI (REPL etc.), and a
library providing eval, without significantly altering the structure
of build targets.

To accomplish this the workspace has been designed to allow projects
to remain independent build targets. I want to avoid lumping all the
projects together - something like //tvix/eval should always be
independent of other parts of tvix.

A helper function in //tvix/default.nix lets downstream naersk
projects construct a sparse root for the project which combines the
workspace's `Cargo.lock` with the project's own `Cargo.toml`.

Note that cargo commands in the workspace itself require the build
dependencies of _all_ projects to be present, which is currently a bit
annoying to accomplish.

This introduces some breakage:

1. It breaks usage of rust-analyser without being in a shell with the
   dependencies of *all* Tvix projects, as it is not capable of
   respecting only the subset of dependencies for a part of the
   workspace.

2. It is no longer possible to run tests using `cargo test`, as the
   test generation crate we use does not work with workspaces:

   https://github.com/frehberg/test-generator/issues/6

   This still works in the Nix build as we construct a Cargo project
   that looks like it's not in a workspace there. Until somebody fixes
   that crate / writes a new macro / does something else with the test
   suite, the way to run the tests is through the Nix build.

Long-term we'll probably want to get rid of cargo completely, it's
just a big wart and most tooling works without it if correctly
configured, but we don't have time for that now.

Change-Id: I846bff7a8429a25c077fd1e9ef4e3c34a299a4a1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7533
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-15 17:26:45 +00:00
Vincent Ambo
0fd956f248 fix(tvix): remove disruptive .envrc file
This .envrc file causes additional software to be loaded, but there is
no way to opt-out even if the software is not desired:

1. If I opt-in (i.e. `direnv allow`) the file, additional stuff that I
   don't need is injected into my environment in a blocking way.

2. If I opt-out, *all* of the depot configuration (including `mg`) is
   unloaded, as direnv configurations do not trivially nest.

I have to work around this constantly by making the file contain just
the line `source_up` and then setting `--assume-unchanged` on the git
index to avoid accidentally committing the file changes.

This is kind of silly, the people who *want* this stuff to be loaded
should devise a mechanism that loads it automatically but is opt-in.

This could be done e.g. by gating something on environment variables,
or having a shell hook, or whatever. Breaking expectations that hold
elsewhere in depot is not okay, however.

If you manually want a shell for a project, run `mg shell` either with
a target specification for that project (e.g. `mg shell //tvix/store`)
or in the project's folder.

You can also just use standard nix-shell invocations.

Change-Id: I0de43378424d0cb1e1279c72c47940fecf497bf0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7531
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
2022-12-15 17:26:45 +00:00
Vincent Ambo
f282984c25 fix(tvix/eval): use rnix-parser from crates.io
A few weeks ago, oberblastmeister did a release to crates.io so we can
stop importing it via GitHub.

Change-Id: I9d5fa5cd281685779c71b12fed45ed201a1db17e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7532
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-12-06 18:29:50 +00:00
Florian Klink
0a4a0d1c6b feat(tvix/store): add size() and digest() functions for Directory
Change-Id: I3a9e3c77da1d5d7bfb93da0cd7bce8d48dbc8cd4
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7254
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-04 10:41:39 +00:00
Florian Klink
a97e3726df feat(tvix/store): build rust proto files
This uses prost-build to build the proto files.

Change-Id: Ia99fcfa4a19c741683cf28a45202e1d9211f9131
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7286
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-12-04 10:41:39 +00:00
Florian Klink
c432aae9b3 feat(tvix/store): init
Change-Id: Id846647fa456ff8b187ed4f16d035ce030f11d25
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7264
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <tazjin@tvl.su>
2022-12-04 10:41:39 +00:00
Florian Klink
12413a669f feat(tvix/store): add pathinfo.proto
This adds the PathInfo message, which hosts information about a Nix
Store path, mapping to either of a {Directory,File,Symlink}Node.

Change-Id: I79d871b6fad450d6a4ae4101fb72c51f9a83471f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7132
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-04 10:41:39 +00:00
Florian Klink
ff5e041fdb chore(tvix/store): move castore.proto
This moves the castore.proto file into the //tvix/store/protos directory. Per-
component protos might make more sense, than a "tvix-wide" proto directory.

Change-Id: Ie728210174b041e9285a0e2ac605d715d0f0cbda
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7285
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-04 10:41:39 +00:00
Lyle Mantooth
f4e17caae8 feat(tvix/eval): Continue removing leakage of BTreeMap.
Fixes b/212. Based on feedback in https://cl.tvl.fyi/c/depot/+/7492, all
uses of `NixAttrs::from_map` have been removed. Only `from_iter` and
`from_kv` remain.

Change-Id: I52e25f73018c2aa1843197427516b7a852503e2c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7500
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: IslandUsurper <lyle@menteeth.us>
2022-12-03 13:26:51 +00:00
Lyle Mantooth
39dba6aa16 feat(tvix/eval): impl FromIterator for NixAttrs
Allows for the removal of some BTreeMap usage when constructing NixAttrs
by allowing any iterator over 2-tuples to build a NixAttrs. Some
instances of BTreeMap didn't have anything to do with making NixAttrs,
and some were just the best tool for the job, so they are left using the
old `from_map` interface.

Change-Id: I668ea600b0d93eae700a6b1861ac84502c968d78
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7492
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-12-02 14:46:47 +00:00
sterni
90fe9a51d7 test(tvix/eval): check inner forcing despite declaring pointer
Maybe counter-intuitively the inner elements of a list or the
attribute values of an attribute set will be forced despite
pointer equality (but only one layer deep).

Change-Id: I485d96452fb56f5fb342d39039c9137725b33d3f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7371
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-12-02 14:41:50 +00:00
Vincent Ambo
5ab86ab8dc test(tvix/eval): add a test for repeated keys in listToAttrs
This came up in the Nix Language channel today and I thought it
warranted a test case.

We did actually implement this correctly.

Change-Id: I4b37c92d06eb6e3a7f59ea3d10af38f2b0a93d53
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7493
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-02 14:39:34 +00:00
sterni
1ad777e3c7 test(tvix/eval): verify pointer equality checks
Change-Id: I9baf2810fbd5b6ee8bfe10fce5b64801a35c1d67
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7369
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-12-02 14:06:35 +00:00
sterni
7bab0c26ee test(tvix/eval): verify pointer equality in list comparisons
Change-Id: I617d402c8ecc7aaf607c4bdcd58a06ebddb71fac
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7370
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-12-02 14:06:22 +00:00
Adam Joseph
3b92ff454f feat(tvix/eval): inline(always) tail_call_value
Rust doesn't do tail-call elimination (still!) so the best we can
hope for here is to inline non-recursive invocations.

Change-Id: I78949967e48b006fcbf31786d8f6281cd122f36f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7360
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: Adam Joseph <adam@westernsemico.com>
2022-12-02 13:36:12 +00:00
Adam Joseph
8eb32fb2d7 feat(tvix/eval): crude caching builtins.import
Before this, tvix was spending most of its time furiously re-parsing
and re-compiling nixpkgs, each time hoping to get a different result...

Change-Id: I1c0cfbf9af622c276275b1f2fb8d4e976f1b5533
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7361
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-02 13:32:11 +00:00
Adam Joseph
a87abd5eed feat(tvix/eval): placeholder for builtins.placeholder
Change-Id: I8d11f2db4489a7d82910256069d10f8bed3bdf9a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7451
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-12-01 10:30:43 +00:00
Adam Joseph
f32abc57cf feat(tvix/eval): impl Default for AttrsRep
Change-Id: I3a55413e5004777b90c06cd8655f26abb2faf39b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7448
Autosubmit: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-01 10:25:41 +00:00
Adam Joseph
dfdebece14 feat(tvix/eval): From<Rc<Vec<Value>>> for NixList
Change-Id: I2ab53453ed7370b520bb929ef7285e4f23eec65b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7453
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: Adam Joseph <adam@westernsemico.com>
2022-11-30 10:44:19 +00:00
Adam Joseph
580616a812 feat(tvix/eval): implement equality on derivations
Change-Id: I344b66c39cbc4b426accc482aa8f6f2eb18db68a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7417
Autosubmit: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-28 20:05:34 +00:00
Adam Joseph
7606e62a2f feat(tvix/eval): add CoercionKind::ThunksOnly
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I92acb7e6099a4796d953b2d4d02cca4076ed0fb1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7426
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-28 20:05:33 +00:00
Adam Joseph
22c2c5ba46 fix(tvix/eval): implement function/thunk ptr-equality for list ord
With this change, the test introduced by cl/7370 passes.

Change-Id: Ie7d2f02a59d61151f14ebd328e6cfa5892cacfb0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7375
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: Adam Joseph <adam@westernsemico.com>
2022-11-27 19:16:57 +00:00
Adam Joseph
dad8a7cbff feat(tvix/eval): non-recursive implementation of nix_eq()
This passes all the function/thunk-pointer-equality tests in
cl/7369.

Change-Id: Ib47535ba2fc77a4f1c2cc2fd23d3a879e21d8b4c
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7358
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-27 19:10:34 +00:00
Adam Joseph
b5a1b965a6 feat(tvix/eval): add --raw flag to eval, like cppnix
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: If07250a45fdf65a3f22ed8c37d7f37b45edccde9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7416
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-26 21:20:02 +00:00
Adam Joseph
56c00df710 feat(tvix/eval): use backtrace-on-stack-overflow crate
The backtrace-on-stack-overflow create provides best-effort stack
traces when a stack overflow happens.  Since it's running on the
(usually tiny) signal alternate stack this isn't easy.

This is guarded by a new `backtrace_overflow` feature flag and never
enabled (even if that feature is selected) for release builds.  This
is strictly for debugging; there's crazy unsafe voodoo in there.

   https://lib.rs/crates/backtrace-on-stack-overflow

Example output:

```
Stack Overflow:
   0: backtrace_on_stack_overflow::handle_sigsegv
             at /home/amjoseph/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-on-stack-overflow-0.2.0/src/lib.rs:93:40
   1: <unknown>
   2: __rust_probestack
   3: tvix_eval::vm::VM::run_op
             at src/vm.rs:399
   4: tvix_eval::vm::VM::run
             at src/vm.rs:388:23
   5: tvix_eval::vm::VM::enter_frame
             at src/vm.rs:360:22
   6: tvix_eval::value::thunk::Thunk::force
             at src/value/thunk.rs:116:25
   7: tvix_eval::vm::VM::run_op
             at src/vm.rs:801:37
   8: tvix_eval::vm::VM::run
             at src/vm.rs:388:23
   9: tvix_eval::vm::VM::enter_frame
             at src/vm.rs:360:22
  10: tvix_eval::value::thunk::Thunk::force
             at src/value/thunk.rs:116:25
...
```

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I1d8a2017f836be7bf91a2223e7adacb86fa1dbb2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7354
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-26 19:41:43 +00:00
Adam Joseph
4b09f01571 fix(tvix/eval): OpAdd must weakly stringify if either arg is string
Tests included.

Change-Id: I7a4905d6103813373e383e2e8629c5fd243d6bca
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7377
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: Adam Joseph <adam@westernsemico.com>
2022-11-26 19:37:42 +00:00
Adam Joseph
5f52c97a3a feat(tvix/eval): mock builtins.unsafeGetAttrPos
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I9d986dd8c0aad4e67df01bda13cee443e0fc0d20
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7415
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-26 11:57:15 +00:00
Adam Joseph
b79822a105 feat(tvix/eval): declare function-pointer-equality dealt with
Change-Id: If81ff414dba10a0448b905eec373730a68795376
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7376
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: Adam Joseph <adam@westernsemico.com>
2022-11-26 11:48:12 +00:00
Adam Joseph
6b986de92b feat(tvix/eval): add Closure::ptr_eq()
See cl/7368

Change-Id: I97630994c3d65f4d16414a0da236ce000a5b6d33
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7374
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-26 11:44:10 +00:00
Adam Joseph
0616976f7c feat(tvix/eval): wrap Closure::upvalues in Rc
See cl/7372; Nix equality semantics require the ability to track
pointer equality of upvalue-sets.

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I82ba517499cf370189a80355e4e46a5caaab7153
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7373
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-26 11:44:10 +00:00
sterni
094f07ad9a docs(tvix): document pointer equality in (C++) Nix
semi-obscure = #nix-lang on freenode

Change-Id: Id235f7019bbee137bbde57a552c755261e23b58f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7368
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-11-25 10:27:08 +00:00
Adam Joseph
325a7d6fa9 test(tvix/eval): add eval-okay-closure-pointer-compare
This test case checks two things:

* A sanity check that "pointer equality for functions" means not
  just the lambda, but also the upvalues.

* To be pointer-equal, it is not enough for the upvalues to be
  normal-form equal (i.e. `nix_eq()`-equal); the upvalues must be
  *pointer*-equal.  The second part of the test case checks for
  this.

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I4e59327a6f199b8212e97197b212e3c3934bb3f0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7372
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-11-25 00:48:31 +00:00
Adam Joseph
11874d3a71 chore(tvix/eval): postpone use of "dep:" for a bit
The "dep:" syntax in Cargo.toml is very new; crate2nix master has
support for it, but they have not yet made a release with this
update, and therefore the crate2nix in nixpkgs does not yet support
it.

Could we avoid using "dep:" for a few weeks to give crate2nix a
chance to release so I can bump the version in nixpkgs?  I've opened
an issue asking crate2nix to make a release:

  https://github.com/kolloch/crate2nix/issues/264

I propose that if they haven't acted within a month we stop waiting
and revert this at that time.

Change-Id: I999a72429db667bedf4b2cdba27cb63b3f3d9657
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7350
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-24 20:11:46 +00:00
sterni
bc537d2c0d test(tvix/eval): test limits of builtins.seq's forcing
Change-Id: I6dfc9108220762ef3372cd2739e91d79c01a55e1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7366
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-24 13:25:28 +00:00
Adam Joseph
ff658006f0 feat(tvix/eval): ExactSizeIterator for Iter<KeyValue<'a>> and Keys
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: Ia373eb30d8516a056f1349f9011dee9816593d6f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7357
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-23 20:33:32 +00:00
Adam Joseph
4e33bc2390 feat(tvix/eval): improve panic!() messages in Thunk::value()
Change-Id: I3b1284e28c350bfed84d643ae7f922f3487e1f2a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7355
Autosubmit: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-23 13:20:24 +00:00
Adam Joseph
de89dc9cfc feat(tvix/eval): add NixAttrs::into_iter()
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: Ib813d794177c623bf2f12fc2e6a6f304089607d1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7356
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-23 13:02:19 +00:00
Adam Joseph
a740653c83 feat(tvix/eval): make NixList::clone() cheap
When we start unrecursivifying (sp?) things, Rust's borrow checker
is going to be a headache; its magic only works when you use the CPU
stack as your call stack.

Fixing the borrow checker issues usually involves adding lots of
`clone()`s.  Right now `NixList` is the only variant of `Value` that
isn't cheap to clone() -- all the others are either a wrapper around
Rc or else are of bounded size.

Note that this requires dropping the `DerefMut for NixList` instance
and using `Vec<Value>` instead in those situations.

Change-Id: I5a47df66855342aa2064f8f3cb7934ff422d26bd
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7359
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-23 13:02:19 +00:00
Vincent Ambo
878dc6c227 fix(tvix/eval): aggressively fix a borrow error in nix_eq
When comparing Nix values for equality, an issue can occur where
recursive values contain thunks to themselves which causes borrow
errors when forcing them for comparison later down the line.

To work around this we clone the values for now. There might be some
optimisations possible like checking for thunk equality directly and
short-circuiting on that (we have to check what Nix does).

Change-Id: I7e75c992ea68f100058f52b4b46168da7d671994
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7314
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-11-21 15:26:56 +00:00
Vincent Ambo
f7907db69d fix(tvix/eval): builtins.listToAttrs must force keys
Change-Id: Ief9ebc2285a0c50654c2edd3351432dc1588f9fc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7313
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-11-21 14:14:49 +00:00
Vincent Ambo
994bf03b74 fix(tvix/eval): ensure callable is forced when using call_with
When passing multiple arguments, every intermediate callable needs to
be forced as this is expected by the VM's call_value function.

Also adds a debug assertion for this which makes it easier to spot
exactly what went wrong.

Change-Id: I3aa519cb6cdaab713bd18282bef901c4cd77c535
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7312
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-11-21 14:14:49 +00:00
Vincent Ambo
e1e8285ecf test(tvix/eval): enable eval-okay-closure test from nix_tests
This function covers builtins.genericClosure, seemingly including
weird behaviour around the order in which the work set is processed.

For some reason, in C++ Nix the test expectation is written in XML
which we do not yet support, so I have created a new expectation file
using `nix-instantiate --eval --strict` on the file (yes, using C++
Nix).

Change-Id: Id90e7117d120dc66d963a51083c4d8e8f2d9f181
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7311
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-11-21 14:14:49 +00:00
Vincent Ambo
ae30def055 feat(tvix/eval): Implement builtins.genericClosure
This implementation closely follows the original implementation in
Nix, including the use of an equality-based "set" structure to track
keys that have already been processed.

Note that this test does not yet enable the `notyetpassing` test for
builtins.genericClosure because (for as of yet unknown reasons) this
test compares against XML output (however, evaluating the test case
actually does work).

This takes us one step closer to nixpkgs eval.

This commit was written somewhere in the North Sea.

Co-Authored-By: Griffin Smith <root@gws.fyi>
Change-Id: I450a866e6f2888b27c2fe7c7f77ce0f79bfe3e6c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7310
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-11-21 14:14:49 +00:00
Florian Klink
dde62055fe feat(tvix/): .gitignore target folders
Change-Id: Ic52159141b2346dd580215566056aca7110f0a10
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7253
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-11-11 19:55:12 +00:00
Florian Klink
7eb7014821 feat(tvix/eval): move shell.nix and .envrc to //tvix
Both //tvix/eval and //tvix/nix_cli have need to for rust tooling available
in $PATH.

Move this one level up, so it's accessible in all subdirectories.

Change-Id: I0763bbe9cefdc962f3a8f86c51e8f67cde8b4b04
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7248
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-11-11 19:55:12 +00:00
jhahn
d00030128e feat(tvix/eval): detect division by zero
This detects if the second argument of a division is a zero (either as integer
or as float). If so, an error message is displayed.

This fixes b/219.

Change-Id: I50203d14a71482bc757832a2c8dee08eb7d35c49
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7258
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
2022-11-10 13:12:05 +00:00
Florian Klink
41883b6c08 chore(tvix/proto/castore.proto) rename *Node.{ref->digest}
As per the discussion in
https://cl.tvl.fyi/c/depot/+/7128/2..5/tvix/proto/castore.proto#b39, ref
sounds more like an external, stateful ID. Call this `digest`, to make
clear it's precisely this.

Change-Id: I81dd3769e2ce017de470ae92f72a38fb72015f10
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7134
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-11-08 17:57:53 +00:00
Florian Klink
5731fbbee3 chore(tvix/proto): change package name to tvix.proto.v1
`buf` doesn't like protos with different package names in the same
directory.

Change-Id: I30806b46b88f103779faa40466461091a4a01e06
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7130
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-11-08 17:57:53 +00:00
Florian Klink
7ac36fd8db chore(tvix/proto/castore.proto): rename link to symlinks
Make it clear these are symlinks, not hardlinks.

The term "link" is too heavily correlated to other meanings in IPFS/IPLD
world, and calling this symlink removes this confusion.

Change-Id: Id3f1eaa32098510b05f3e1a1348344503bcb4d5a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7129
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
2022-11-08 17:57:53 +00:00
Florian Klink
442384f6e5 docs(tvix/proto/castore.proto): add comments
Change-Id: Ie5438cc6b6d4c63fc05236a2f0f900c92b5a4a7d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7128
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-08 17:57:53 +00:00
Griffin Smith
76d7671c8a feat(tvix/eval): Add docstrings as documentation for builtins
Add a new `documentation: Option<&'static str>` field to Builtin, and
populate it in the `#[builtins]` macro with the docstring of the builtin
function, if any.

Change-Id: Ic68fdf9b314d15a780731974234e2ae43f6a44b0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7205
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-08 13:42:37 +00:00
Griffin Smith
a1015ba1d7 feat(tvix/eval): Give names to builtin arguments
Refactor the arguments of a Builtin to be a vec of a new BuiltinArgument
struct, which contains the old strictness boolean and also a static
`name` str - this is automatically determined via the ident for the
corresponding function argument in the proc-macro case, and passed in in
the cases where we're still manually calling Builtin::new.

Currently this name is unused, but in the future this can be used as
part of a documentation system for builtins.

Change-Id: Ib9dadb15b69bf8c9ea1983a4f4f197294a2394a6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7204
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-08 13:42:37 +00:00
Griffin Smith
dad07a8bc0 refactor(tvix/eval): Be clearer about public interface
Some new top-level re-exports (specifically VM, Builtin, and ErrorKind)
were added to lib.rs in tvix/eval to allow the builtin-macros tests to
work - we should be clear which of these are part of the public
interface (I think it's reasonable for ErrorKind to be) and which
aren't (specifically I'm not sure VM and Builtin necessarily should be,
at least yet).

Change-Id: I3bbeaa63cdda9227224cd3bc298a9bb8da4deb7c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7203
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-08 13:42:37 +00:00
Griffin Smith
a4c9cc8d5e refactor(tvix/eval): Define impure builtins using the macro
Similar to what we did with pure builtins, define the impure builtins
within a module at the top-level using the new #[builtins] attribute
macro

Change-Id: Ie5d5135d00bb65e651531df6eadba642cd4eb08e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7202
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-11-08 13:42:37 +00:00
Griffin Smith
2d26925dd9 refactor(tvix/eval): Define *all* pure builtins at the top-level
Break out all pure builtin functions to top-level functions defined
within the `pure_builtins` module in `builtins/mod.rs`.

Change-Id: I9a10660446d557b1a86da4c45a463e9a1a9b4f2d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7201
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-11-08 13:42:37 +00:00
Griffin Smith
43eb4900e0 refactor(tvix/eval): Define a single builtin at the top level
Mostly as a proof-of-concept of the new proc-macros for defining
builtins, define a single builtin (the first in the list, `abort`) at
the top-level of a child module within builtins/mod.rs, and add it to
the list of builtins returned from `pure_builtins`.

If this works nicely, we can start breaking out the rest of the builtins
into the top-level too, in addition to introducing additional sets of
builtins (to differentiate between pure and impure builtins).

Change-Id: I5bdd57c57fecf8d63c9fed4fc6b1460f533b20f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7199
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-11-08 13:42:37 +00:00
Griffin Smith
645d0c06e5 feat(tvix/eval): Add a proc-macro for defining builtins
Add a single new proc macro to a new proc-macro crate,
`tvix-eval-proc-macros` for defining an inline module containing nix
builtins, and automatically generating a function within that module
which returns a list of those builtins as `tvix_eval::value::Builtin`.

Change-Id: Ie4afae438914d2af93d15637151a49b4c68aa352
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7198
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
2022-11-08 13:42:37 +00:00
Vincent Ambo
cf82a545eb feat(tvix/eval): add helper for selecting required attributes
Change-Id: Idd4ae78ef55891d89b72b5c2f3afc8b697b4b26e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7189
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
2022-11-08 12:33:36 +00:00