feat(tvix/eval): implement initial compiler::optimiser module

This optimiser can rewrite some expressions into more efficient forms,
and warn users about those cases.

As a proof-of-concept, only some simple boolean comparisons are
supported for now.

Change-Id: I7df561118cfbad281fc99523e859bc66e7a1adcb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7766
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2023-01-05 15:11:28 +03:00 committed by tazjin
parent 36e5a4cc07
commit 6a8541e35a
5 changed files with 165 additions and 0 deletions

View file

@ -13,6 +13,8 @@ pub enum WarningKind {
ShadowedGlobal(&'static str),
DeprecatedLegacyLet,
InvalidNixPath(String),
UselessBoolOperation(&'static str),
DeadCode,
/// Tvix internal warning for features triggered by users that are
/// not actually implemented yet, but do not cause runtime failures.
@ -85,6 +87,14 @@ impl EvalWarning {
format!("invalid NIX_PATH resulted in a parse error: {}", err)
}
WarningKind::UselessBoolOperation(msg) => {
format!("useless operation on boolean: {}", msg)
}
WarningKind::DeadCode => {
format!("this code will never be executed")
}
WarningKind::NotImplemented(what) => {
format!("feature not yet implemented in tvix: {}", what)
}
@ -101,6 +111,9 @@ impl EvalWarning {
WarningKind::ShadowedGlobal(_) => "W004",
WarningKind::DeprecatedLegacyLet => "W005",
WarningKind::InvalidNixPath(_) => "W006",
WarningKind::UselessBoolOperation(_) => "W007",
WarningKind::DeadCode => "W008",
WarningKind::NotImplemented(_) => "W999",
}
}