Skip to content

Make class vtable slot resolution O(1), deterministic, and kind-safe#200

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/class-vtable-slot-resolution
Jul 11, 2026
Merged

Make class vtable slot resolution O(1), deterministic, and kind-safe#200
ASDAlexander77 merged 1 commit into
mainfrom
refactor/class-vtable-slot-resolution

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Refactors ClassInfo::getVirtualTable (MLIRGenStore.h), which resolved every method override with a linear std::find_if over the accumulated vtable — O(methods × slots), copying each entry by value per comparison — sorted methods with unstable std::sort, and matched method names against interface slots through the shared methodInfo.name field.

  • O(1) slot resolution: llvm::StringMap name→slot indices are carried through the base-class recursion; no more linear scans or per-comparison struct copies.
  • Kind-safe matching: separate maps for method vs interface slots — a method whose name matches an interface full name can no longer clobber the interface slot or suppress its creation (the old find_if searched both kinds through methodInfo.name).
  • Deterministic ABI order: std::sortstd::stable_sort on orderWeight. VTable slot order is ABI for separately compiled modules (.instanceOf must be slot 0, DLL/consumer builds must agree), so members with equal weight — e.g. compiler-generated ones — must keep declaration order rather than an implementation-defined one.

Behavior is unchanged for all non-pathological inputs; the public getVirtualTable(vtable) signature is preserved (the map-carrying overload is used by the recursion).

Test plan

  • Full suite: 683/683 pass (compile + JIT).
  • Virtual-dispatch tests (00class_virtual_call, 00class_virtual_table, 00class_abstract, 00interface) additionally run directly under -O3 JIT.

🤖 Generated with Claude Code

@ASDAlexander77 ASDAlexander77 merged commit 0a6ef3d into main Jul 11, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/class-vtable-slot-resolution branch July 11, 2026 14:51
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