feat(tvix/eval): implement recursive attribute sets

Yep.

This is kind of ugly right now. The idea is that the recursive_scope
compilation function is used for recursive sets as well by emitting
the keys. The rest of the logic is pretty much identical.

There is quite a lot of code here that can be cleaned up (duplication
between attrs and let, duplication inside of the recursive scope
compilation function etc.), but I'd like to get it working first and
then make it nice.

Note that nested keys are *not* supported yet.

Change-Id: I45c7cdd5f0e1d35fd94797093904740af3a97134
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6610
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-09-16 19:35:39 +03:00 committed by tazjin
parent a7e280ec00
commit 20230e1e2d
2 changed files with 77 additions and 34 deletions

View file

@ -215,25 +215,23 @@ impl Compiler<'_, '_> {
/// 2. Keys can refer to nested attribute sets.
/// 3. Attribute sets can (optionally) be recursive.
pub(super) fn compile_attr_set(&mut self, slot: LocalIdx, node: ast::AttrSet) {
if node.rec_token().is_some() {
let span = self.span_for(&node);
self.emit_warning(
span,
WarningKind::NotImplemented("recursive attribute sets"),
);
}
// Open a scope to track the positions of the temporaries used
// by the `OpAttrs` instruction.
self.scope_mut().begin_scope();
let mut count = self.compile_inherit_attrs(slot, node.inherits());
if node.rec_token().is_some() {
self.compile_recursive_scope(slot, true, &node);
self.push_op(OpCode::OpAttrs(Count(node.entries().count())), &node);
} else {
let mut count = self.compile_inherit_attrs(slot, node.inherits());
let dynamic_entries = self.compile_static_attr_entries(&mut count, node.attrpath_values());
let dynamic_entries =
self.compile_static_attr_entries(&mut count, node.attrpath_values());
self.compile_dynamic_attr_entries(&mut count, dynamic_entries);
self.compile_dynamic_attr_entries(&mut count, dynamic_entries);
self.push_op(OpCode::OpAttrs(Count(count)), &node);
self.push_op(OpCode::OpAttrs(Count(count)), &node);
}
// Remove the temporary scope, but do not emit any additional
// cleanup (OpAttrs consumes all of these locals).