feat(tvix/eval): support builtins implemented in Nix itself

This makes it possible to inject builtins into the builtin set that
are written in Nix code, and which at runtime are represented by a
thunk that will compile them the first time they are used.

Change-Id: Ia632367328f66fb2f26cb64ae464f8f3dc9c6d30
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7891
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2023-01-21 15:18:45 +03:00 committed by tazjin
parent 8513a58b37
commit 5719763fd3
4 changed files with 109 additions and 18 deletions

View file

@ -2,6 +2,10 @@ use builtin_macros::builtins;
use pretty_assertions::assert_eq;
use test_generator::test_resources;
/// Module for one-off tests which do not follow the rest of the
/// test layout.
mod one_offs;
#[builtins]
mod mock_builtins {
//! Builtins which are required by language tests, but should not

View file

@ -0,0 +1,19 @@
use crate::*;
#[test]
fn test_source_builtin() {
// Test an evaluation with a source-only builtin. The test ensures
// that the artificially constructed thunking is correct.
let mut eval = Evaluation::new_impure("builtins.testSourceBuiltin", None);
eval.src_builtins.push(("testSourceBuiltin", "42"));
let result = eval.evaluate();
assert!(
result.errors.is_empty(),
"evaluation failed: {:?}",
result.errors
);
assert!(matches!(result.value.unwrap(), Value::Integer(42)));
}