fix(tvix/eval): force value in builtins.typeOf

This prevents Nix programs to observe the "internal" type of thunks.
Possibly .type_of() is also an area of the runtime where we should panic
if "internal" would ever be returned.

Change-Id: I9f358044c48ad64896fb6a1b1a42f00a29efac00
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6539
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
sterni 2022-09-12 17:39:50 +02:00 committed by clbot
parent 6d53fb6c52
commit 7e625afc59
3 changed files with 27 additions and 2 deletions

View file

@ -125,8 +125,10 @@ fn pure_builtins() -> Vec<Builtin> {
Ok(Value::String(format!("{}", value).into()))
})
}),
Builtin::new("typeOf", 1, |args, _| {
Ok(Value::String(args[0].type_of().into()))
Builtin::new("typeOf", 1, |args, vm| {
force!(vm, &args[0], value, {
Ok(Value::String(value.type_of().into()))
})
}),
]
}

View file

@ -0,0 +1 @@
[ "null" "bool" "bool" "int" "int" "float" "string" "string" "set" "set" "set" "list" "lambda" "path" ]

View file

@ -0,0 +1,22 @@
let
fix = f: let x = f x; in x;
in
fix (self:
[
(builtins.typeOf null)
(builtins.typeOf true)
(builtins.typeOf (true && false))
(builtins.typeOf 12)
(builtins.typeOf (builtins.add 21 21))
(builtins.typeOf 1.2)
(builtins.typeOf "foo")
(builtins.typeOf "${"foo" + "bar"}baz")
(builtins.typeOf {})
(builtins.typeOf { foo.bar = 32; }.foo)
(builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; }))
(builtins.typeOf self)
(builtins.typeOf fix)
(builtins.typeOf /nix/store)
]
)