Skip to content

Fix BytecodeDeserializer to return BytecodeTypes, restore Strict.Bytecode and Strict compilation#38

Draft
Copilot wants to merge 115 commits intomasterfrom
copilot/experiment-image-processing-parallelization
Draft

Fix BytecodeDeserializer to return BytecodeTypes, restore Strict.Bytecode and Strict compilation#38
Copilot wants to merge 115 commits intomasterfrom
copilot/experiment-image-processing-parallelization

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

The BytecodeDeserializer was left in a half-reworked state: TypeEntryData, Package, Instructions, PrecompiledMethods were inside a TODO comment block, Deserialize() referenced non-existent variables, and Runner.cs had incomplete statements. Nothing compiled.

BytecodeDeserializer

  • Restored TypeEntryData as private class, fixed Deserialize(Package) to read ZIP entries, extract metadata into BytecodeTypes, and read instructions
  • Added ReadTypeMetadataIntoBytecodeTypes — captures member/method string data into BytecodeTypes.TypeMembersAndMethods while still creating Language types needed for instruction deserialization
  • Uses BuildMethodInstructionKey format (TypeName|MethodName|ParamCount) consistently — matches what VirtualMachine expects for precompiled method lookup

BytecodeTypes

  • Fixed method.FullName.Namemethod.Name (FullName is already a string)
  • Updated Find to use BuildMethodInstructionKey format via shared GetTypeNameFromEntryName

Runner

  • Restored constructor initialization of package, mainType, currentFolder for both .strict source and .strictbinary input
  • Build() and Run() now branch on deserializedBytecodeTypes != null to handle bytecode-loaded vs source-loaded types
  • Removed dead commented-out code blocks

Usage after changes

// File-based: returns BytecodeTypes (new unified data structure)
var types = new BytecodeDeserializer(filePath).Deserialize(basePackage);
var instructions = types.Find("SimpleCalculator", "Run", 0);

// In-memory (tests): sets Package/Instructions/PrecompiledMethods properties
var deserializer = new BytecodeDeserializer(entryBytes, package);
vm.Execute(deserializer.Instructions!.Values.First());

Test results

  • Strict.Bytecode.Tests: 67/67 ✅
  • Strict.Compiler.Assembly.Tests: 158/158 ✅
  • Strict.Expressions.Tests: 546/546 ✅
  • Strict.Optimizers.Tests: 59/59 ✅

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits March 14, 2026 04:39
…single-thread

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
…threshold

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
…iable

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
@BenjaminNitschke
Copy link
Collaborator

@copilot continue, we want to test gpu impact. Also the loop count alone is not a good indicator of overall complexity, a 1million iterations loop with 1 instruction each is less complex than a 10k iteration loop with 1k instructions each, which would be a perfect candidate for parallization and gpu usage

Copilot AI changed the title [WIP] Add parallel processing for image brightness adjustment Add MLIR parallel loop support and GPU execution plan for image processing Mar 14, 2026
Copilot AI requested a review from BenjaminNitschke March 14, 2026 04:52
Copilot AI and others added 2 commits March 14, 2026 04:59
…tions) and add GPU impact projection

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 14, 2026

@copilot continue, we want to test gpu impact. Also the loop count alone is not a good indicator of overall complexity, a 1million iterations loop with 1 instruction each is less complex than a 10k it...

Implemented in 343fe60 and 42d88e7:

Complexity-based threshold: Changed from simple iteration count to iterations × body instruction count. ShouldEmitParallelLoop now calls CountLoopBodyInstructions() to scan between LoopBegin/LoopEnd and multiply by iteration count. So:

  • 10K iterations × 20 body instructions = 200K complexity → parallelizes ✓
  • 50K iterations × 1 body instruction = 50K complexity → stays sequential ✓
  • 1M iterations × 1 instruction = 1M → parallelizes ✓

GPU impact: Added projection test based on BlurPerformanceTests CUDA reference data (143x speedup). For 4K brightness adjustment: SingleThread ~1.8s, ParallelCpu ~730ms (2.5x), projected GPU ~92ms (20x, conservative estimate since real CUDA showed 143x for blur). The test validates projected GPU time beats CPU parallel.

Threshold constant is InstructionsToMlir.ComplexityThreshold = 100_000 (public, used by tests).

Copilot AI changed the title Add MLIR parallel loop support and GPU execution plan for image processing Add MLIR parallel loop support with complexity-based threshold and GPU execution plan Mar 14, 2026
Copilot AI and others added 2 commits March 14, 2026 05:39
…ia unrolled interior kernel

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
…zes instead

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Copilot AI changed the title Add MLIR parallel loop support with complexity-based threshold and GPU execution plan Add 5×5 blur performance tests with optimized kernel and complexity-based parallelization Mar 14, 2026
…e Cuda.Tests how CPU, Single threaded vs Parallized vs GPU performs. What matters is implementation to Mlir generation
Copilot AI and others added 2 commits March 14, 2026 13:36
…2 of GpuSupportPlan)

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
… with Phase 2 implementation status

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Copilot AI changed the title Add 5×5 blur performance tests with optimized kernel and complexity-based parallelization Implement MLIR GPU dialect emission for high-complexity loops (Phase 2) Mar 14, 2026
BenjaminNitschke and others added 30 commits March 24, 2026 01:58
…mbine, added more tests, grammar fixes. still working on one final test to parse text
…verflows, still getting through all the remaining issues of RunAllTestsForAllStrictFilesInThisRepo
…t package for the RunAllTestsForAllStrictFilesInThisRepo test
…emantics (partial)

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/strict-lang/Strict/sessions/4a53801f-4e6e-4129-8785-37cc72b514af
…but wrong loop bound)

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/strict-lang/Strict/sessions/2c515314-58d9-4e68-8684-fd9cb75081cb
…trictBasePackageCode test to quickly check if all .strict code can be parsed (no need to do it much higher up with other issues left and right)
… is in the span, removed not longer used App.strict
…mentation, still not the best, but a little helpful
…rror, need to try a different attempt, for loops also need one more fix and FindType needs to be consolidated with GetType and TryGetType, too many ways to get types that all work slightly different
…comparisons, a bit verbose, but works for now.
…lso fixed, now Text.Split is causing trouble, but we are close to the end
…GetType→FindType (public)

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/strict-lang/Strict/sessions/bbd18155-4d13-4006-9414-b6e11fec697c
…rName condition

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/strict-lang/Strict/sessions/bbd18155-4d13-4006-9414-b6e11fec697c
…ion member ordering

Co-authored-by: BenjaminNitschke <1650127+BenjaminNitschke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/strict-lang/Strict/sessions/e8e6ec52-3265-4e14-8fdc-1d99c0d45c28
…ls or MemberCalls, it is like adding this. everywhere, no need, but causes some things to fail as the parsing is not always aware of this
…ons there yet, probably not worth it. Updated HashCode to use selection if, but the computation is still very much dummy, we first need generic type check support. also fixed parsing inside brackets to correctly include all binary arguments
…t replaces some old NamedType things and Member.strict, both not longer needed in the strict world. Also added test to make sure assigning members is ok in from constructors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants