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

@ -15,6 +15,7 @@
mod bindings;
mod import;
mod optimiser;
mod scope;
use codemap::Span;
@ -230,6 +231,8 @@ impl Compiler<'_> {
// Actual code-emitting AST traversal methods.
impl Compiler<'_> {
fn compile(&mut self, slot: LocalIdx, expr: ast::Expr) {
let expr = optimiser::optimise_expr(self, expr);
match &expr {
ast::Expr::Literal(literal) => self.compile_literal(literal),
ast::Expr::Path(path) => self.compile_path(slot, path),