From 0624d78af0839cd8b290eb9cb6e5737f01162b96 Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 15 Oct 2022 16:21:14 +0200 Subject: refactor(tvix/eval): make OpFindFile use internal UnresolvedPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To assert that OpFindFile is only emitted for specially compiled SPATH expressions, as well as make sure it doesn't accidentally operate on “ordinary values”, introduce an UnresolvedPath internal value. If OpFindFile sees a non-UnresolvedPath value, it'll crash. Note that this change is not done purely for OpFindFile: We may want to compile SPATH expressions as function calls to __findFile (like C++ Nix does) in the future, so the UnresolvedPath value would definitely need to be an ordinary string again then. Rather, this change is done in preparation for resolving home dir relative paths at runtime (since they depend on the environment) for which we'll need a similar mechanism to OpFindFile. Change-Id: I6acf287f35197cd9e13377079f972b9d36e5b22e Reviewed-on: https://cl.tvl.fyi/c/depot/+/7023 Autosubmit: sterni Reviewed-by: Adam Joseph Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/vm.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'tvix/eval/src/vm.rs') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 252635de56..05adec5f6e 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -524,14 +524,17 @@ impl<'o> VM<'o> { self.push(Value::String(string)); } - OpCode::OpFindFile => { - let path = self.pop().to_str().map_err(|e| self.error(e))?; - let resolved = self - .nix_search_path - .resolve(path) - .map_err(|e| self.error(e))?; - self.push(resolved.into()); - } + OpCode::OpFindFile => match self.pop() { + Value::UnresolvedPath(path) => { + let resolved = self + .nix_search_path + .resolve(path) + .map_err(|e| self.error(e))?; + self.push(resolved.into()); + } + + _ => panic!("tvix compiler bug: OpFindFile called on non-UnresolvedPath"), + }, OpCode::OpJump(JumpOffset(offset)) => { debug_assert!(offset != 0); @@ -836,7 +839,10 @@ impl<'o> VM<'o> { // If any of these internal values are encountered here a // critical error has happened (likely a compiler bug). - Value::AttrNotFound | Value::Blueprint(_) | Value::DeferredUpvalue(_) => { + Value::AttrNotFound + | Value::Blueprint(_) + | Value::DeferredUpvalue(_) + | Value::UnresolvedPath(_) => { panic!("tvix bug: internal value left on stack: {:?}", value) } -- cgit 1.4.1