From 31ca5c8aa54a558a74e7d43fb8ef62930ee4cd93 Mon Sep 17 00:00:00 2001 From: EehMauro Date: Tue, 30 Dec 2025 07:54:26 -0300 Subject: [PATCH] feat: update tx3 to v0.14 --- Cargo.lock | 116 ++++++++++++++++++++++++----------- Cargo.toml | 3 +- src/cmds/generate_ast.rs | 6 +- src/cmds/generate_diagram.rs | 11 ++-- src/cmds/generate_tir.rs | 22 +++---- src/lib.rs | 16 ++--- 6 files changed, 107 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b56bc71..66f3ef5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,26 +119,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "bincode" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" -dependencies = [ - "bincode_derive", - "serde", - "unty", -] - -[[package]] -name = "bincode_derive" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" -dependencies = [ - "virtue", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -172,6 +152,33 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "4.5.40" @@ -233,6 +240,12 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "crypto-common" version = "0.1.6" @@ -403,6 +416,17 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -1224,11 +1248,11 @@ dependencies = [ [[package]] name = "tx3-lang" -version = "0.11.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4faaad8f112e459a8e06c0ccd07756cf4b71a5d5545d1b95078c304dc74934fe" +checksum = "f417262ee0e5c4f4749ca355054dd790126a1cc5d69307d0f220df3b0f8c68d4" dependencies = [ - "bincode", + "ciborium", "hex", "miette", "pest", @@ -1236,6 +1260,7 @@ dependencies = [ "serde", "thiserror", "trait-variant", + "tx3-tir", ] [[package]] @@ -1254,9 +1279,22 @@ dependencies = [ "tower", "tower-lsp", "tx3-lang", + "tx3-tir", "url", ] +[[package]] +name = "tx3-tir" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a98854a4d5de6cde2025a5e84d596c5e7128219b594a08156c3f2270923fc165" +dependencies = [ + "ciborium", + "hex", + "serde", + "thiserror", +] + [[package]] name = "typenum" version = "1.18.0" @@ -1293,12 +1331,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" -[[package]] -name = "unty" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" - [[package]] name = "url" version = "2.5.4" @@ -1329,12 +1361,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "virtue" -version = "0.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -1526,6 +1552,26 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zerocopy" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zerofrom" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 57d942f..3428305 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,8 @@ tower-lsp = "0.20.0" tower = { version = "0.4", features = ["util"] } dashmap = "6.1.0" ropey = "1.6.1" -tx3-lang = "0.11.0" +tx3-lang = "0.14.0" +tx3-tir = "0.14.0" pest = "2.7.15" miette = "7.5.0" serde_json = "1.0.140" diff --git a/src/cmds/generate_ast.rs b/src/cmds/generate_ast.rs index a3b3a9e..4d7b9dd 100644 --- a/src/cmds/generate_ast.rs +++ b/src/cmds/generate_ast.rs @@ -26,12 +26,12 @@ pub async fn run( ) -> Result, Error> { let args: Args = args.try_into()?; - let protocol = context.get_document_protocol(&args.document_url)?; + let mut program = context.get_document_program(&args.document_url)?; - let ast = protocol.ast().to_owned(); + tx3_lang::analyzing::analyze(&mut program).ok().unwrap(); let out = json!({ - "ast": ast, + "ast": program, }); Ok(Some(out)) diff --git a/src/cmds/generate_diagram.rs b/src/cmds/generate_diagram.rs index 03f49bb..477e3e2 100644 --- a/src/cmds/generate_diagram.rs +++ b/src/cmds/generate_diagram.rs @@ -25,16 +25,17 @@ pub async fn run( ) -> Result, Error> { let args: Args = args.try_into()?; - let protocol = context.get_document_protocol(&args.document_url)?; - let ast = protocol.ast().to_owned(); + let mut program = context.get_document_program(&args.document_url)?; - let tx_svgs: Vec = ast + tx3_lang::analyzing::analyze(&mut program).ok().unwrap(); + + let tx_svgs: Vec = program .txs .iter() .map(|tx| { - let svg = tx_to_svg(&ast, tx); + let svg = tx_to_svg(&program, tx); json!({ - "tx_name": tx.name, + "tx_name": tx.name.value, "svg": svg }) }) diff --git a/src/cmds/generate_tir.rs b/src/cmds/generate_tir.rs index 9059e07..497e341 100644 --- a/src/cmds/generate_tir.rs +++ b/src/cmds/generate_tir.rs @@ -1,7 +1,5 @@ -use std::collections::HashMap; - use serde_json::{json, Value}; - +use tx3_tir::reduce::Apply; use crate::{Context, Error}; #[derive(Debug)] @@ -35,20 +33,18 @@ pub async fn run( ) -> Result, Error> { let args: Args = args.try_into()?; - let protocol = context.get_document_protocol(&args.document_url)?; + let mut program = context.get_document_program(&args.document_url)?; + + tx3_lang::analyzing::analyze(&mut program).ok().unwrap(); - let prototx = protocol.new_tx(&args.tx_name)?; + let tx = tx3_lang::lowering::lower(&program, &args.tx_name).unwrap(); - let params = prototx - .find_params() - .iter() - .map(|(k, v)| (k.to_string(), serde_json::to_value(v).unwrap())) - .collect::>(); + let tir = tx3_tir::encoding::to_bytes(&tx); let out = json!({ - "tir": hex::encode(prototx.ir_bytes()), - "version": tx3_lang::ir::IR_VERSION, - "parameters": params, + "tir": hex::encode(&tir.0), + "version": tir.1, + "parameters": tx.params(), }); Ok(Some(out)) diff --git a/src/lib.rs b/src/lib.rs index 04e07e3..08297de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ use thiserror::Error; use tower_lsp::jsonrpc::ErrorCode; use tower_lsp::lsp_types::*; use tower_lsp::Client; -use tx3_lang::Protocol; mod ast_to_svg; mod cmds; @@ -27,8 +26,8 @@ pub enum Error { #[error("Document not found: {0}")] DocumentNotFound(Url), - #[error("Protocol loading error: {0}")] - ProtocolLoadingError(#[from] tx3_lang::loading::Error), + #[error("Program parsing error: {0}")] + ProgramParsingError(#[from] tx3_lang::parsing::Error), #[error("Tx3 Lowering error: {0}")] TxLoweringError(#[from] tx3_lang::lowering::Error), @@ -41,7 +40,7 @@ impl From<&Error> for ErrorCode { Error::ParseError(_) => ErrorCode::InvalidParams, Error::DocumentNotFound(_) => ErrorCode::InvalidParams, Error::InvalidCommandArgs(_) => ErrorCode::InvalidParams, - Error::ProtocolLoadingError(_) => ErrorCode::InvalidRequest, + Error::ProgramParsingError(_) => ErrorCode::InvalidRequest, Error::TxLoweringError(_) => ErrorCode::InvalidRequest, } } @@ -243,7 +242,7 @@ impl Context { token_modifiers: MOD_DECLARATION | MOD_DEFINITION, }); } - visitor::SymbolAtOffset::TypeIdentifier(x) => { + visitor::SymbolAtOffset::TypeIdentifier(_x) => { // TODO: wait for the introduction of `TypeAnnotation` in AST // token_infos.push(TokenInfo { @@ -315,12 +314,9 @@ impl Context { Ok(document.value().clone()) } - fn get_document_protocol(&self, url_arg: &str) -> Result { + fn get_document_program(&self, url_arg: &str) -> Result { let document = self.get_document(url_arg)?; - - let protocol = Protocol::from_string(document.to_string()).load()?; - - Ok(protocol) + tx3_lang::parsing::parse_string(document.to_string().as_str()).map_err(Error::ProgramParsingError) } async fn process_document(&self, uri: Url, text: &str) -> Vec {