From 3f34af205f36f0a18c37befb7d20872f4ae8f418 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 28 Sep 2022 14:57:53 +0300 Subject: feat(tvix/eval): add scaffolding for merging nested attribute sets This sets up the required logic for finding and merging attribute sets into nested bindings if they exist. This is absolutely not complete yet and can, at this commit, probably cause undefined runtime behaviour if nested attributes are specified. The basic idea is that a new helper function on the `TrackedBindings` struct is called with each encountered attribute and determines whether the new entry can be merged into an existing attribute or not. Right now the only effect this has in practice is that a new error becomes available if somebody attempts to cause a merge into an inherited key. Change-Id: Id010df3605055eb1ad7fa65241055889dd21bab0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6798 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/errors.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tvix/eval/src/errors.rs') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 822ebdbc8cb4..92ca59f105a4 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -4,6 +4,7 @@ use std::{fmt::Display, num::ParseIntError}; use codemap::{CodeMap, Span}; use codemap_diagnostic::{Diagnostic, Emitter, Level, SpanLabel, SpanStyle}; +use smol_str::SmolStr; use crate::Value; @@ -88,6 +89,12 @@ pub enum ErrorKind { length: i64, }, + // Errors specific to nested attribute sets and merges thereof. + /// Nested attributes can not be merged with an inherited value. + UnmergeableInherit { + name: SmolStr, + }, + /// Tvix internal warning for features triggered by users that are /// not actually implemented yet, and without which eval can not /// proceed. @@ -242,6 +249,13 @@ to a missing value in the attribute set(s) included via `with`."#, ) } + ErrorKind::UnmergeableInherit { name } => { + format!( + "cannot merge a nested attribute set into the inherited entry '{}'", + name + ) + } + ErrorKind::NotImplemented(feature) => { format!("feature not yet implemented in Tvix: {}", feature) } @@ -275,6 +289,7 @@ to a missing value in the attribute set(s) included via `with`."#, ErrorKind::ParseIntError(_) => "E021", ErrorKind::NegativeLength { .. } => "E022", ErrorKind::TailEmptyList { .. } => "E023", + ErrorKind::UnmergeableInherit { .. } => "E024", ErrorKind::NotImplemented(_) => "E999", } } -- cgit 1.4.1