From 6d53fb6c522ae21a5b930920b72a66f551f82c65 Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 12 Sep 2022 18:27:00 +0200 Subject: fix(tvix/eval): force exprs inside string interpolation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The expression inside ${…} may return arbitrary values, including thunks, so we need to make sure to force them just in case. Change-Id: Ic11ba00c4c92a10a83becd91233db5f57f6e59c8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6541 Autosubmit: sterni Reviewed-by: grfn Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/compiler/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/compiler') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 07086c72fc29..3830c01712f2 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -258,6 +258,7 @@ impl Compiler<'_, '_> { } fn compile_str(&mut self, slot: LocalIdx, node: ast::Str) { + // TODO: thunk string construction if it is not a literal let mut count = 0; // The string parts are produced in literal order, however @@ -271,7 +272,10 @@ impl Compiler<'_, '_> { // Interpolated expressions are compiled as normal and // dealt with by the VM before being assembled into // the final string. - ast::InterpolPart::Interpolation(node) => self.compile(slot, node.expr().unwrap()), + ast::InterpolPart::Interpolation(node) => { + self.compile(slot, node.expr().unwrap()); + self.emit_force(&node); + } ast::InterpolPart::Literal(lit) => { self.emit_constant(Value::String(lit.into()), &node); -- cgit 1.4.1