From 290a8190189891fc46d7a0b48ed6a2d28b9a4878 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 5 Nov 2022 15:07:02 +0300 Subject: feat(tvix/eval): placeholder builtin implementations Adds initial placeholders for builtins.{derivation, unsafeDiscardStringContext}. Change-Id: I67a126c9b9f9f4f11e2256e69b9a32ebd9eb1b0e Reviewed-on: https://cl.tvl.fyi/c/depot/+/7187 Autosubmit: tazjin Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/builtins/mod.rs | 52 ++++++++++++++++++---- .../nix_tests/eval-okay-delayed-with-inherit.exp | 1 + .../nix_tests/eval-okay-delayed-with-inherit.nix | 24 ++++++++++ .../eval-okay-delayed-with-inherit.exp | 1 - .../eval-okay-delayed-with-inherit.nix | 24 ---------- 5 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.exp create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.nix delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.exp delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.nix diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index a6fcb8742c56..045487cbf676 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -19,7 +19,7 @@ use crate::{ vm::VM, }; -use crate::arithmetic_op; +use crate::{arithmetic_op, unwrap_or_clone_rc}; use self::versions::{VersionPart, VersionPartsIter}; @@ -829,14 +829,48 @@ fn pure_builtins() -> Vec { /// /// These are used as a crutch to make progress on nixpkgs evaluation. fn placeholders() -> Vec { - vec![Builtin::new( - "addErrorContext", - &[false, false], - |mut args: Vec, vm: &mut VM| { - vm.emit_warning(WarningKind::NotImplemented("builtins.addErrorContext")); - Ok(args.pop().unwrap()) - }, - )] + vec![ + Builtin::new( + "addErrorContext", + &[false, false], + |mut args: Vec, vm: &mut VM| { + vm.emit_warning(WarningKind::NotImplemented("builtins.addErrorContext")); + Ok(args.pop().unwrap()) + }, + ), + Builtin::new( + "unsafeDiscardStringContext", + &[true], + |mut args: Vec, vm: &mut VM| { + vm.emit_warning(WarningKind::NotImplemented( + "builtins.unsafeDiscardStringContext", + )); + Ok(args.pop().unwrap()) + }, + ), + Builtin::new("derivation", &[true], |args: Vec, vm: &mut VM| { + vm.emit_warning(WarningKind::NotImplemented("builtins.derivation")); + + // We do not implement derivations yet, so this function sets mock + // values on the fields that a real derivation would contain. + // + // Crucially this means we do not yet *validate* the values either. + let attrs = unwrap_or_clone_rc(args[0].to_attrs()?); + let attrs = attrs.update(NixAttrs::from_map(BTreeMap::from([ + ( + "outPath".into(), + "/nix/store/00000000000000000000000000000000-mock".into(), + ), + ( + "drvPath".into(), + "/nix/store/00000000000000000000000000000000-mock.drv".into(), + ), + ("type".into(), "derivation".into()), + ]))); + + Ok(Value::Attrs(Rc::new(attrs))) + }), + ] } // we set TVIX_CURRENT_SYSTEM in build.rs pub const CURRENT_PLATFORM: &str = env!("TVIX_CURRENT_SYSTEM"); diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.exp b/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.exp new file mode 100644 index 000000000000..eaacb55c1aff --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.exp @@ -0,0 +1 @@ +"b-overridden" diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.nix b/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.nix new file mode 100644 index 000000000000..84b388c27130 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with-inherit.nix @@ -0,0 +1,24 @@ +let + pkgs_ = with pkgs; { + a = derivation { + name = "a"; + system = builtins.currentSystem; + builder = "/bin/sh"; + args = [ "-c" "touch $out" ]; + inherit b; + }; + + inherit b; + }; + + packageOverrides = p: { + b = derivation { + name = "b-overridden"; + system = builtins.currentSystem; + builder = "/bin/sh"; + args = [ "-c" "touch $out" ]; + }; + }; + + pkgs = pkgs_ // (packageOverrides pkgs_); +in pkgs.a.b.name diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.exp deleted file mode 100644 index eaacb55c1aff..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.exp +++ /dev/null @@ -1 +0,0 @@ -"b-overridden" diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.nix deleted file mode 100644 index 84b388c27130..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with-inherit.nix +++ /dev/null @@ -1,24 +0,0 @@ -let - pkgs_ = with pkgs; { - a = derivation { - name = "a"; - system = builtins.currentSystem; - builder = "/bin/sh"; - args = [ "-c" "touch $out" ]; - inherit b; - }; - - inherit b; - }; - - packageOverrides = p: { - b = derivation { - name = "b-overridden"; - system = builtins.currentSystem; - builder = "/bin/sh"; - args = [ "-c" "touch $out" ]; - }; - }; - - pkgs = pkgs_ // (packageOverrides pkgs_); -in pkgs.a.b.name -- cgit 1.4.1