diff options
author | sterni <sternenseemann@systemli.org> | 2023-06-13T20·26+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2023-06-14T10·57+0000 |
commit | 8e5551329a4b13e516259126559d7d52ac998a5a (patch) | |
tree | 40c3956c566afc1dff0d5478560c04b2963840e5 | |
parent | 0128323c555b6209315f30a723af3a62f63d446e (diff) |
fix(tvix/eval): don't thunk home relative paths r/6297
C++ Nix resolves home relative paths at [parse] time. This is not an option for us, since it prevents being able to separate the compilation and execution phase later (e.g. precompiled nix expressions). However, a practical consequence of this is that paths expressions are always literals (strict) and never thunks. [parse]: https://github.com/NixOS/nix/blob/7066d21a0ddb421967980094222c4bc1f5a0f45a/src/libexpr/parser.y#L518-L527 Change-Id: Ie4b9dc68f62c86d6c7fd5f1c9460c850d97ed1ca Reviewed-on: https://cl.tvl.fyi/c/depot/+/7041 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 21 | ||||
-rw-r--r-- | tvix/eval/tests/nix_oracle.rs | 3 |
2 files changed, 13 insertions, 11 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 43dab506c5ed..436e504af2a6 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -341,18 +341,17 @@ impl Compiler<'_> { let path = if raw_path.starts_with('/') { Path::new(&raw_path).to_owned() } else if raw_path.starts_with('~') { - return self.thunk(slot, node, move |c, _| { - // We assume that home paths start with ~/ or fail to parse - // TODO: this should be checked using a parse-fail test. - debug_assert!(raw_path.len() > 2 && raw_path.starts_with("~/")); + // We assume that home paths start with ~/ or fail to parse + // TODO: this should be checked using a parse-fail test. + debug_assert!(raw_path.len() > 2 && raw_path.starts_with("~/")); - let home_relative_path = &raw_path[2..(raw_path.len())]; - c.emit_constant( - Value::UnresolvedPath(Box::new(home_relative_path.into())), - node, - ); - c.push_op(OpCode::OpResolveHomePath, node); - }); + let home_relative_path = &raw_path[2..(raw_path.len())]; + self.emit_constant( + Value::UnresolvedPath(Box::new(home_relative_path.into())), + node, + ); + self.push_op(OpCode::OpResolveHomePath, node); + return; } else if raw_path.starts_with('<') { // TODO: decide what to do with findFile if raw_path.len() == 2 { diff --git a/tvix/eval/tests/nix_oracle.rs b/tvix/eval/tests/nix_oracle.rs index 386d49c51ccd..b9531c81ddc0 100644 --- a/tvix/eval/tests/nix_oracle.rs +++ b/tvix/eval/tests/nix_oracle.rs @@ -154,6 +154,9 @@ compare_lazy_eval_tests! { thunked_lambda_in_list("[ (x: x) ]"); thunked_function_application_in_list("[ (builtins.add 1 2) ]"); thunked_legacy_let_in_list("[ (let { foo = 12; body = foo; }) ]"); + unthunked_relative_path("[ ./foo ]"); + unthunked_home_relative_path("[ ~/foo ]"); + unthunked_absolute_path("[ /foo ]"); unthunked_formals_fallback_literal("({ foo ? 12 }: [ foo ]) { }"); unthunked_formals_fallback_string_literal("({ foo ? \"wiggly\" }: [ foo ]) { }"); |