From 14c641797a7d861cf3608176f34cacc3074c4ef6 Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Thu, 1 Jan 2026 12:35:57 -0700 Subject: [PATCH 1/2] Fixed optimizer bug where certain syscalls were not included in register liveness analysis --- .../libs/integration_tests/src/lib.rs | 22 +++++++++++++++ ..._tests__setbatched_with_member_access.snap | 28 +++++++++++++++++++ rust_compiler/libs/optimizer/src/helpers.rs | 5 ++++ 3 files changed, 55 insertions(+) create mode 100644 rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__setbatched_with_member_access.snap diff --git a/rust_compiler/libs/integration_tests/src/lib.rs b/rust_compiler/libs/integration_tests/src/lib.rs index 7295e46..292eeaf 100644 --- a/rust_compiler/libs/integration_tests/src/lib.rs +++ b/rust_compiler/libs/integration_tests/src/lib.rs @@ -18,6 +18,12 @@ mod tests { let compiler = Compiler::new(parser, None); let result = compiler.compile(); + assert!( + result.errors.is_empty(), + "Compilation errors: {:?}", + result.errors + ); + // Get unoptimized output let mut unoptimized_writer = std::io::BufWriter::new(Vec::new()); result @@ -219,4 +225,20 @@ mod tests { let output = compile_with_and_without_optimization(source); insta::assert_snapshot!(output); } + + #[test] + fn test_setbatched_with_member_access() { + let source = indoc! {r#" + const SENSOR = 20088; + const PANELS = hash("StructureSolarPanelDual"); + + loop { + setBatched(PANELS, "Horizontal", SENSOR.Horizontal); + setBatched(PANELS, "Vertical", SENSOR.Vertical + 90); + yield(); + } + "#}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } } diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__setbatched_with_member_access.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__setbatched_with_member_access.snap new file mode 100644 index 0000000..0bfb100 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__setbatched_with_member_access.snap @@ -0,0 +1,28 @@ +--- +source: libs/integration_tests/src/lib.rs +assertion_line: 242 +expression: output +--- +## Unoptimized Output + +j main +main: +__internal_L1: +l r1 20088 Horizontal +sb -539224550 Horizontal r1 +l r2 20088 Vertical +add r3 r2 90 +sb -539224550 Vertical r3 +yield +j __internal_L1 +__internal_L2: + +## Optimized Output + +l r1 20088 Horizontal +sb -539224550 Horizontal r1 +l r2 20088 Vertical +add r3 r2 90 +sb -539224550 Vertical r3 +yield +j 0 diff --git a/rust_compiler/libs/optimizer/src/helpers.rs b/rust_compiler/libs/optimizer/src/helpers.rs index f396969..6bb8d23 100644 --- a/rust_compiler/libs/optimizer/src/helpers.rs +++ b/rust_compiler/libs/optimizer/src/helpers.rs @@ -125,6 +125,9 @@ pub fn reg_is_read(instr: &Instruction, reg: u8) -> bool { | Instruction::Pow(_, a, b) => check(a) || check(b), Instruction::Load(_, a, _) => check(a), Instruction::Store(a, _, b) => check(a) || check(b), + Instruction::StoreBatch(a, _, b) => check(a) || check(b), + Instruction::StoreBatchNamed(a, b, _, c) => check(a) || check(b) || check(c), + Instruction::StoreSlot(a, b, _, c) => check(a) || check(b) || check(c), Instruction::BranchEq(a, b, _) | Instruction::BranchNe(a, b, _) | Instruction::BranchGt(a, b, _) @@ -167,6 +170,8 @@ pub fn reg_is_read(instr: &Instruction, reg: u8) -> bool { Instruction::Atan2(_, a, b) | Instruction::Max(_, a, b) | Instruction::Min(_, a, b) => { check(a) || check(b) } + Instruction::JumpRelative(a) => check(a), + Instruction::Alias(_, a) => check(a), _ => false, } } From 089fe46d361fa3e22686186edfc5d6c8ceaa8502 Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Thu, 1 Jan 2026 12:38:53 -0700 Subject: [PATCH 2/2] update changelog and version bump --- Changelog.md | 8 ++++++++ ModData/About/About.xml | 2 +- csharp_mod/Plugin.cs | 2 +- csharp_mod/stationeersSlang.csproj | 2 +- rust_compiler/Cargo.lock | 2 +- rust_compiler/Cargo.toml | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index 290ce09..8300ad1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,13 @@ # Changelog +[0.5.1] + +- Fixed optimizer bug where `StoreBatch` and `StoreBatchNamed` instructions + were not recognized as reading operands, causing incorrect elimination of + necessary device property loads +- Added comprehensive register read tracking for `StoreSlot`, `JumpRelative`, + and `Alias` instructions in the optimizer + [0.5.0] - Added full tuple support: declarations, assignments, and returns diff --git a/ModData/About/About.xml b/ModData/About/About.xml index b6f8562..6134c9d 100644 --- a/ModData/About/About.xml +++ b/ModData/About/About.xml @@ -2,7 +2,7 @@ Slang JoeDiertay - 0.5.0 + 0.5.1 [h1]Slang: High-Level Programming for Stationeers[/h1] diff --git a/csharp_mod/Plugin.cs b/csharp_mod/Plugin.cs index 15b0053..a7aa94f 100644 --- a/csharp_mod/Plugin.cs +++ b/csharp_mod/Plugin.cs @@ -39,7 +39,7 @@ namespace Slang { public const string PluginGuid = "com.biddydev.slang"; public const string PluginName = "Slang"; - public const string PluginVersion = "0.5.0"; + public const string PluginVersion = "0.5.1"; private static Harmony? _harmony; diff --git a/csharp_mod/stationeersSlang.csproj b/csharp_mod/stationeersSlang.csproj index 7bd7e07..61af2f9 100644 --- a/csharp_mod/stationeersSlang.csproj +++ b/csharp_mod/stationeersSlang.csproj @@ -5,7 +5,7 @@ enable StationeersSlang Slang Compiler Bridge - 0.5.0 + 0.5.1 true latest diff --git a/rust_compiler/Cargo.lock b/rust_compiler/Cargo.lock index aed6d37..f7e2302 100644 --- a/rust_compiler/Cargo.lock +++ b/rust_compiler/Cargo.lock @@ -1039,7 +1039,7 @@ checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" [[package]] name = "slang" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "clap", diff --git a/rust_compiler/Cargo.toml b/rust_compiler/Cargo.toml index 550171e..c0d74e7 100644 --- a/rust_compiler/Cargo.toml +++ b/rust_compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slang" -version = "0.5.0" +version = "0.5.1" edition = "2021" [workspace]