refactor(tvix/eval): Upgrade to latest rnix-parser
Since the latest published version of rnix-parser on crates.io, the crate has undergone major changes which are only available in the git repository at the moment. This commit updates the compiler to this newer version of rnix. Most notably, the entire AST provided by rnix is now wrapped in the AST type system. As a result of this traversal is much nicer in many places, especially for things like nested attribute selection. There are a handful of smaller features missing for full feature parity with the previous version, especially handling of path literals, but PRs for these already exist in rnix-parser. Change-Id: Icde6d393067976549492b7d89c4cc49e5e575fc7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6231 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
a00e4730a5
commit
813fb98470
6 changed files with 529 additions and 637 deletions
41
tvix/eval/Cargo.lock
generated
41
tvix/eval/Cargo.lock
generated
|
@ -49,15 +49,6 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cbitset"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29b6ad25ae296159fb0da12b970b2fe179b234584d7cd294c891e2bbb284466b"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
|
@ -94,9 +85,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "countme"
|
||||
version = "2.0.4"
|
||||
version = "3.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
|
||||
checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636"
|
||||
|
||||
[[package]]
|
||||
name = "criterion"
|
||||
|
@ -337,9 +328,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
|
|||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.9.1"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
|
@ -647,20 +638,17 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
|||
|
||||
[[package]]
|
||||
name = "rnix"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8024a523e8836f1a5d051203dc00d833357fee94e351b51348dfaeca5364daa9"
|
||||
version = "0.11.0-dev"
|
||||
source = "git+https://github.com/nix-community/rnix-parser.git?rev=ae9fe1344993bb57d292f361c83e0379282e88ed#ae9fe1344993bb57d292f361c83e0379282e88ed"
|
||||
dependencies = [
|
||||
"cbitset",
|
||||
"rowan",
|
||||
"smol_str",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rowan"
|
||||
version = "0.12.6"
|
||||
version = "0.15.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
|
||||
checksum = "e88acf7b001007e9e8c989fe7449f6601d909e5dd2c56399fc158977ad6c56e8"
|
||||
dependencies = [
|
||||
"countme",
|
||||
"hashbrown",
|
||||
|
@ -735,9 +723,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.142"
|
||||
version = "1.0.144"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2"
|
||||
checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
|
||||
|
||||
[[package]]
|
||||
name = "serde_cbor"
|
||||
|
@ -852,18 +840,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.32"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994"
|
||||
checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.32"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21"
|
||||
checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.43",
|
||||
"quote 1.0.21",
|
||||
|
@ -889,6 +877,7 @@ dependencies = [
|
|||
"path-clean",
|
||||
"pretty_assertions",
|
||||
"rnix",
|
||||
"rowan",
|
||||
"rustyline",
|
||||
"smol_str",
|
||||
"tabwriter",
|
||||
|
|
|
@ -6,12 +6,18 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rnix = "0.10.2"
|
||||
smol_str = "0.1"
|
||||
rustyline = "10.0.0"
|
||||
dirs = "4.0.0"
|
||||
path-clean = "0.1"
|
||||
tabwriter = { version = "1.2", optional = true }
|
||||
rowan = "*" # pinned by rnix
|
||||
|
||||
# rnix has not been released in a while (as of 2022-08-16), we will
|
||||
# use it from git.
|
||||
[dependencies.rnix]
|
||||
git = "https://github.com/nix-community/rnix-parser.git"
|
||||
rev = "ae9fe1344993bb57d292f361c83e0379282e88ed"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3.6"
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ pub enum Error {
|
|||
DynamicKeyInLet(rnix::SyntaxNode),
|
||||
|
||||
// Unknown variable in statically known scope.
|
||||
UnknownStaticVariable(rnix::types::Ident),
|
||||
UnknownStaticVariable(rnix::ast::Ident),
|
||||
|
||||
// Unknown variable in dynamic scope (with, rec, ...).
|
||||
UnknownDynamicVariable(String),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use rnix::{self, types::TypedNode};
|
||||
use rnix;
|
||||
|
||||
use crate::{
|
||||
errors::{Error, EvalResult},
|
||||
|
@ -8,21 +8,27 @@ use crate::{
|
|||
};
|
||||
|
||||
pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
|
||||
let ast = rnix::parse(code);
|
||||
let parsed = rnix::ast::Root::parse(code);
|
||||
let errors = parsed.errors();
|
||||
|
||||
let errors = ast.errors();
|
||||
if !errors.is_empty() {
|
||||
for err in &errors {
|
||||
for err in errors {
|
||||
eprintln!("parse error: {}", err);
|
||||
return Err(Error::ParseErrors(errors));
|
||||
}
|
||||
return Err(Error::ParseErrors(errors.to_vec()));
|
||||
}
|
||||
|
||||
// If we've reached this point, there are no errors.
|
||||
let root_expr = parsed
|
||||
.tree()
|
||||
.expr()
|
||||
.expect("expression should exist if no errors occured");
|
||||
|
||||
if std::env::var("TVIX_DISPLAY_AST").is_ok() {
|
||||
println!("{}", ast.root().dump());
|
||||
println!("{:?}", root_expr);
|
||||
}
|
||||
|
||||
let result = crate::compiler::compile(ast, location)?;
|
||||
let result = crate::compiler::compile(root_expr, location)?;
|
||||
|
||||
#[cfg(feature = "disassembler")]
|
||||
crate::disassembler::disassemble_chunk(&result.chunk);
|
||||
|
|
|
@ -83,7 +83,7 @@ impl VM {
|
|||
}
|
||||
|
||||
fn pop(&mut self) -> Value {
|
||||
self.stack.pop().expect("TODO")
|
||||
self.stack.pop().expect("runtime stack empty")
|
||||
}
|
||||
|
||||
fn push(&mut self, value: Value) {
|
||||
|
|
Loading…
Reference in a new issue