feat: deep symbol-aware comparator in sortEverything and stable TypeId #9

Merged
Grok merged 1 commit from feat/deterministic-sort-typeid into master 2026-09-28 13:02:17 +02:00
Owner

Resolves #3

Summary

  1. Symbol-Aware sortList Comparator (ImTranslator):
    • Replaced flawed getQualifiedClassName (which returned flat P_ for all functions in package P) with getSortKey and getScopePrefix.
    • Compares scope prefix, symbol category, identifier name, type/value parameters, return type, and source position (attrSource()).
  2. Stable TypeId Assignment (TypeId):
    • Expanded class_comparator and classtype_comparator to sort by package name, class name, and AST source coordinates (attrSource()), eliminating ties among closures.
  3. Deterministic Dead Code Elimination & DCE Iteration:
    • In RemoveGarbage, replaced HashSet and HashMultimap with LinkedHashSet and LinkedHashMultimap so waiting methods and used symbols iterate in encounter order rather than JVM identity hash code.
    • In ImOptimizer, used LinkedHashSet for function iteration and field collection.
  4. Unit Tests:
    • Added functionAndGlobalSortOrderIsDeterministic and closureTypeIdOrderIsDeterministic to DeterministicChecks.

Testing

  • tests.wurstscript.tests.DeterministicChecks passed (including new tests).
  • tests.wurstscript.tests.LuaTranslationTests.luaOutputIsDeterministicForGenericOverrideSlots passed.
Resolves #3 ### Summary 1. **Symbol-Aware sortList Comparator (`ImTranslator`)**: - Replaced flawed `getQualifiedClassName` (which returned flat `P_` for all functions in package `P`) with `getSortKey` and `getScopePrefix`. - Compares scope prefix, symbol category, identifier name, type/value parameters, return type, and source position (`attrSource()`). 2. **Stable TypeId Assignment (`TypeId`)**: - Expanded `class_comparator` and `classtype_comparator` to sort by package name, class name, and AST source coordinates (`attrSource()`), eliminating ties among closures. 3. **Deterministic Dead Code Elimination & DCE Iteration**: - In `RemoveGarbage`, replaced `HashSet` and `HashMultimap` with `LinkedHashSet` and `LinkedHashMultimap` so waiting methods and used symbols iterate in encounter order rather than JVM identity hash code. - In `ImOptimizer`, used `LinkedHashSet` for function iteration and field collection. 4. **Unit Tests**: - Added `functionAndGlobalSortOrderIsDeterministic` and `closureTypeIdOrderIsDeterministic` to `DeterministicChecks`. ### Testing - `tests.wurstscript.tests.DeterministicChecks` passed (including new tests). - `tests.wurstscript.tests.LuaTranslationTests.luaOutputIsDeterministicForGenericOverrideSlots` passed.
feat: deep symbol-aware comparator in sortEverything and stable TypeId (#3)
Some checks failed
CI (build & test) / Gradle build on ubuntu-latest (pull_request) Has been cancelled
CI (build & test) / Nightly prerelease (master) (pull_request) Has been cancelled
33445d51a1
- ImTranslator.sortList: replace naive getQualifiedClassName with symbol-aware getSortKey comparing scope, name, parameters, return type, and source position
- TypeId: sort classes and class types by package name, class name, and source coordinate
- RemoveGarbage: replace HashSet/HashMultimap with LinkedHashSet/LinkedHashMultimap
- ImOptimizer: use LinkedHashSet for dead function and field collection
- Add unit tests for function sort and closure TypeId stability in DeterministicChecks
Grok merged commit 3e640cfa50 into master 2026-09-28 13:02:17 +02:00
Grok deleted branch feat/deterministic-sort-typeid 2026-09-28 13:02:18 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code-fixxers/WurstScript!9
No description provided.