From 4f91ecd58ca826c55480d3022a9251fd85132d61 Mon Sep 17 00:00:00 2001 From: Simon Tennant Date: Mon, 28 Jul 2025 15:34:14 +0200 Subject: [PATCH 1/3] update simfony references to SimplicityHL in README.md --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b333726..312c1e6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -Simfony is a high-level language for writing Bitcoin smart contracts. +SimplicityHL is a high-level language for writing Bitcoin smart contracts. -Simfony looks and feels like [Rust](https://www.rust-lang.org). Just how Rust compiles down to assembly language, Simfony compiles down to [Simplicity](https://github.com/BlockstreamResearch/simplicity) bytecode. Developers write Simfony, full nodes execute Simplicity. +SimplicityHL looks and feels like [Rust](https://www.rust-lang.org). Just how Rust compiles down to assembly language, SimplicityHL compiles down to [Simplicity](https://github.com/BlockstreamResearch/simplicity) bytecode. Developers write SimplicityHL, full nodes execute Simplicity. -**Simfony is a work in progress and is not yet ready for production use.** +**SimplicityHL is a work in progress and is not yet ready for production use.** ```rust let a: u32 = 10; @@ -16,7 +16,7 @@ let b = { assert!(jet::eq_32(b, 7)); ``` -Take a look at the [example programs](https://github.com/BlockstreamResearch/simfony/tree/master/examples). +Take a look at the [example programs](https://github.com/BlockstreamResearch/SimplicityHL/tree/master/examples). ## MSRV @@ -24,30 +24,30 @@ This crate should compile with any feature combination on **Rust 1.78.0** or hig ## Simplicity's need for a high-level language -Simplicity introduces a groundbreaking low-level programming language and machine model meticulously crafted for blockchain-based smart contracts. The primary goal is to provide a streamlined and comprehensible foundation that facilitates static analysis and encourages reasoning through formal methods. While the elegance of the language itself is distilled into something as succinct as fitting onto a T-shirt, it's important to note that the simplicity of the language doesn't directly equate to simplicity in the development process. Simfony revolves around demystifying and simplifying the complexities involved in this ecosystem. +Simplicity introduces a groundbreaking low-level programming language and machine model meticulously crafted for blockchain-based smart contracts. The primary goal is to provide a streamlined and comprehensible foundation that facilitates static analysis and encourages reasoning through formal methods. While the elegance of the language itself is distilled into something as succinct as fitting onto a T-shirt, it's important to note that the simplicity of the language doesn't directly equate to simplicity in the development process. SimplicityHL revolves around demystifying and simplifying the complexities involved in this ecosystem. The distinguishing aspects that set Simplicity apart from conventional programming languages are: - **Distinct Programming Paradigm**: Simplicity's programming model requires a paradigm shift from conventional programming. It hinges on reasoning about programs in a functional sense with a focus on combinators. This intricacy surpasses even popular functional languages like Haskell, with its own unique challenges. - **Exceptional Low-Level Nature**: Unlike high-level languages such as JavaScript or Python, Simplicity operates at an extremely low level, resembling assembly languages. This design choice enables easier reasoning about the formal semantics of programs, but is really work on directly. -## Simfony +## SimplicityHL -Simfony is a high-level language that compiles to Simplicity. It maps programming concepts from Simplicity onto programming concepts that developers are more familar with. In particular, Rust is a popular language whose functional aspects fit Simplicity well. Simfony aims to closely resemble Rust. +SimplicityHL is a high-level language that compiles to Simplicity. It maps programming concepts from Simplicity onto programming concepts that developers are more familar with. In particular, Rust is a popular language whose functional aspects fit Simplicity well. SimplicityHL aims to closely resemble Rust. -Just how Rust is compiled to assembly language, Simfony is compiled to Simplicity. Just how writing Rust doesn't necessarily produce the most efficient assembly, writing Simfony doesn't necessarily produce the most efficient Simplicity code. The compilers try to optimize the target code they produce, but manually written target code can be more efficient. On the other hand, a compiled language is much easier to read, write and reason about. Assembly is meant to be consumed by machines while Rust is meant to be consumed by humans. Simplicity is meant to be consumed by Bitcoin full nodes while Simfony is meant to be consumed by Bitcoin developers. +Just how Rust is compiled to assembly language, SimplicityHL is compiled to Simplicity. Just how writing Rust doesn't necessarily produce the most efficient assembly, writing SimplicityHL doesn't necessarily produce the most efficient Simplicity code. The compilers try to optimize the target code they produce, but manually written target code can be more efficient. On the other hand, a compiled language is much easier to read, write and reason about. Assembly is meant to be consumed by machines while Rust is meant to be consumed by humans. Simplicity is meant to be consumed by Bitcoin full nodes while SimplicityHL is meant to be consumed by Bitcoin developers. ## Installation -Clone the repo and build the Simfony compiler using cargo. +Clone the repo and build the SimplicityHL compiler using cargo. ```bash -git clone https://github.com/BlockstreamResearch/simfony.git -cd simfony +git clone https://github.com/BlockstreamResearch/SimplicityHL.git +cd SimplicityHL cargo build ``` -Optionally, install the Simfony compiler using cargo. +Optionally, install the SimplicityHL compiler using cargo. ```bash cargo install --path . @@ -55,10 +55,10 @@ cargo install --path . ## Usage -The Simfony compiler takes two arguments: +The SimplicityHL compiler takes two arguments: -1. A path to a Simfony program file (`.simf`) -1. A path to a Simfony witness file (`.wit`, optional) +1. A path to a SimplicityHL program file (`.simf`) +1. A path to a SimplicityHL witness file (`.wit`, optional) The compiler produces a base64-encoded Simplicity program. Witness data will be included if a witness file is provided. From b393f7ee5501faff54e37fdfd0c609848b426e5f Mon Sep 17 00:00:00 2001 From: Simon Tennant Date: Mon, 28 Jul 2025 21:14:38 +0200 Subject: [PATCH 2/3] change Simfony references to SimplicityHL --- Cargo.lock | 38 ++++---- Cargo.toml | 8 +- bitcoind-tests/Cargo.lock | 4 +- bitcoind-tests/Cargo.toml | 2 +- bitcoind-tests/tests/common/daemon.rs | 2 +- bitcoind-tests/tests/common/test.rs | 18 ++-- bitcoind-tests/tests/common/util.rs | 4 +- bitcoind-tests/tests/spend_utxo.rs | 28 +++--- book/book.toml | 2 +- book/src/function.md | 8 +- book/src/introduction.md | 8 +- book/src/let_statement.md | 4 +- book/src/match_expression.md | 4 +- book/src/program.md | 2 +- book/src/type.md | 8 +- book/src/type_alias.md | 4 +- book/src/type_casting.md | 8 +- codegen/Cargo.toml | 4 +- codegen/src/jet.rs | 2 +- codegen/src/main.rs | 12 +-- doc/context.md | 4 +- doc/environment.md | 8 +- doc/translation.md | 4 +- flake.nix | 2 +- fuzz/Cargo.toml | 4 +- fuzz/fuzz_targets/compile_parse_tree.rs | 4 +- fuzz/fuzz_targets/compile_text.rs | 4 +- fuzz/fuzz_targets/display_parse_tree.rs | 2 +- fuzz/fuzz_targets/parse_value_rtt.rs | 2 +- fuzz/fuzz_targets/parse_witness_json_rtt.rs | 2 +- fuzz/fuzz_targets/parse_witness_module_rtt.rs | 4 +- fuzz/fuzz_targets/reconstruct_value.rs | 2 +- src/ast.rs | 2 +- src/compile.rs | 14 +-- src/debug.rs | 12 +-- src/error.rs | 4 +- src/lib.rs | 26 ++--- src/main.rs | 14 +-- src/named.rs | 2 +- src/pattern.rs | 2 +- src/types.rs | 8 +- src/value.rs | 95 ++++++------------- vscode/LICENSE | 2 +- vscode/README.md | 2 +- vscode/package.json | 4 +- 45 files changed, 179 insertions(+), 220 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a381af1..b69c134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -219,7 +219,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" name = "codegen" version = "0.1.0" dependencies = [ - "simfony", + "simplicityhl", ] [[package]] @@ -620,24 +620,6 @@ dependencies = [ "digest", ] -[[package]] -name = "simfony" -version = "0.1.0" -dependencies = [ - "arbitrary", - "base64", - "clap", - "either", - "getrandom", - "itertools", - "miniscript", - "pest", - "pest_derive", - "serde", - "serde_json", - "simplicity-lang", -] - [[package]] name = "simplicity-lang" version = "0.4.0" @@ -665,6 +647,24 @@ dependencies = [ "cc", ] +[[package]] +name = "simplicityhl" +version = "0.1.0" +dependencies = [ + "arbitrary", + "base64", + "clap", + "either", + "getrandom", + "itertools", + "miniscript", + "pest", + "pest_derive", + "serde", + "serde_json", + "simplicity-lang", +] + [[package]] name = "strsim" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index 9e303fc..ae8f4c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,16 @@ [package] -name = "simfony" +name = "simplicityhl" version = "0.1.0" authors = ["sanket1729 "] license = "CC0-1.0" -homepage = "https://github.com/BlockstreamResearch/simfony/" -repository = "https://github.com/BlockstreamResearch/simfony/" +homepage = "https://github.com/BlockstreamResearch/SimplicityHL" +repository = "https://github.com/BlockstreamResearch/SimplicityHL" description = "Rust-like language that compiles to Simplicity bytecode." edition = "2021" rust-version = "1.78.0" [lib] -name = "simfony" +name = "simplicityhl" path = "src/lib.rs" [[bin]] diff --git a/bitcoind-tests/Cargo.lock b/bitcoind-tests/Cargo.lock index 7bd88d3..d1beef4 100644 --- a/bitcoind-tests/Cargo.lock +++ b/bitcoind-tests/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ "elementsd", "rand", "secp256k1", - "simfony", + "simplicityhl", ] [[package]] @@ -693,7 +693,7 @@ dependencies = [ ] [[package]] -name = "simfony" +name = "simplicityhl" version = "0.1.0" dependencies = [ "base64 0.21.2", diff --git a/bitcoind-tests/Cargo.toml b/bitcoind-tests/Cargo.toml index a770d4c..5dd2023 100644 --- a/bitcoind-tests/Cargo.toml +++ b/bitcoind-tests/Cargo.toml @@ -5,7 +5,7 @@ authors = ["sanket1729 "] edition = "2021" [dependencies] -simfony = { path = ".." } +simplicityhl = { path = ".." } elementsd = { version = "0.11.0" } actual-rand = { package = "rand", version = "0.8.4" } secp256k1 = { version = "0.29.0", features = ["rand-std"] } diff --git a/bitcoind-tests/tests/common/daemon.rs b/bitcoind-tests/tests/common/daemon.rs index c33b157..c6cdd46 100644 --- a/bitcoind-tests/tests/common/daemon.rs +++ b/bitcoind-tests/tests/common/daemon.rs @@ -5,7 +5,7 @@ use elements::hex::FromHex; use elementsd::bitcoincore_rpc::jsonrpc::serde_json::{json, Value}; use elementsd::bitcoind::bitcoincore_rpc::RpcApi; use elementsd::ElementsD; -use simfony::elements; +use simplicityhl::elements; // We are not using pegins right now, but it might be required in case in future // if we extend the tests to check pegins etc. diff --git a/bitcoind-tests/tests/common/test.rs b/bitcoind-tests/tests/common/test.rs index 5dd151f..b3be027 100644 --- a/bitcoind-tests/tests/common/test.rs +++ b/bitcoind-tests/tests/common/test.rs @@ -5,18 +5,18 @@ use elements::pset::PartiallySignedTransaction as Psbt; use elements::{confidential, secp256k1_zkp as secp256k1}; use elementsd::ElementsD; use secp256k1::XOnlyPublicKey; -use simfony::{elements, simplicity}; use simplicity::jet::elements::{ElementsEnv, ElementsUtxo}; +use simplicityhl::{elements, simplicity}; use crate::common::daemon::Call; -type FnWitness = fn([u8; 32]) -> simfony::WitnessValues; +type FnWitness = fn([u8; 32]) -> simplicityhl::WitnessValues; #[derive(Clone)] pub struct TestCase<'a> { pub name: &'static str, - template: Option, - compiled: Option, + template: Option, + compiled: Option, witness: FnWitness, lock_time: elements::LockTime, sequence: elements::Sequence, @@ -53,7 +53,7 @@ impl<'a> TestCase<'a> { pub fn program_path>(mut self, path: P) -> Self { let text = std::fs::read_to_string(path).expect("path should be readable"); - let compiled = simfony::CompiledProgram::new(text.as_str(), simfony::Arguments::default(), false) + let compiled = simplicityhl::CompiledProgram::new(text.as_str(), simplicityhl::Arguments::default(), false) .expect("program should compile"); self.compiled = Some(compiled); self @@ -62,12 +62,12 @@ impl<'a> TestCase<'a> { pub fn template_path>(mut self, path: P) -> Self { let text = std::fs::read_to_string(path).expect("path should be readable"); let template = - simfony::TemplateProgram::new(text.as_str()).expect("program should compile"); + simplicityhl::TemplateProgram::new(text.as_str()).expect("program should compile"); self.template = Some(template); self } - pub fn arguments(mut self, arguments: simfony::Arguments) -> Self { + pub fn arguments(mut self, arguments: simplicityhl::Arguments) -> Self { let compiled = self .template .as_ref() @@ -220,6 +220,6 @@ impl<'a> TestCase<'a> { } } -fn empty_witness(_sighash_all: [u8; 32]) -> simfony::WitnessValues { - simfony::WitnessValues::default() +fn empty_witness(_sighash_all: [u8; 32]) -> simplicityhl::WitnessValues { + simplicityhl::WitnessValues::default() } diff --git a/bitcoind-tests/tests/common/util.rs b/bitcoind-tests/tests/common/util.rs index 8ce7d73..7edc217 100644 --- a/bitcoind-tests/tests/common/util.rs +++ b/bitcoind-tests/tests/common/util.rs @@ -11,8 +11,8 @@ pub fn sign_schnorr(secret_key: u32, message: [u8; 32]) -> [u8; 64] { key_pair.sign_schnorr(message).serialize() } -pub fn xonly_public_key(secret_key: u32) -> simfony::num::U256 { +pub fn xonly_public_key(secret_key: u32) -> simplicityhl::num::U256 { let key_pair = key_pair(secret_key); let bytes = key_pair.x_only_public_key().0.serialize(); - simfony::num::U256::from_byte_array(bytes) + simplicityhl::num::U256::from_byte_array(bytes) } diff --git a/bitcoind-tests/tests/spend_utxo.rs b/bitcoind-tests/tests/spend_utxo.rs index 3f1cd64..01d9183 100644 --- a/bitcoind-tests/tests/spend_utxo.rs +++ b/bitcoind-tests/tests/spend_utxo.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; use elements::hashes::Hash; use elements::secp256k1_zkp as secp256k1; use secp256k1::hashes::{sha256, HashEngine}; -use simfony::str::WitnessName; -use simfony::types::TypeConstructible; -use simfony::value::ValueConstructible; -use simfony::{elements, ResolvedType, Value}; +use simplicityhl::str::WitnessName; +use simplicityhl::types::TypeConstructible; +use simplicityhl::value::ValueConstructible; +use simplicityhl::{elements, ResolvedType, Value}; mod common; use common::daemon::{self, Call}; @@ -49,7 +49,7 @@ fn spend_utxo() { } } -fn hodl_vault(sighash_all: [u8; 32]) -> simfony::WitnessValues { +fn hodl_vault(sighash_all: [u8; 32]) -> simplicityhl::WitnessValues { let mut witness_values = HashMap::new(); let oracle_height = 1000; witness_values.insert( @@ -73,24 +73,24 @@ fn hodl_vault(sighash_all: [u8; 32]) -> simfony::WitnessValues { WitnessName::from_str_unchecked("OWNER_SIG"), Value::byte_array(util::sign_schnorr(2, sighash_all)), ); - simfony::WitnessValues::from(witness_values) + simplicityhl::WitnessValues::from(witness_values) } -fn p2pk_args() -> simfony::Arguments { - simfony::Arguments::from(HashMap::from([( +fn p2pk_args() -> simplicityhl::Arguments { + simplicityhl::Arguments::from(HashMap::from([( WitnessName::from_str_unchecked("ALICE_PUBLIC_KEY"), Value::u256(util::xonly_public_key(1)), )])) } -fn p2pk(sighash_all: [u8; 32]) -> simfony::WitnessValues { - simfony::WitnessValues::from(HashMap::from([( +fn p2pk(sighash_all: [u8; 32]) -> simplicityhl::WitnessValues { + simplicityhl::WitnessValues::from(HashMap::from([( WitnessName::from_str_unchecked("ALICE_SIGNATURE"), Value::byte_array(util::sign_schnorr(1, sighash_all)), )])) } -fn p2pkh(sighash_all: [u8; 32]) -> simfony::WitnessValues { +fn p2pkh(sighash_all: [u8; 32]) -> simplicityhl::WitnessValues { let mut witness_values = HashMap::new(); witness_values.insert( WitnessName::from_str_unchecked("PK"), @@ -100,10 +100,10 @@ fn p2pkh(sighash_all: [u8; 32]) -> simfony::WitnessValues { WitnessName::from_str_unchecked("SIG"), Value::byte_array(util::sign_schnorr(1, sighash_all)), ); - simfony::WitnessValues::from(witness_values) + simplicityhl::WitnessValues::from(witness_values) } -fn p2ms(sighash_all: [u8; 32]) -> simfony::WitnessValues { +fn p2ms(sighash_all: [u8; 32]) -> simplicityhl::WitnessValues { let mut witness_values = HashMap::new(); let sig1 = Value::some(Value::byte_array(util::sign_schnorr(1, sighash_all))); let sig2 = Value::none(ResolvedType::byte_array(64)); @@ -111,5 +111,5 @@ fn p2ms(sighash_all: [u8; 32]) -> simfony::WitnessValues { let ty = sig1.ty().clone(); let maybe_sigs = Value::array([sig1, sig2, sig3], ty); witness_values.insert(WitnessName::from_str_unchecked("MAYBE_SIGS"), maybe_sigs); - simfony::WitnessValues::from(witness_values) + simplicityhl::WitnessValues::from(witness_values) } diff --git a/book/book.toml b/book/book.toml index 3c5e97f..c25c24c 100644 --- a/book/book.toml +++ b/book/book.toml @@ -3,4 +3,4 @@ authors = ["Christian Lewe"] language = "en" multilingual = false src = "src" -title = "The Simfony Programming Language" +title = "The SimplicityHL Programming Language" diff --git a/book/src/function.md b/book/src/function.md index 3f92165..92588be 100644 --- a/book/src/function.md +++ b/book/src/function.md @@ -31,12 +31,12 @@ let z: u32 = add(40, 2); ## No early returns -Simfony has no support for an early return via a "return" keyword. +SimplicityHL has no support for an early return via a "return" keyword. The only branching that is available is via [match expressions](./match_expression.md). ## No recursion -Simfony has no support for recursive function calls. +SimplicityHL has no support for recursive function calls. A function can be called inside a function body if it has been defined before. This means that a function cannot call itself. Loops, where `f` calls `g` and `g` calls `f`, are also impossible. @@ -75,7 +75,7 @@ fn g() -> u32 { ## Main function -The `main` function is the entry point of each Simfony program. +The `main` function is the entry point of each SimplicityHL program. Running a program means running its `main` function. Other functions are called from the `main` function. @@ -86,7 +86,7 @@ fn main() { ``` The `main` function is a reserved name and must exist in every program. -Simfony programs are always "binaries". +SimplicityHL programs are always "binaries". There is no support for "libraries". ## Jets diff --git a/book/src/introduction.md b/book/src/introduction.md index 40c9bd5..9610e60 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -1,7 +1,7 @@ # Introduction -Simfony is a high-level language for writing Bitcoin smart contracts. -In other words, Simfony is a language for expressing spending conditions of UTXOs on the Bitcoin blockchain. +SimplicityHL is a high-level language for writing Bitcoin smart contracts. +In other words, SimplicityHL is a language for expressing spending conditions of UTXOs on the Bitcoin blockchain. -Simfony looks and feels like [Rust](https://www.rust-lang.org/). -Developers write Simfony, Bitcoin full nodes run Simplicity. +SimplicityHL looks and feels like [Rust](https://www.rust-lang.org/). +Developers write SimplicityHL, Bitcoin full nodes run Simplicity. diff --git a/book/src/let_statement.md b/book/src/let_statement.md index f9cb1d3..70c9d1c 100644 --- a/book/src/let_statement.md +++ b/book/src/let_statement.md @@ -17,12 +17,12 @@ Variables can be assigned to the output value of any expression, such as functio ## Explicit typing -In Simfony, the type of a defined variable **always** has to be written. +In SimplicityHL, the type of a defined variable **always** has to be written. This is different from Rust, which has better type inference. ## Immutability -Simfony variables are **always** immutable. +SimplicityHL variables are **always** immutable. There are no mutable variables. ## Redefinition and scoping diff --git a/book/src/match_expression.md b/book/src/match_expression.md index f5a1574..5e2e2e0 100644 --- a/book/src/match_expression.md +++ b/book/src/match_expression.md @@ -21,7 +21,7 @@ The whole match expression returns a value of type `u32`, from one of the two ar ## Explicit typing -In Simfony, the type of variables inside match arms must **always** be written. +In SimplicityHL, the type of variables inside match arms must **always** be written. This is different from Rust, which has better type inference. ## Pattern matching @@ -29,7 +29,7 @@ This is different from Rust, which has better type inference. There is limited support for pattern matching inside match expressions. Boolean values can be matched. -The Boolean match expression is the replacement for an "if-then-else" in Simfony. +The Boolean match expression is the replacement for an "if-then-else" in SimplicityHL. ```rust let bit_flip: bool = match false { diff --git a/book/src/program.md b/book/src/program.md index 869ceeb..dfb6ec1 100644 --- a/book/src/program.md +++ b/book/src/program.md @@ -1,6 +1,6 @@ # Programs -A Simfony program consists of a `main` [function](./function.md). +A SimplicityHL program consists of a `main` [function](./function.md). A program may also have [type aliases](./type_alias.md) or custom [function definitions](./function.md). The `main` function comes last in the program, because everything it calls must be defined before it. diff --git a/book/src/type.md b/book/src/type.md index baa6773..4f0295f 100644 --- a/book/src/type.md +++ b/book/src/type.md @@ -1,6 +1,6 @@ # Types and Values -Simfony mostly uses a subset of Rust's types. +SimplicityHL mostly uses a subset of Rust's types. It extends Rust in some ways to make it work better with Simplicity and with the blockchain. ## Boolean Type @@ -27,7 +27,7 @@ Values of type `bool` are truth values, which are either `true` or `false`. Unsigned integers range from 1 bit to 256 bits. [`u8`](https://doc.rust-lang.org/std/primitive.u8.html) to [`u128`](https://doc.rust-lang.org/std/primitive.u128.html) are also supported in Rust. -`u1`, `u2`, `u4` and `u256` are new to Simfony. +`u1`, `u2`, `u4` and `u256` are new to SimplicityHL. Integer values can be written in decimal notation `123456`, binary notation[^bin] `0b10101010` or hexadecimal notation[^hex] `0xdeadbeef`. There are no signed integers. @@ -103,8 +103,8 @@ Arrays are always of finite length. | `ListN`>` | <2N-list | `list![]`, …, `list![a1, …, a`(2N - 1)`]` | Lists hold a variable number of elements of the same type. -This is similar to [Rust vectors](https://doc.rust-lang.org/std/vec/struct.Vec.html), but Simfony doesn't have a heap. -In Simfony, lists exists on the stack, which is why the maximum list length is bounded. +This is similar to [Rust vectors](https://doc.rust-lang.org/std/vec/struct.Vec.html), but SimplicityHL doesn't have a heap. +In SimplicityHL, lists exists on the stack, which is why the maximum list length is bounded. <2-lists hold fewer than 2 elements, so zero or one element. <4-lists hold fewer than 4 elements, so zero to three elements. diff --git a/book/src/type_alias.md b/book/src/type_alias.md index 0387483..5f23423 100644 --- a/book/src/type_alias.md +++ b/book/src/type_alias.md @@ -1,6 +1,6 @@ # Type Aliases -Simfony currently doesn't support Rust-like `struct`s for organizing data. +SimplicityHL currently doesn't support Rust-like `struct`s for organizing data. ```rust struct User { @@ -10,7 +10,7 @@ struct User { } ``` -Simfony programmers have to handle long tuples of unlabeled data, which can get messy. +SimplicityHL programmers have to handle long tuples of unlabeled data, which can get messy. ```rust (bool, u256, u64) diff --git a/book/src/type_casting.md b/book/src/type_casting.md index aabcf77..eb4d2e9 100644 --- a/book/src/type_casting.md +++ b/book/src/type_casting.md @@ -1,6 +1,6 @@ # Casting -A Simfony type can be cast into another Simfony type if both types share the same structure. +A SimplicityHL type can be cast into another SimplicityHL type if both types share the same structure. The structure of a type has to do with how the type is implemented on the Simplicity "processor". I will spare you the boring details. @@ -50,7 +50,7 @@ If type `A` can be cast into type `B` and type `B` can be cast into type `C`, th ## Casting Expression -All casting in Simfony happens explicitly through a casting expression. +All casting in SimplicityHL happens explicitly through a casting expression. ```rust ::into(input) @@ -59,7 +59,7 @@ All casting in Simfony happens explicitly through a casting expression. The above expression casts the value `input` of type `Input` into some output type. The input type of the cast is explict while the output type is implicit. -In Simfony, the output type of every expression is known. +In SimplicityHL, the output type of every expression is known. ```rust let x: u32 = 1; @@ -69,7 +69,7 @@ In the above example, the meaning of the expression `1` is clear because of the Here, `1` means a string of 31 zeroes and 1 one. _In other contexts, `1` could mean something different, like a string of 255 zeroes and 1 one._ -The Simfony compiler knows the type of the outermost expression, and it tries to infer the types of inner expressions based on that. +The SimplicityHL compiler knows the type of the outermost expression, and it tries to infer the types of inner expressions based on that. When it comes to casting expressions, the compiler has no idea about the input type of the cast. The programmer needs to supply this information by annotating the cast with its input type. diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 6d2bd4d..952f32d 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -2,8 +2,8 @@ name = "codegen" version = "0.1.0" edition = "2021" -description = "Generator of Rust code as interface between Simfony and Rust." +description = "Generator of Rust code as interface between SimplicityHL and Rust." publish = false [dependencies] -simfony = { path = ".." } +simplicityhl = { path = ".." } diff --git a/codegen/src/jet.rs b/codegen/src/jet.rs index a862492..c90b74e 100644 --- a/codegen/src/jet.rs +++ b/codegen/src/jet.rs @@ -1,4 +1,4 @@ -use simfony::simplicity::jet::Elements; +use simplicityhl::simplicity::jet::Elements; use std::fmt; #[rustfmt::skip] diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 89fb04f..3b38418 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -1,12 +1,12 @@ use std::fs::File; use std::io; -use simfony::simplicity::jet::{Elements, Jet}; -use simfony::types::TypeDeconstructible; +use simplicityhl::simplicity::jet::{Elements, Jet}; +use simplicityhl::types::TypeDeconstructible; mod jet; -/// Write a Simfony jet as a Rust function to the sink. +/// Write a SimplicityHL jet as a Rust function to the sink. fn write_jet(jet: Elements, w: &mut W) -> io::Result<()> { for line in jet::documentation(jet).lines() { match line.is_empty() { @@ -19,7 +19,7 @@ fn write_jet(jet: Elements, w: &mut W) -> io::Result<()> { writeln!(w, "///")?; writeln!(w, "/// {} mWU _(milli weight units)_", jet.cost())?; write!(w, "pub fn {jet}(")?; - let parameters = simfony::jet::source_type(jet); + let parameters = simplicityhl::jet::source_type(jet); for (i, ty) in parameters.iter().enumerate() { let identifier = (b'a' + i as u8) as char; if i == parameters.len() - 1 { @@ -28,10 +28,10 @@ fn write_jet(jet: Elements, w: &mut W) -> io::Result<()> { write!(w, "{identifier}: {ty}, ")?; } } - let target = simfony::jet::target_type(jet); + let target = simplicityhl::jet::target_type(jet); match target.is_unit() { true => writeln!(w, ") {{")?, - false => writeln!(w, ") -> {} {{", simfony::jet::target_type(jet))?, + false => writeln!(w, ") -> {} {{", simplicityhl::jet::target_type(jet))?, } writeln!(w, " todo!()")?; diff --git a/doc/context.md b/doc/context.md index 3cd81ec..2159a8b 100644 --- a/doc/context.md +++ b/doc/context.md @@ -6,7 +6,7 @@ A context Γ maps variable names to Simplicity types: We write Γ(`v`) = A to denote that variable `v` has type A in context Γ. -We handle free variables inside Simfony expressions via contexts. +We handle free variables inside SimplicityHL expressions via contexts. If all free variables are defined in a context, then the context assigns a type to the expression. @@ -14,7 +14,7 @@ We write Γ ⊩ `a`: A to denote that expression `a` has type A in context Γ. Note that contexts handle only the **target type** of an expression! -Source types are handled by environments and the translation of Simfony to Simplicity. +Source types are handled by environments and the translation of SimplicityHL to Simplicity. We write Γ ⊎ Δ to denote the **disjoint union** of Γ and Δ. diff --git a/doc/environment.md b/doc/environment.md index 4ff6e2d..3c72cb9 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -12,13 +12,13 @@ All expressions inside an environment share the same source type A. We say the e ] ``` -We use environments to translate variables inside Simfony expressions to Simplicity. +We use environments to translate variables inside SimplicityHL expressions to Simplicity. The environment tells us the Simplicity expression that returns the value of each variable. -We translate a Simfony program "top to bottom". Each time a variable is defined, we update the environment to reflect this change. +We translate a SimplicityHL program "top to bottom". Each time a variable is defined, we update the environment to reflect this change. -During the translation, we can ignore the source type of Simplicity expressions (translated Simfony expressions) entirely. We can focus on producing a Simplicity value of the expected target type. Environments ensure that we get input values for each variable that is in scope. +During the translation, we can ignore the source type of Simplicity expressions (translated SimplicityHL expressions) entirely. We can focus on producing a Simplicity value of the expected target type. Environments ensure that we get input values for each variable that is in scope. Target types are handled by contexts. @@ -31,7 +31,7 @@ Ctx(Ξ)(`x`) = B if Ξ(`x`) = a: A → B Patterns occur in let statements `let p := s`. -Pattern `p` binds the output of Simfony expression `s` to variables. +Pattern `p` binds the output of SimplicityHL expression `s` to variables. As we translate `s` to Simplicity, we need an environment that maps the variables from `p` to Simplicity expressions. diff --git a/doc/translation.md b/doc/translation.md index 0a28393..077228e 100644 --- a/doc/translation.md +++ b/doc/translation.md @@ -1,10 +1,10 @@ # Translation -We write ⟦`e`⟧Ξ to denote the translation of Simfony expression `e` using environment Ξ from A. +We write ⟦`e`⟧Ξ to denote the translation of SimplicityHL expression `e` using environment Ξ from A. The translation produces a Simplicity expression with source type A. -The target type depends on the Simfony expression `e`. +The target type depends on the SimplicityHL expression `e`. ## Unit literal diff --git a/flake.nix b/flake.nix index c6e1b90..ff26d4a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Simfony"; + description = "SimplicityHL"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 3815e0a..e70be25 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "simfony-fuzz" +name = "simplicityhl-fuzz" version = "0.0.0" publish = false edition = "2021" @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" arbitrary = { version = "1", features = ["derive"] } -simfony = { path = "..", features = ["arbitrary", "serde"]} +simplicityhl = { path = "..", features = ["arbitrary", "serde"] } itertools = "0.13.0" serde_json = "1.0.105" diff --git a/fuzz/fuzz_targets/compile_parse_tree.rs b/fuzz/fuzz_targets/compile_parse_tree.rs index 718d055..05014f1 100644 --- a/fuzz/fuzz_targets/compile_parse_tree.rs +++ b/fuzz/fuzz_targets/compile_parse_tree.rs @@ -3,8 +3,8 @@ use arbitrary::Arbitrary; use libfuzzer_sys::fuzz_target; -use simfony::error::WithFile; -use simfony::{ast, named, parse, ArbitraryOfType, Arguments}; +use simplicityhl::error::WithFile; +use simplicityhl::{ast, named, parse, ArbitraryOfType, Arguments}; fuzz_target!(|data: &[u8]| { let mut u = arbitrary::Unstructured::new(data); diff --git a/fuzz/fuzz_targets/compile_text.rs b/fuzz/fuzz_targets/compile_text.rs index 5c0776d..ea2ff34 100644 --- a/fuzz/fuzz_targets/compile_text.rs +++ b/fuzz/fuzz_targets/compile_text.rs @@ -3,7 +3,7 @@ use arbitrary::Arbitrary; use libfuzzer_sys::{fuzz_target, Corpus}; -use simfony::{ArbitraryOfType, Arguments}; +use simplicityhl::{ArbitraryOfType, Arguments}; /// The PEST parser is slow for inputs with many open brackets. /// Detect some of these inputs to reject them from the corpus. @@ -38,7 +38,7 @@ fuzz_target!(|data: &[u8]| -> Corpus { if slow_input(&program_text) { return Corpus::Reject; } - let template = match simfony::TemplateProgram::new(program_text) { + let template = match simplicityhl::TemplateProgram::new(program_text) { Ok(x) => x, Err(..) => return Corpus::Keep, }; diff --git a/fuzz/fuzz_targets/display_parse_tree.rs b/fuzz/fuzz_targets/display_parse_tree.rs index 40d7ab7..064952a 100644 --- a/fuzz/fuzz_targets/display_parse_tree.rs +++ b/fuzz/fuzz_targets/display_parse_tree.rs @@ -2,7 +2,7 @@ use libfuzzer_sys::fuzz_target; -use simfony::parse::{self, ParseFromStr}; +use simplicityhl::parse::{self, ParseFromStr}; fuzz_target!(|parse_program: parse::Program| { let program_text = parse_program.to_string(); diff --git a/fuzz/fuzz_targets/parse_value_rtt.rs b/fuzz/fuzz_targets/parse_value_rtt.rs index f3a1767..fdb835c 100644 --- a/fuzz/fuzz_targets/parse_value_rtt.rs +++ b/fuzz/fuzz_targets/parse_value_rtt.rs @@ -2,7 +2,7 @@ use libfuzzer_sys::fuzz_target; -use simfony::value::Value; +use simplicityhl::value::Value; fuzz_target!(|value: Value| { let value_string = value.to_string(); diff --git a/fuzz/fuzz_targets/parse_witness_json_rtt.rs b/fuzz/fuzz_targets/parse_witness_json_rtt.rs index 8d71ca4..b371c61 100644 --- a/fuzz/fuzz_targets/parse_witness_json_rtt.rs +++ b/fuzz/fuzz_targets/parse_witness_json_rtt.rs @@ -2,7 +2,7 @@ use libfuzzer_sys::fuzz_target; -use simfony::WitnessValues; +use simplicityhl::WitnessValues; fuzz_target!(|witness_values: WitnessValues| { let witness_text = serde_json::to_string(&witness_values) diff --git a/fuzz/fuzz_targets/parse_witness_module_rtt.rs b/fuzz/fuzz_targets/parse_witness_module_rtt.rs index acdaa1e..ac5f645 100644 --- a/fuzz/fuzz_targets/parse_witness_module_rtt.rs +++ b/fuzz/fuzz_targets/parse_witness_module_rtt.rs @@ -2,8 +2,8 @@ use libfuzzer_sys::fuzz_target; -use simfony::parse::ParseFromStr; -use simfony::WitnessValues; +use simplicityhl::parse::ParseFromStr; +use simplicityhl::WitnessValues; fuzz_target!(|witness_values: WitnessValues| { let witness_text = witness_values.to_string(); diff --git a/fuzz/fuzz_targets/reconstruct_value.rs b/fuzz/fuzz_targets/reconstruct_value.rs index fc11dc8..d17abd6 100644 --- a/fuzz/fuzz_targets/reconstruct_value.rs +++ b/fuzz/fuzz_targets/reconstruct_value.rs @@ -2,7 +2,7 @@ use libfuzzer_sys::fuzz_target; -use simfony::value::{StructuralValue, Value}; +use simplicityhl::value::{StructuralValue, Value}; fuzz_target!(|value: Value| { let structural_value = StructuralValue::from(&value); diff --git a/src/ast.rs b/src/ast.rs index 8c08722..596555d 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -830,7 +830,7 @@ impl Expression { /// ## Const evaluation /// /// The returned expression might not be evaluable at compile time. - /// The details depend on the current state of the Simfony compiler. + /// The details depend on the current state of the SimplicityHL compiler. pub fn analyze_const(from: &parse::Expression, ty: &ResolvedType) -> Result { let mut empty_scope = Scope::default(); Self::analyze(from, ty, &mut empty_scope) diff --git a/src/compile.rs b/src/compile.rs index 01a1dc4..741cf85 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -23,11 +23,11 @@ use crate::value::StructuralValue; use crate::witness::Arguments; use crate::{ProgNode, Value}; -/// Each Simfony expression expects an _input value_. -/// A Simfony expression is translated into a Simplicity expression +/// Each SimplicityHL expression expects an _input value_. +/// A SimplicityHL expression is translated into a Simplicity expression /// that similarly expects an _input value_. /// -/// Simfony variable names are translated into Simplicity expressions +/// SimplicityHL variable names are translated into Simplicity expressions /// that extract the seeked value from the _input value_. /// /// Each (nested) block expression introduces a new scope. @@ -64,7 +64,7 @@ struct Scope { ctx: simplicity::types::Context, /// Tracker of function calls. call_tracker: Arc, - /// Values for parameters inside the Simfony program. + /// Values for parameters inside the SimplicityHL program. arguments: Arguments, include_debug_symbols: bool, } @@ -247,7 +247,7 @@ fn compile_blk( } impl Program { - /// Compile the Simfony source code to Simplicity target code. + /// Compile the SimplicityHL source code to Simplicity target code. /// /// ## Precondition /// @@ -402,9 +402,9 @@ impl Call { } CallName::TypeCast(..) => { // A cast converts between two structurally equal types. - // Structural equality of Simfony types A and B means + // Structural equality of SimplicityHL types A and B means // exact equality of the underlying Simplicity types of A and of B. - // Therefore, a Simfony cast is a NOP in Simplicity. + // Therefore, a SimplicityHL cast is a NOP in Simplicity. Ok(args) } CallName::Custom(function) => { diff --git a/src/debug.rs b/src/debug.rs index a5529dd..610e0b1 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -9,13 +9,13 @@ use crate::error::Span; use crate::types::ResolvedType; use crate::value::{StructuralValue, Value}; -/// Tracker of Simfony call expressions inside Simplicity target code. +/// Tracker of SimplicityHL call expressions inside Simplicity target code. /// /// Tracking happens via CMRs that are inserted into the Simplicity target code. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct DebugSymbols(HashMap); -/// Intermediate representation of tracked Simfony call expressions +/// Intermediate representation of tracked SimplicityHL call expressions /// that is mutable and that lacks information about the source file. /// /// The struct can be converted to [`DebugSymbols`] by providing the source file. @@ -71,7 +71,7 @@ pub struct DebugValue { impl DebugSymbols { /// Insert a tracked call expression. - /// Use the Simfony source `file` to extract the Simfony text of the expression. + /// Use the SimplicityHL source `file` to extract the SimplicityHL text of the expression. pub(crate) fn insert(&mut self, span: Span, cmr: Cmr, name: TrackedCallName, file: &str) { let text = remove_excess_whitespace(span.to_slice(file).unwrap_or("")); let text = text @@ -152,7 +152,7 @@ impl CallTracker { } impl TrackedCall { - /// Access the text of the Simfony call expression. + /// Access the text of the SimplicityHL call expression. pub fn text(&self) -> &str { &self.text } @@ -197,7 +197,7 @@ impl TrackedCall { } impl FallibleCall { - /// Access the Simfony text of the call expression. + /// Access the SimplicityHL text of the call expression. pub fn text(&self) -> &str { &self.text } @@ -209,7 +209,7 @@ impl FallibleCall { } impl DebugValue { - /// Access the Simfony text of the debug expression. + /// Access the SimplicityHL text of the debug expression. pub fn text(&self) -> &str { &self.text } diff --git a/src/error.rs b/src/error.rs index 5a7c885..b4b35a3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -301,8 +301,8 @@ pub enum Error { CannotParse(String), Grammar(String), IncompatibleMatchArms(MatchPattern, MatchPattern), - // TODO: Remove CompileError once Simfony has a type system - // The Simfony compiler should never produce ill-typed Simplicity code + // TODO: Remove CompileError once SimplicityHL has a type system + // The SimplicityHL compiler should never produce ill-typed Simplicity code // The compiler can only be this precise if it knows a type system at least as expressive as Simplicity's CannotCompile(String), JetDoesNotExist(JetName), diff --git a/src/lib.rs b/src/lib.rs index bdb0bf3..efe6b34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! Library for parsing and compiling simfony +//! Library for parsing and compiling SimplicityHL pub type ProgNode = Arc; @@ -36,7 +36,7 @@ pub use crate::types::ResolvedType; pub use crate::value::Value; pub use crate::witness::{Arguments, Parameters, WitnessTypes, WitnessValues}; -/// The template of a Simfony program. +/// The template of a SimplicityHL program. /// /// A template has parameterized values that need to be supplied with arguments. #[derive(Clone, Debug, PartialEq, Eq)] @@ -46,11 +46,11 @@ pub struct TemplateProgram { } impl TemplateProgram { - /// Parse the template of a Simfony program. + /// Parse the template of a SimplicityHL program. /// /// ## Errors /// - /// The string is not a valid Simfony program. + /// The string is not a valid SimplicityHL program. pub fn new>>(s: Str) -> Result { let file = s.into(); let parse_program = parse::Program::parse_from_str(&file)?; @@ -91,7 +91,7 @@ impl TemplateProgram { } } -/// A Simfony program, compiled to Simplicity. +/// A SimplicityHL program, compiled to Simplicity. #[derive(Clone, Debug)] pub struct CompiledProgram { simplicity: ProgNode, @@ -111,7 +111,7 @@ impl Default for CompiledProgram { } impl CompiledProgram { - /// Parse and compile a Simfony program from the given string. + /// Parse and compile a SimplicityHL program from the given string. /// /// ## See /// @@ -133,25 +133,25 @@ impl CompiledProgram { /// Access the Simplicity target code, without witness data. pub fn commit(&self) -> Arc> { - named::to_commit_node(&self.simplicity).expect("Compiled Simfony program has type 1 -> 1") + named::to_commit_node(&self.simplicity).expect("Compiled SimplicityHL program has type 1 -> 1") } - /// Satisfy the Simfony program with the given `witness_values`. + /// Satisfy the SimplicityHL program with the given `witness_values`. /// /// ## Errors /// - /// - Witness values have a different type than declared in the Simfony program. + /// - Witness values have a different type than declared in the SimplicityHL program. /// - There are missing witness values. pub fn satisfy(&self, witness_values: WitnessValues) -> Result { self.satisfy_with_env(witness_values, None) } - /// Satisfy the Simfony program with the given `witness_values`. + /// Satisfy the SimplicityHL program with the given `witness_values`. /// If `env` is `None`, the program is not pruned, otherwise it is pruned with the given environment. /// /// ## Errors /// - /// - Witness values have a different type than declared in the Simfony program. + /// - Witness values have a different type than declared in the SimplicityHL program. /// - There are missing witness values. pub fn satisfy_with_env( &self, @@ -173,7 +173,7 @@ impl CompiledProgram { } } -/// A Simfony program, compiled to Simplicity and satisfied with witness data. +/// A SimplicityHL program, compiled to Simplicity and satisfied with witness data. #[derive(Clone, Debug, PartialEq, Eq)] pub struct SatisfiedProgram { simplicity: Arc>, @@ -181,7 +181,7 @@ pub struct SatisfiedProgram { } impl SatisfiedProgram { - /// Parse, compile and satisfy a Simfony program from the given string. + /// Parse, compile and satisfy a SimplicityHL program from the given string. /// /// ## See /// diff --git a/src/main.rs b/src/main.rs index a5f24ad..4f029c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use base64::display::Base64Display; use base64::engine::general_purpose::STANDARD; use clap::{Arg, ArgAction, Command}; -use simfony::{Arguments, CompiledProgram}; +use simplicityhl::{Arguments, CompiledProgram}; use std::env; // Directly returning Result<(), String> prints the error using Debug @@ -19,8 +19,8 @@ fn run() -> Result<(), String> { Command::new(env!("CARGO_BIN_NAME")) .about( "\ - Compile the given Simfony program and print the resulting Simplicity base64 string.\n\ - If a Simfony witness is provided, then use it to satisfy the program (requires \ + Compile the given SimplicityHL program and print the resulting Simplicity base64 string.\n\ + If a SimplicityHL witness is provided, then use it to satisfy the program (requires \ feature 'serde' to be enabled).\ ", ) @@ -29,7 +29,7 @@ fn run() -> Result<(), String> { .required(true) .value_name("PROGRAM_FILE") .action(ArgAction::Set) - .help("Simfony program file to build"), + .help("SimplicityHL program file to build"), ) }; @@ -65,16 +65,16 @@ fn run() -> Result<(), String> { let witness_opt = { matches .get_one::("wit_file") - .map(|wit_file| -> Result { + .map(|wit_file| -> Result { let wit_path = std::path::Path::new(wit_file); let wit_text = std::fs::read_to_string(wit_path).map_err(|e| e.to_string())?; - let witness = serde_json::from_str::(&wit_text).unwrap(); + let witness = serde_json::from_str::(&wit_text).unwrap(); Ok(witness) }) .transpose()? }; #[cfg(not(feature = "serde"))] - let witness_opt: Option = None; + let witness_opt: Option = None; if let Some(witness) = witness_opt { let satisfied = compiled.satisfy(witness)?; diff --git a/src/named.rs b/src/named.rs index 1a028d5..4a50ab9 100644 --- a/src/named.rs +++ b/src/named.rs @@ -98,7 +98,7 @@ pub fn to_commit_node(node: &ConstructNode) -> Result>, /// /// It is the responsibility of the caller to ensure that the given witness `values` match the /// types in the construct `node`. This can be done by calling [`WitnessValues::is_consistent`] -/// on the original Simfony program before it is compiled to Simplicity. +/// on the original SimplicityHL program before it is compiled to Simplicity. pub fn to_witness_node(node: &ConstructNode, values: WitnessValues) -> Arc> { struct Populator { values: WitnessValues, diff --git a/src/pattern.rs b/src/pattern.rs index d88e4df..518c50b 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -157,7 +157,7 @@ impl crate::ArbitraryRec for Pattern { } } -/// Basic structure of a Simfony value for pattern matching. +/// Basic structure of a SimplicityHL value for pattern matching. #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum BasePattern { /// Ignore: Match any value. diff --git a/src/types.rs b/src/types.rs index 22f5bf0..c5dc5a7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -9,7 +9,7 @@ use crate::array::{BTreeSlice, Partition}; use crate::num::{NonZeroPow2Usize, Pow2Usize}; use crate::str::AliasName; -/// Primitives of the Simfony type system, excluding type aliases. +/// Primitives of the SimplicityHL type system, excluding type aliases. #[derive(Debug, PartialEq, Eq, Hash, Clone)] #[non_exhaustive] pub enum TypeInner { @@ -315,7 +315,7 @@ pub trait TypeDeconstructible: Sized { fn as_list(&self) -> Option<(&Self, NonZeroPow2Usize)>; } -/// Simfony type without type aliases. +/// SimplicityHL type without type aliases. #[derive(PartialEq, Eq, Hash, Clone)] pub struct ResolvedType(TypeInner>); @@ -484,7 +484,7 @@ impl<'a> arbitrary::Arbitrary<'a> for ResolvedType { } } -/// Simfony type with type aliases. +/// SimplicityHL type with type aliases. #[derive(PartialEq, Eq, Hash, Clone)] pub struct AliasedType(AliasedInner); @@ -911,7 +911,7 @@ impl FromStr for BuiltinAlias { } } -/// Internal structure of a Simfony type. +/// Internal structure of a SimplicityHL type. /// 1:1 isomorphism to Simplicity. #[derive(Clone, PartialEq, Eq, Hash)] pub struct StructuralType(Arc); diff --git a/src/value.rs b/src/value.rs index ccedc8a..1ae5001 100644 --- a/src/value.rs +++ b/src/value.rs @@ -362,7 +362,7 @@ pub trait ValueConstructible: Sized + From + From { construct_int!(u256, U256, "a 256-bit"); } -/// The structure of a Simfony value. +/// The structure of a SimplicityHL value. #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub enum ValueInner { /// Left value. @@ -388,7 +388,7 @@ pub enum ValueInner { List(Arc<[Value]>, NonZeroPow2Usize), } -/// A Simfony value. +/// A SimplicityHL value. #[derive(Clone, Eq, PartialEq, Hash)] pub struct Value { inner: ValueInner, @@ -528,10 +528,7 @@ impl ValueConstructible for Value { } fn none(inner: Self::Type) -> Self { - Self { - inner: ValueInner::Option(None), - ty: ResolvedType::option(inner), - } + Self { inner: ValueInner::Option(None), ty: ResolvedType::option(inner) } } fn some(inner: Self) -> Self { @@ -544,24 +541,15 @@ impl ValueConstructible for Value { fn tuple>(elements: I) -> Self { let values: Arc<[Self]> = elements.into_iter().collect(); let ty = ResolvedType::tuple(values.iter().map(Value::ty).map(ResolvedType::clone)); - Self { - inner: ValueInner::Tuple(values), - ty, - } + Self { inner: ValueInner::Tuple(values), ty } } fn array>(elements: I, ty: Self::Type) -> Self { let values: Arc<[Self]> = elements.into_iter().collect(); for value in values.iter() { - assert!( - value.is_of_type(&ty), - "Element {value} is not of expected type {ty}" - ); - } - Self { - ty: ResolvedType::array(ty, values.len()), - inner: ValueInner::Array(values), + assert!(value.is_of_type(&ty), "Element {value} is not of expected type {ty}"); } + Self { ty: ResolvedType::array(ty, values.len()), inner: ValueInner::Array(values) } } fn list>( @@ -575,33 +563,21 @@ impl ValueConstructible for Value { "There must be fewer list elements than the bound {bound}" ); for element in elements.iter() { - assert!( - element.is_of_type(&ty), - "Element {element} is not of expected type {ty}" - ); - } - Self { - inner: ValueInner::List(elements, bound), - ty: ResolvedType::list(ty, bound), + assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); } + Self { inner: ValueInner::List(elements, bound), ty: ResolvedType::list(ty, bound) } } } impl From for Value { fn from(value: bool) -> Self { - Self { - inner: ValueInner::Boolean(value), - ty: ResolvedType::boolean(), - } + Self { inner: ValueInner::Boolean(value), ty: ResolvedType::boolean() } } } impl From for Value { fn from(value: UIntValue) -> Self { - Self { - ty: value.get_type().into(), - inner: ValueInner::UInt(value), - } + Self { ty: value.get_type().into(), inner: ValueInner::UInt(value) } } } @@ -850,7 +826,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Value { } } -/// Structure of a Simfony value. +/// Structure of a SimplicityHL value. /// 1:1 isomorphism to Simplicity. #[derive(Clone, Eq, PartialEq, Hash)] pub struct StructuralValue(SimValue); @@ -935,10 +911,7 @@ impl ValueConstructible for StructuralValue { fn array>(elements: I, ty: Self::Type) -> Self { let elements: Vec = elements.into_iter().collect(); for element in &elements { - assert!( - element.is_of_type(&ty), - "Element {element} is not of expected type {ty}" - ); + assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); } let tree = BTreeSlice::from_slice(&elements); tree.fold(Self::product).unwrap_or_else(Self::unit) @@ -955,10 +928,7 @@ impl ValueConstructible for StructuralValue { "There must be fewer list elements than the bound {bound}" ); for element in &elements { - assert!( - element.is_of_type(&ty), - "Element {element} is not of expected type {ty}" - ); + assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); } let partition = Partition::from_slice(&elements, bound); let process = |block: &[Self], size: usize| -> Self { @@ -1058,50 +1028,44 @@ impl StructuralValue { } fn destruct<'a>(&'a self, ty: &'a ResolvedType) -> Destructor<'a> { - Destructor::Ok { - value: self.0.as_ref(), - ty, - } + Destructor::Ok { value: self.0.as_ref(), ty } } } -/// An iterator over the contents of a Simplicity value in terms of a Simfony type. +/// An iterator over the contents of a Simplicity value in terms of a SimplicityHL type. /// /// ## Examples /// -/// A Simfony array is a nested Simplicity product. +/// A SimplicityHL array is a nested Simplicity product. /// The destructor allows simple iteration over all array elements. /// -/// A Simfony list is a nested Simplicity product _(partition)_ +/// A SimplicityHL list is a nested Simplicity product _(partition)_ /// of options of more products _(blocks)_. /// The destructor allows simple iteration over all list elements. /// /// ## Lazy type checking /// -/// The destructor creates a tree of Simplicity value-Simfony type pairs. -/// The Simfony type dictates whether the node has children. +/// The destructor creates a tree of Simplicity value-SimplicityHL type pairs. +/// The SimplicityHL type dictates whether the node has children. /// Parent nodes are type-checked. Leaf nodes are not type-checked. /// /// The destructor tries to destruct the Simplicity value into child values. /// If destructing fails, then a single `Destructor::WrongType` leaf is created instead. /// This leaf signifies that the entire tree is ill-typed and that the original Simplicity value -/// was not of the given Simfony type.`Destructor::WrongType` leaves, if there are any, +/// was not of the given SimplicityHL type.`Destructor::WrongType` leaves, if there are any, /// should appear early during post-order iteration, enabling early termination. /// /// The leaf values (Boolean, unsigned integer, empty tuple, empty array) are not checked. -/// Extraction of actual Simfony values (Boolean, unsigned integer, ...) +/// Extraction of actual SimplicityHL values (Boolean, unsigned integer, ...) /// from the leaf Simplicity values may fail, in which case the entire tree is, again, ill-typed. #[derive(Clone, Debug)] enum Destructor<'a> { - Ok { - value: ValueRef<'a>, - ty: &'a ResolvedType, - }, + Ok { value: ValueRef<'a>, ty: &'a ResolvedType }, WrongType, } impl<'a> Destructor<'a> { - /// Create a destructor for the given Simplicity `value` and the given Simfony type. + /// Create a destructor for the given Simplicity `value` and the given SimplicityHL type. pub const fn new(value: ValueRef<'a>, ty: &'a ResolvedType) -> Self { Self::Ok { value, ty } } @@ -1163,7 +1127,7 @@ impl TreeLike for Destructor<'_> { } } -/// Functions for destructing Simplicity values alongside Simfony types. +/// Functions for destructing Simplicity values alongside SimplicityHL types. mod destruct { use super::*; use simplicity::ValueRef; @@ -1247,10 +1211,8 @@ mod tests { assert_eq!("(1, 42, 1337)", &triple.to_string()); let empty_array = Value::array([], ResolvedType::unit()); assert_eq!("[]", &empty_array.to_string()); - let array = Value::array( - [Value::unit(), Value::unit(), Value::unit()], - ResolvedType::unit(), - ); + let array = + Value::array([Value::unit(), Value::unit(), Value::unit()], ResolvedType::unit()); assert_eq!("[(), (), ()]", &array.to_string()); let list = Value::list([Value::unit()], ResolvedType::unit(), NonZeroPow2Usize::TWO); assert_eq!("list![()]", &list.to_string()); @@ -1299,10 +1261,7 @@ mod tests { ( "[1, 2, 3]", ResolvedType::array(UIntType::U4.into(), 3), - Value::array( - [Value::u4(1), Value::u4(2), Value::u4(3)], - UIntType::U4.into(), - ), + Value::array([Value::u4(1), Value::u4(2), Value::u4(3)], UIntType::U4.into()), ), ( "list![1, 2, 3]", diff --git a/vscode/LICENSE b/vscode/LICENSE index 50cdf4c..b12a53e 100644 --- a/vscode/LICENSE +++ b/vscode/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Simfony contributors +Copyright (c) 2025 SimplicityHL contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vscode/README.md b/vscode/README.md index e698b2e..ec2cf3c 100644 --- a/vscode/README.md +++ b/vscode/README.md @@ -1,4 +1,4 @@ -# SimplicityHL (Simfony) extension for VSCode +# SimplicityHL extension for VSCode VSCode extension that provides syntax highlighting for the [SimplicityHL](https://github.com/BlockstreamResearch/SimplicityHL) programming language. diff --git a/vscode/package.json b/vscode/package.json index 6b6dc56..a13c36d 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -1,8 +1,8 @@ { "name": "simplicityhl", - "displayName": "SimplicityHL (Simfony) Language Support", + "displayName": "SimplicityHL Language Support", "description": "Syntax highlighting and autocompletion for SimplicityHL (Simfony) language", - "version": "0.1.0", + "version": "0.1.1", "publisher": "Simplicity", "repository": { "type": "git", From 4493b607788a85ab4042d1c603299a93a2cca3ed Mon Sep 17 00:00:00 2001 From: Simon Tennant Date: Mon, 28 Jul 2025 21:54:02 +0200 Subject: [PATCH 3/3] fix: code formatting --- src/lib.rs | 3 ++- src/main.rs | 3 ++- src/value.rs | 71 +++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index efe6b34..d95a55a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,7 +133,8 @@ impl CompiledProgram { /// Access the Simplicity target code, without witness data. pub fn commit(&self) -> Arc> { - named::to_commit_node(&self.simplicity).expect("Compiled SimplicityHL program has type 1 -> 1") + named::to_commit_node(&self.simplicity) + .expect("Compiled SimplicityHL program has type 1 -> 1") } /// Satisfy the SimplicityHL program with the given `witness_values`. diff --git a/src/main.rs b/src/main.rs index 4f029c2..74d3c8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,8 @@ fn run() -> Result<(), String> { .map(|wit_file| -> Result { let wit_path = std::path::Path::new(wit_file); let wit_text = std::fs::read_to_string(wit_path).map_err(|e| e.to_string())?; - let witness = serde_json::from_str::(&wit_text).unwrap(); + let witness = + serde_json::from_str::(&wit_text).unwrap(); Ok(witness) }) .transpose()? diff --git a/src/value.rs b/src/value.rs index 1ae5001..0542af9 100644 --- a/src/value.rs +++ b/src/value.rs @@ -528,7 +528,10 @@ impl ValueConstructible for Value { } fn none(inner: Self::Type) -> Self { - Self { inner: ValueInner::Option(None), ty: ResolvedType::option(inner) } + Self { + inner: ValueInner::Option(None), + ty: ResolvedType::option(inner), + } } fn some(inner: Self) -> Self { @@ -541,15 +544,24 @@ impl ValueConstructible for Value { fn tuple>(elements: I) -> Self { let values: Arc<[Self]> = elements.into_iter().collect(); let ty = ResolvedType::tuple(values.iter().map(Value::ty).map(ResolvedType::clone)); - Self { inner: ValueInner::Tuple(values), ty } + Self { + inner: ValueInner::Tuple(values), + ty, + } } fn array>(elements: I, ty: Self::Type) -> Self { let values: Arc<[Self]> = elements.into_iter().collect(); for value in values.iter() { - assert!(value.is_of_type(&ty), "Element {value} is not of expected type {ty}"); + assert!( + value.is_of_type(&ty), + "Element {value} is not of expected type {ty}" + ); + } + Self { + ty: ResolvedType::array(ty, values.len()), + inner: ValueInner::Array(values), } - Self { ty: ResolvedType::array(ty, values.len()), inner: ValueInner::Array(values) } } fn list>( @@ -563,21 +575,33 @@ impl ValueConstructible for Value { "There must be fewer list elements than the bound {bound}" ); for element in elements.iter() { - assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); + assert!( + element.is_of_type(&ty), + "Element {element} is not of expected type {ty}" + ); + } + Self { + inner: ValueInner::List(elements, bound), + ty: ResolvedType::list(ty, bound), } - Self { inner: ValueInner::List(elements, bound), ty: ResolvedType::list(ty, bound) } } } impl From for Value { fn from(value: bool) -> Self { - Self { inner: ValueInner::Boolean(value), ty: ResolvedType::boolean() } + Self { + inner: ValueInner::Boolean(value), + ty: ResolvedType::boolean(), + } } } impl From for Value { fn from(value: UIntValue) -> Self { - Self { ty: value.get_type().into(), inner: ValueInner::UInt(value) } + Self { + ty: value.get_type().into(), + inner: ValueInner::UInt(value), + } } } @@ -911,7 +935,10 @@ impl ValueConstructible for StructuralValue { fn array>(elements: I, ty: Self::Type) -> Self { let elements: Vec = elements.into_iter().collect(); for element in &elements { - assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); + assert!( + element.is_of_type(&ty), + "Element {element} is not of expected type {ty}" + ); } let tree = BTreeSlice::from_slice(&elements); tree.fold(Self::product).unwrap_or_else(Self::unit) @@ -928,7 +955,10 @@ impl ValueConstructible for StructuralValue { "There must be fewer list elements than the bound {bound}" ); for element in &elements { - assert!(element.is_of_type(&ty), "Element {element} is not of expected type {ty}"); + assert!( + element.is_of_type(&ty), + "Element {element} is not of expected type {ty}" + ); } let partition = Partition::from_slice(&elements, bound); let process = |block: &[Self], size: usize| -> Self { @@ -1028,7 +1058,10 @@ impl StructuralValue { } fn destruct<'a>(&'a self, ty: &'a ResolvedType) -> Destructor<'a> { - Destructor::Ok { value: self.0.as_ref(), ty } + Destructor::Ok { + value: self.0.as_ref(), + ty, + } } } @@ -1060,7 +1093,10 @@ impl StructuralValue { /// from the leaf Simplicity values may fail, in which case the entire tree is, again, ill-typed. #[derive(Clone, Debug)] enum Destructor<'a> { - Ok { value: ValueRef<'a>, ty: &'a ResolvedType }, + Ok { + value: ValueRef<'a>, + ty: &'a ResolvedType, + }, WrongType, } @@ -1211,8 +1247,10 @@ mod tests { assert_eq!("(1, 42, 1337)", &triple.to_string()); let empty_array = Value::array([], ResolvedType::unit()); assert_eq!("[]", &empty_array.to_string()); - let array = - Value::array([Value::unit(), Value::unit(), Value::unit()], ResolvedType::unit()); + let array = Value::array( + [Value::unit(), Value::unit(), Value::unit()], + ResolvedType::unit(), + ); assert_eq!("[(), (), ()]", &array.to_string()); let list = Value::list([Value::unit()], ResolvedType::unit(), NonZeroPow2Usize::TWO); assert_eq!("list![()]", &list.to_string()); @@ -1261,7 +1299,10 @@ mod tests { ( "[1, 2, 3]", ResolvedType::array(UIntType::U4.into(), 3), - Value::array([Value::u4(1), Value::u4(2), Value::u4(3)], UIntType::U4.into()), + Value::array( + [Value::u4(1), Value::u4(2), Value::u4(3)], + UIntType::U4.into(), + ), ), ( "list![1, 2, 3]",