Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ cast_possible_truncation = "allow"
case_sensitive_file_extension_comparisons = "allow"

[workspace.dependencies]
rue-lexer = { path = "crates/rue-lexer", version = "0.8.2" }
rue-parser = { path = "crates/rue-parser", version = "0.8.2" }
rue-diagnostic = { path = "crates/rue-diagnostic", version = "0.8.2" }
rue-ast = { path = "crates/rue-ast", version = "0.8.2" }
rue-compiler = { path = "crates/rue-compiler", version = "0.8.2" }
rue-options = { path = "crates/rue-options", version = "0.8.2" }
rue-lir = { path = "crates/rue-lir", version = "0.8.2" }
rue-hir = { path = "crates/rue-hir", version = "0.8.2" }
rue-types = { path = "crates/rue-types", version = "0.8.2" }
rue-lexer = { path = "crates/rue-lexer", version = "0.8.3" }
rue-parser = { path = "crates/rue-parser", version = "0.8.3" }
rue-diagnostic = { path = "crates/rue-diagnostic", version = "0.8.3" }
rue-ast = { path = "crates/rue-ast", version = "0.8.3" }
rue-compiler = { path = "crates/rue-compiler", version = "0.8.3" }
rue-options = { path = "crates/rue-options", version = "0.8.3" }
rue-lir = { path = "crates/rue-lir", version = "0.8.3" }
rue-hir = { path = "crates/rue-hir", version = "0.8.3" }
rue-types = { path = "crates/rue-types", version = "0.8.3" }
anyhow = "1.0.98"
clvm-traits = "0.28.1"
clvm-utils = "0.28.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-ast"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "An implementation of the Abstract Syntax Tree for the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-cli"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A CLI tool for invoking the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-compiler"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A compiler for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-diagnostic"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "All of the potential diagnostics that can be emitted by the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-hir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-hir"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "Provides a high-level intermediate representation of the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-lexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lexer"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A lexer for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-lir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lir"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "Provides a low-level intermediate representation that compiles to CLVM."
Expand Down
54 changes: 52 additions & 2 deletions crates/rue-lir/src/optimize/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,61 @@ pub fn opt_substr(
}

pub fn opt_logand(arena: &mut Arena<Lir>, args: Vec<LirId>) -> LirId {
arena.alloc(Lir::Logand(args))
let mut args = ArgList::new(args);
let mut result = Vec::new();
let mut value = BigInt::from(-1);

while let Some(arg) = args.next() {
match arena[arg].clone() {
Lir::Atom(atom) => value &= atom_bigint(atom),
Lir::Logand(items) => args.prepend(items),
Lir::Raise(_) => return arg,
_ => result.push(arg),
}
}

if value != BigInt::from(-1) {
result.push(arena.alloc(Lir::Atom(bigint_atom(value))));
}

if result.is_empty() {
return arena.alloc(Lir::Atom(bigint_atom(BigInt::from(-1))));
}

if result.len() == 1 && matches!(arena[result[0]], Lir::Atom(_)) {
return result[0];
}

arena.alloc(Lir::Logand(result))
}

pub fn opt_logior(arena: &mut Arena<Lir>, args: Vec<LirId>) -> LirId {
arena.alloc(Lir::Logior(args))
let mut args = ArgList::new(args);
let mut result = Vec::new();
let mut value = BigInt::from(0);

while let Some(arg) = args.next() {
match arena[arg].clone() {
Lir::Atom(atom) => value |= atom_bigint(atom),
Lir::Logior(items) => args.prepend(items),
Lir::Raise(_) => return arg,
_ => result.push(arg),
}
}

if value != BigInt::from(0) {
result.push(arena.alloc(Lir::Atom(bigint_atom(value))));
}

if result.is_empty() {
return arena.alloc(Lir::Atom(vec![]));
}

if result.len() == 1 && matches!(arena[result[0]], Lir::Atom(_)) {
return result[0];
}

arena.alloc(Lir::Logior(result))
}

