feat(tvix/eval): implement legacy let syntax

... and emit a warning if anyone decides to use.

Change-Id: Iaa6fe9fa932340e6d0fa9f357155e78823702576
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6611
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-09-16 19:48:30 +03:00 committed by tazjin
parent 20230e1e2d
commit e86acd3212
2 changed files with 18 additions and 4 deletions

View file

@ -188,10 +188,7 @@ impl Compiler<'_, '_> {
// their value on the stack. // their value on the stack.
ast::Expr::Paren(paren) => self.compile(slot, paren.expr().unwrap()), ast::Expr::Paren(paren) => self.compile(slot, paren.expr().unwrap()),
ast::Expr::LegacyLet(_) => { ast::Expr::LegacyLet(legacy_let) => self.compile_legacy_let(slot, legacy_let),
let span = self.span_for(&expr);
self.emit_error(span, ErrorKind::NotImplemented("legacy let syntax"));
}
ast::Expr::Root(_) => unreachable!("there cannot be more than one root"), ast::Expr::Root(_) => unreachable!("there cannot be more than one root"),
ast::Expr::Error(_) => unreachable!("compile is only called on validated trees"), ast::Expr::Error(_) => unreachable!("compile is only called on validated trees"),
@ -997,6 +994,17 @@ impl Compiler<'_, '_> {
self.push_op(OpCode::OpCall, &node); self.push_op(OpCode::OpCall, &node);
} }
fn compile_legacy_let(&mut self, slot: LocalIdx, node: ast::LegacyLet) {
self.scope_mut().begin_scope();
self.compile_recursive_scope(slot, true, &node);
self.push_op(OpCode::OpAttrs(Count(node.entries().count())), &node);
self.emit_constant(Value::String(SmolStr::new_inline("body").into()), &node);
self.push_op(OpCode::OpAttrsSelect, &node);
let warning_span = self.span_for(&node);
self.emit_warning(warning_span, WarningKind::DeprecatedLegacyLet);
}
/// Compile an expression into a runtime thunk which should be /// Compile an expression into a runtime thunk which should be
/// lazily evaluated when accessed. /// lazily evaluated when accessed.
// TODO: almost the same as Compiler::compile_lambda; unify? // TODO: almost the same as Compiler::compile_lambda; unify?

View file

@ -10,6 +10,7 @@ pub enum WarningKind {
UselessInherit, UselessInherit,
UnusedBinding, UnusedBinding,
ShadowedGlobal(&'static str), ShadowedGlobal(&'static str),
DeprecatedLegacyLet,
/// Tvix internal warning for features triggered by users that are /// Tvix internal warning for features triggered by users that are
/// not actually implemented yet, but do not cause runtime failures. /// not actually implemented yet, but do not cause runtime failures.
@ -75,6 +76,10 @@ impl EvalWarning {
format!("declared variable '{}' shadows a built-in global!", name) format!("declared variable '{}' shadows a built-in global!", name)
} }
WarningKind::DeprecatedLegacyLet => {
"legacy `let` syntax used, please rewrite this as `let .. in ...`".to_string()
}
WarningKind::NotImplemented(what) => { WarningKind::NotImplemented(what) => {
format!("feature not yet implemented in tvix: {}", what) format!("feature not yet implemented in tvix: {}", what)
} }
@ -89,6 +94,7 @@ impl EvalWarning {
WarningKind::UselessInherit => "W002", WarningKind::UselessInherit => "W002",
WarningKind::UnusedBinding => "W003", WarningKind::UnusedBinding => "W003",
WarningKind::ShadowedGlobal(_) => "W004", WarningKind::ShadowedGlobal(_) => "W004",
WarningKind::DeprecatedLegacyLet => "W005",
WarningKind::NotImplemented(_) => "W999", WarningKind::NotImplemented(_) => "W999",
} }
} }