refactor(tvix/eval): encapsulate list construction in value::list

Ensuring that the implementation is not leaking out of the module lets
us keep things open for optimisations (e.g. empty list or pairs
through tuples).

Change-Id: I18fd9b7740f28c55736471e16c6b4095a05dd6d0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6145
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-11 11:55:59 +03:00 committed by tazjin
parent 75a22321ce
commit 9407af5684
2 changed files with 17 additions and 17 deletions

View file

@ -4,7 +4,7 @@ use std::fmt::Display;
use super::Value;
#[derive(Clone, Debug, PartialEq)]
pub struct NixList(pub Vec<Value>);
pub struct NixList(Vec<Value>);
impl Display for NixList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -26,4 +26,15 @@ impl NixList {
lhs.0.append(&mut rhs.0);
lhs
}
pub fn construct(count: usize, stack_slice: Vec<Value>) -> Self {
debug_assert!(
count == stack_slice.len(),
"NixList::construct called with count == {}, but slice.len() == {}",
count,
stack_slice.len(),
);
NixList(stack_slice)
}
}