Repository navigation
Commit 1cbef7f
authored
Refactor bisector system, add supervisor, add unit tests, and fix transformations (#1290)
* Refactor bisector system, add supervisor, add unit tests, and fix transformations.
Major refactor of UnitTestBisectorSystem: introduces new bisector plans (DisableOne, EnableOne, RandomCombo, FailureInducing, Masking), robust state management, improved transform observation, and enhanced reporting. Adds Mosa.Utility.UnitTestBisector.Supervisor for process supervision and restart. Updates command-line options, documentation, and project files. Improves diagnostics, output, and testability throughout the bisector and unit test infrastructure.
* Enable SafePoint stages in method compiler pipeline
Activated SafePointStage before and SafePointLayoutStage after CodeGenerationStage in the method compiler pipeline, enabling GC safepoint infrastructure for improved garbage collection support.
* Standardize bisect arg names, refactor bisector logic
- Renames `-bisect-state-file` to `-bisect-state` for consistency.
- Refactors bisector plan/order parsing to use switch expressions.
- Simplifies output and reporting in bisector system.
- Removes redundant/debug code from transform disabling logic.
- Updates `Mosa.Linux.sln` for VS2022 and normalizes configs.
- Applies minor string, argument, and formatting cleanups.
* Refactor: centralize bisector constants in Constant.cs
Move magic constants (exit kinds, baseline iteration, option names, etc.) to a new Constant.cs file. Update all usages in BisectorState.cs and UnitTestBisectorSystem.cs to reference the Constant class, improving maintainability and reducing duplication.
* Remove forced-disabled transforms from bisector logic
Eliminates all handling of forced-disabled transforms and the related file option from the bisector system. Updates state, compatibility checks, and reporting to only use session-based disabled transforms. Refactors IsSupervisorOption to use a switch expression and performs minor cleanup in unit test handling and status output.
* Refactor bisector classes to internal top-level types
Refactored private nested classes in Mosa.Utility.UnitTestBisector to internal top-level classes for better accessibility and maintainability. Moved PlanKind and OrderKind enums to separate files. Removed BisectorDisabledTransformsFile from MOSASettings. No functional changes.
* Refactor: Move unit test serialization to new class
Extract unit test serialization, result parsing, and formatting logic from UnitTestSystem into a new static UnitTestSerializer class. Update all usages in UnitTestSystem, UnitTestEngine, and UnitTestBisectorSystem to use UnitTestSerializer, improving code organization and separation of concerns.
* Refactor unit test discovery and execution flow
Centralize unit test discovery and execution in a new UnitTestRunner static class. Update UnitTestBisectorSystem and UnitTestSystem to use this runner, passing discovered tests explicitly. Remove shared state for test lists, clean up unused code, and improve separation of concerns for better maintainability.
* Refactor Sub64 logic for clarity in BitTrackerOperations
Clarified Sub64 by adding an explicit else branch. Now, when value2 is zero, the result is narrowed to value1; otherwise, SetStable(value1, value2) is used. This improves code readability and intent.
* Add sign extension tests and fix SignExtend32x64 mask
Added thorough unit tests for SignExtend32x64 and SignExtend8x64, covering all sign bit and known/unknown bit scenarios. Fixed SignExtend32x64 to use the correct upper 32 bits mask for sign extension.
* Add new optimization defaults; reformat Constant.cs
Added default settings for ReduceCodeSize and inlining options in MOSASettings. Reformatted Constant.cs to use tabs for indentation. No logic changes in constants.
* Refactor bisector session state and iteration handling
Refactored bisector logic to introduce explicit session state fields in BisectorState, persist session name and invert outcome, and improve masking pre-check handling. Platform registration is now centralized. Bisector plan execution is split into clear phases with robust state management, supporting single-iteration-per-process and supervisor restarts. Output and disabled transform logic are clarified and simplified.
* Replay all bisector session results from index 0
Previously, the loop skipped the first result when restoring bisector state. Now, all results in state.Results are replayed to ensure the bisector state is fully restored.
* Add regression tests and fix BitTrackerOperations bugs
Comprehensive regression and additional unit tests were added for BitTrackerOperations. Fixed Add64 to only narrow min/max when no unsigned overflow is possible. Corrected And32 to use BitsSet32 for zero checks. Updated RemUnsigned32/64 to use value2.MaxValue for bounds and consolidated divide-by-zero guards. Fixed ShiftRight64 to track stability with both operands.
* Improve BitTrackerOperations edge case handling and tests
Added comprehensive unit tests for Add32, MulUnsigned32, MulSigned32, MulSigned64, and To64, covering overflow and range-narrowing scenarios. Simplified Add32 overflow checks by removing unreachable conditions. Corrected MulSigned32 and MulSigned64 to use actual min/max products for range narrowing. Fixed MulUnsigned32 to only clear upper 32 bits on overflow. Clarified RemUnsigned32 zero-divisor comment. Updated To64 to use BitsSet32 for constructing 64-bit values from 32-bit parts.
* update 1
* Reorganize tests
* Add AddCarryOut32/64 logic and expand boolean narrowing tests
Implemented AddCarryOut32 and AddCarryOut64 in BitTrackerOperations for precise sum and carry-out tracking. Updated BitTrackerStage to use these handlers for IR.AddCarryOut32/64. Added thorough tests for Result2NarrowToBoolean, covering upper bits, unconstrained, known true/false, and stability cases.
* Add unit tests and handlers for Add/Sub carry/overflow ops
Added thorough unit tests for BitTrackerOperations covering AddCarryOut32/64, AddOverflowOut32/64, SubCarryOut32/64, and SubOverflowOut32/64, including edge cases. Updated BitTrackerStage to register and implement dedicated handler methods for these IR instructions, replacing the previous generic handler.
* Document BitTrackerStage and related subsystems
Expand copilot-instructions.md with a detailed "BitTracker Stage" section, covering architecture, BitValue lattice, IntegerTwiddling helpers, dual-result instruction handling, and extension guidelines. Update key namespaces/classes and clarify documentation requirements for new settings.
* Fix signed subtraction overflow logic and tests
Correct IsSubSignedOverflow for int/long to use MinValue+ and MaxValue+ logic. Expand and update related unit tests to cover edge cases and match new overflow detection.
* Standardize carry/overflow out IR handling in BitTracker
Replaced custom handlers for Add/Sub CarryOut and OverflowOut IR instructions with the shared Result2NarrowToBoolean method in BitTrackerStage. This unifies and simplifies result processing by consistently narrowing these results to boolean values.
* Update AddOverflowOut handlers in BitTrackerStage
Switched IR.AddOverflowOut32 and IR.AddOverflowOut64 to use dedicated handlers (AddOverflowOut32/AddOverflowOut64) instead of the generic Result2NarrowToBoolean, enabling more precise bit-tracking for overflow detection.
* Update BitTracker handlers for SubCarry/Overflow IR ops
Replaced generic Result2NarrowToBoolean handler with specific handlers for SubCarryOut32, SubCarryOut64, SubOverflowOut32, and SubOverflowOut64 in BitTrackerStage. This enables more accurate bit-tracking for these instructions.
* Update bisector to support all stages by default
Removed default stage restriction in bisector logic, allowing bisecting across all stages when BisectorStage is unset. Output now displays "All" for unspecified stages. Also removed unused upper bit mask constants from BitTrackerStage.cs.
* Update BitTrackerStage to use generic handler for SubCarryOut
Replaced SubCarryOut32 and SubCarryOut64 handlers with the generic Result2NarrowToBoolean handler in BitTrackerStage, simplifying the registration and handling logic for these IR instructions.
* Tighten BitValue equality; simplify bisector counters
- IsSame in BitValue now checks Is32Bit for stricter equality.
- RecalculateCounters in UnitTestBisectorSystem always sums Results and Baseline, removing special case logic.
- Reformatted UnitTestRunner.cs to use tabs per project style.
* Track newly observed transforms per iteration
Add NewlyObservedTransforms to PlanResult and update bisector logic to record, replay, and persist transforms first seen in each iteration. Simplify and standardize iteration status output, comment out redundant logs, and improve status formatting for clarity.
* Refactor bisector header output to single line
Consolidate multiple OutputStatusBisector calls in PrintIterationHeader into a single formatted line, improving log readability and reducing output verbosity.
* Clean up bisector: remove dead code and debug prints
Refactored UnitTestBisectorSystem.cs and Builder.cs by removing commented-out and redundant debug print statements, including PrintDisabledTransforms. Moved OutputStatusBisector and OutputStatus methods for clarity. The "Order" field is now always displayed, and RecalculateCounters logic is simplified. No changes to core functionality.
* Refactor bisector output methods and add FailureCount
Replaces all "Print" status methods with unified "Output" methods for consistency. Adds FailureCount to BisectorState and updates all failure tracking logic to use it. Enhances OutputIterationStatus to show cumulative stats. Updates all bisector workflows to use new output methods and ensures accurate failure reporting.
* Refactor: organize bisector logic into regions & helpers
Refactored UnitTestBisectorSystem to group related methods into logical regions (Entry Point, Plan Execution, Iteration Execution, State Management, Plan & Transform Helpers, File I/O, Output). Extracted and restructured helper methods for state management, plan parsing, output, and transform set building. Separated deterministic and random plan execution logic. Improved code clarity and maintainability without changing functional behavior.
* Track and report unit test restarts-exceeded failures
Add hasRestartsExceeded to detect when unit test system restarts are exceeded. Update all plan execution paths to halt and record failure if this occurs. Enhance failure review file to indicate both compilation failures and restarts-exceeded conditions for improved diagnostics.
* Move BitTrackerOperations to Analysis namespace
Relocated BitTrackerOperations from Mosa.Compiler.Framework.Stages to Mosa.Compiler.Framework.Analysis without changing its logic. Updated all references and using directives in affected files to use the new namespace.
* Enhance transform hooks and conditional diagnostics
Add notifications and disable checks for block transforms via CompilerHooks in BaseTransformStage. Make application launch status output conditional on MosaSettings.Diagnostic in BaseLauncher.
* Enable transform hooks selectively in OptimizationStage
Allow OptimizationStage to opt-in to transform hook notifications and filtering by introducing an EnableTransformHooks property. Only stages with this property enabled will invoke transform hook logic, reducing unnecessary calls. Also, override the Name property in platform-specific OptimizationStages to include the platform prefix.
* Add global.json to specify .NET SDK version 10.0.203
Added global.json to enforce usage of .NET SDK 10.0.203 with rollForward set to "latestFeature", ensuring consistent build environments across development and CI.
* Improve PipelinePool lifecycle management in Compiler
Added a private pipelinePool field to the Compiler class to track the PipelinePool instance during parallel compilation. Updated ExecuteCompile to assign and clear pipelinePool appropriately. Modified Stop to notify the PipelinePool when stopping the compiler. Also removed the global.json file specifying the .NET SDK version.
* Code cleanup: formatting, unused usings, add NotifyStop
Improved code formatting and indentation across several files for readability. Removed unused using directives in BitTrackerStage.cs and RemoveUnreachableBlocks.cs. Added NotifyStop method to PipelinePool.cs to signal dispatcher shutdown. No functional changes except for the new NotifyStop method.
* Adjust method pipeline, docs, and UI usability
- Clarified default for `-bisect-stage` in command-line docs.
- Refactored method compiler pipeline: always add `DeadBlockStage` with SSA, moved `SafePointStage` after `JumpOptimizationStage`, and removed `PlatformEdgeSplitStage`.
- Added `EmitBinary` property to `ProtectedRegionLayoutStage` and updated logic to respect it.
- Removed obsolete comment in `CodeGenerationStage.cs`.
- Improved UI usability: enabled `CheckOnClick` for relevant checkboxes and cleared default text in `tbTransformStage`.
* Enhance reduction logic and add optimization args
- Improve `ProcessReductionResult` in `Bisector.cs` to include items activated after experiment start in reduction candidates.
- Add `Optimizations_Inline_Maximum`, `Optimizations_ScanWindow`, and `Optimizations_ReduceCodeSize` arguments to `-oSize` and `-oFast` profiles in `CommandLineArguments.cs`.
- Reformat `UnitTestSerializer.cs` for style consistency; logic unchanged.
* Remove dynamic bisecting, fuzz tests, and refactor transforms
Removed all dynamic item observation logic from the Bisector, including ObserveItem and related suspect/candidate set management. Refactored transform tracking to use a single registered Transforms list, eliminating observed transform counts and simplifying state management. Updated all bisector logic, reporting, and compiler hooks to use the new RegisterTransform callback. Deleted all Fuzz0001–Fuzz0018 test files and their contents, removing hundreds of static fuzz test methods. Cleaned up output formatting, removed obsolete code, and improved error handling in the process supervisor.
* Rename EnableTransformHooks to AllowTransformHooks
Renamed the EnableTransformHooks property to AllowTransformHooks in BaseTransformStage and all derived OptimizationStage classes (ARM32, ARM64, x86, x64, and generic). Updated all references accordingly for naming consistency. No functional changes were made.1 parent 8e6aa94 commit 1cbef7f
94 files changed
Lines changed: 8319 additions & 148475 deletions
File tree
- .github
- Source
- .github
- Data
- Docs
- Mosa.Compiler.ARM32/Stages
- Mosa.Compiler.ARM64/Stages
- Mosa.Compiler.Common.xUnit
- Mosa.Compiler.Common
- Mosa.Compiler.Framework.xUnit
- Mosa.Compiler.Framework
- Analysis
- Stages
- Transforms
- BasicBlocks
- Optimizations/Auto
- ConstantFolding
- StrengthReduction
- Mosa.Compiler.x64
- Stages
- Transforms/BaseIR
- Mosa.Compiler.x86/Stages
- Mosa.Tool.Bootstrap
- Mosa.Tool.Compiler
- Mosa.Tool.Explorer.Avalonia
- Mosa.Tool.Explorer
- Mosa.Tool.Launcher
- Mosa.UnitTests
- Fuzzy
- Optimization
- Mosa.Utility.BootImage
- Mosa.Utility.Configuration
- Mosa.Utility.CreateCoreLib
- Mosa.Utility.Launcher
- Mosa.Utility.UnitTestBisector.Supervisor
- Mosa.Utility.UnitTestBisector
- Mosa.Utility.UnitTests
- Mosa.Workspace.Experiment.Debug
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
| |||
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
232 | 381 | | |
233 | 382 | | |
234 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | | - | |
59 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
0 commit comments