Skip to content

Refactor specialize.rs for efficiency and clarity#885

Open
seth-schultz wants to merge 1 commit intorue-language:trunkfrom
seth-schultz:specialize-refactor
Open

Refactor specialize.rs for efficiency and clarity#885
seth-schultz wants to merge 1 commit intorue-language:trunkfrom
seth-schultz:specialize-refactor

Conversation

@seth-schultz
Copy link

Summary

Refactors the generic function specialization pass for improved performance and code clarity.

Changes

  • Fix O(n²) RIR traversal: Store rir_params_start/len in FunctionInfo for O(1) param lookup
  • Remove redundant HashMap: Eliminate intermediate name_map - pass specializations directly
  • Use entry API: Avoid unnecessary .clone() on type_args in collect_specializations
  • Simplify iteration: Use param_arena.iter() instead of manual 4-way zip
  • Add debug assertion: Catch type substitution failures in debug builds
  • Move imports to top: Follow codebase convention for Entry import

Result

  • 280 lines (down from 334, -16%)
  • Same functionality, cleaner code
  • All tests pass

Testing

  • All 1341 spec tests pass
  • All 445 unit tests pass
  • Generic functions and anonymous struct types work correctly

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.

1 participant