pub fn opt_logxor(arena: &mut Arena<Lir>, args: Vec<LirId>) -> LirId {
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lsp"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A language server protocol (LSP) implementation for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-options/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-options"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "Provides a way to configure the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-parser"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A parser for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-tests"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
publish = false
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-types"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
license = "Apache-2.0"
description = "A type system for the Rue programming language."
Expand Down
8 changes: 4 additions & 4 deletions tests/operators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ tests:
byte_cost: 9636000
total_cost: 9655280
- name: bitwise
program: (a (i (= (lognot (q . 10)) (q . -11)) (q 2 (i (= (ash (q . 50) (q . -2)) (q . 12)) (q 2 (i (= (ash (q . 50) (q . 2)) (q . 200)) (q 2 (i (= (lsh (q . -50) (q . -1)) (q . 103)) (q 2 (i (= (lsh (q . 50) (q . -1)) (q . 25)) (q 2 (i (= (lsh (q . -50) (q . 1)) (q . 412)) (q 2 (i (= (lsh (q . 50) (q . 1)) (q . 100)) (q 2 (i (logand (q . 10) (q . 5)) (q 8) (q 2 (i (= (logior (q . 10) (q . 5)) (q . 15)) (q 2 (i (= (logxor (q . 10) (q . 5)) (q . 15)) (q) (q 8)) 1) (q 8)) 1)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1)
program: (a (i (= (lognot (q . 10)) (q . -11)) (q 2 (i (= (ash (q . 50) (q . -2)) (q . 12)) (q 2 (i (= (ash (q . 50) (q . 2)) (q . 200)) (q 2 (i (= (lsh (q . -50) (q . -1)) (q . 103)) (q 2 (i (= (lsh (q . 50) (q . -1)) (q . 25)) (q 2 (i (= (lsh (q . -50) (q . 1)) (q . 412)) (q 2 (i (= (lsh (q . 50) (q . 1)) (q . 100)) (q 2 (i (= (q . 15) (q . 15)) (q 2 (i (= (logxor (q . 10) (q . 5)) (q . 15)) (q) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1) (q 8)) 1)
debug_program: (a (i (= (lognot (q . 10)) (- () (q . 11))) (q 2 (i (= (ash (q . 50) (- () (q . 2))) (q . 12)) (q 2 (i (= (ash (q . 50) (q . 2)) (q . 200)) (q 2 (i (= (lsh (- () (q . 50)) (- () (q . 1))) (q . 103)) (q 2 (i (= (lsh (q . 50) (- () (q . 1))) (q . 25)) (q 2 (i (= (lsh (- () (q . 50)) (- () (- () (q . 1)))) (q . 412)) (q 2 (i (= (lsh (q . 50) (- () (- () (q . 1)))) (q . 100)) (q 2 (i (= (logand (q . 10) (q . 5)) ()) (q 2 (i (= (logior (q . 10) (q . 5)) (q . 15)) (q 2 (i (= (logxor (q . 10) (q . 5)) (q . 15)) (q) (q 8 (q . "assertion failed at operators.rue:71:5"))) 1) (q 8 (q . "assertion failed at operators.rue:70:5"))) 1) (q 8 (q . "assertion failed at operators.rue:69:5"))) 1) (q 8 (q . "assertion failed at operators.rue:68:5"))) 1) (q 8 (q . "assertion failed at operators.rue:67:5"))) 1) (q 8 (q . "assertion failed at operators.rue:66:5"))) 1) (q 8 (q . "assertion failed at operators.rue:65:5"))) 1) (q 8 (q . "assertion failed at operators.rue:64:5"))) 1) (q 8 (q . "assertion failed at operators.rue:63:5"))) 1) (q 8 (q . "assertion failed at operators.rue:62:5"))) 1)
output: ()
runtime_cost: 8473
byte_cost: 4548000
total_cost: 4556473
runtime_cost: 6924
byte_cost: 4092000
total_cost: 4098924
diagnostics:
- Unnecessary `+` operator, since it has no effect at operators.rue:2:12
- Condition always evaluates to `true` at operators.rue:51:12
Expand Down
7 changes: 7 additions & 0 deletions tests/optimizer/bitwise_constant.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test fn test_bitwise_or() -> Int {
SENDER_PUZZLE | RECEIVER_PUZZLE
}

test fn test_bitwise_and() -> Int {
0b110_000 & 0b010_000
}
15 changes: 15 additions & 0 deletions tests/optimizer/bitwise_constant.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests:
- name: test_bitwise_or
program: (q . 18)
debug_program: (logior (q . 16) (q . 2))
output: '18'
runtime_cost: 20
byte_cost: 36000
total_cost: 36020
- name: test_bitwise_and
program: (q . 16)
debug_program: (logand (q . 48) (q . 16))
output: '16'
runtime_cost: 20
byte_cost: 36000
total_cost: 36020
2 changes: 1 addition & 1 deletion wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-wasm"
version = "0.8.2"
version = "0.8.3"
edition = "2024"
publish = false
license = "Apache-2.0"
Expand Down