diff options
author | Vincent Ambo <mail@tazj.in> | 2023-01-05T12·57+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-01-06T12·23+0000 |
commit | 61b8a9b2ba278f697735a2c3ff77fff091c8f464 (patch) | |
tree | f13c708a9a5b386899e8db35364b3c6dae5f17f1 /tvix/eval/src | |
parent | 4e98730f3809e92bc527dac7c7b7928cf311b0ca (diff) |
refactor(tvix/eval): short-circuit on empty attrs in compiler r/5605
This is marginally more efficient and has simpler bytecode. Change-Id: Iad37c9aeef24583e8f696911bcd83d43639f2e36 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7769 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/compiler/bindings.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler/bindings.rs b/tvix/eval/src/compiler/bindings.rs index 93b3dc3cc666..83667c129be0 100644 --- a/tvix/eval/src/compiler/bindings.rs +++ b/tvix/eval/src/compiler/bindings.rs @@ -640,6 +640,15 @@ impl Compiler<'_> { self.declare_namespaced_inherits(kind, inherit_froms, &mut bindings); self.declare_bindings(kind, &mut count, &mut bindings, node); + // Check if we can bail out on empty bindings + if count == 0 { + // still need an attrset to exist, but it is empty. + if kind.is_attrs() { + self.emit_constant(Value::Attrs(Box::new(NixAttrs::empty())), node); + return; + } + } + // Actually bind values and ensure they are on the stack. self.bind_values(bindings); |