Skip to content

Support for Polymorphism #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Support for Polymorphism #1474

wants to merge 10 commits into from

Conversation

ghaith
Copy link
Collaborator

@ghaith ghaith commented May 5, 2025

This is the initial work to support polymorphism in function blocks/classes

The commit introduces a virtual table field on the top level function block in an inheritance chain which points to a globally declared vtable.
Each class will then have its own assigned vtable with method pointers to concrete implementations.
On initialization, the vtable for the concrete type is assigned to the variable.

This does break the function block calling convension but there was no way around it.

Steps to do:

  • Create a Vtable type for each class/subclass/interface
    • Create global variables for each new type's vtable
    • Populate the vtable on initialization with the methods from the concrete type
  • When initializing an instance, assign the correct vtable
  • Adjust method calls to use polymorphism
    • Internal method calls reference the vtable
    • External calls done using a pointer to the function block/class are done using the vtable
    • External calls done not using a pointer are called directly.

Interfaces will be a different PR

ghaith added 4 commits May 6, 2025 11:10
A new type is added for every function block, class or interface
this represents a vtable with the methods declared in the class.
If a class extends another class, the parent's class is also included.
If a class extends an interface, the interface is also included.
recursive validation is ignored for internals
stdlib tests ignored
function blocks now contain an extra entry for the vtable
standard lib functions now account for the exta entry
The `__vtable` field in classes and function blocks is assigned at init
time to the correct global variable

TODO: missing tests
Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 99.35185% with 7 lines in your changes missing coverage. Please review.

Project coverage is 91.29%. Comparing base (e731987) to head (2dd01f8).
Report is 67 commits behind head on master.

Files with missing lines Patch % Lines
src/resolver.rs 66.66% 5 Missing ⚠️
src/typesystem.rs 93.33% 1 Missing ⚠️
src/validation/statement.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1474      +/-   ##
==========================================
- Coverage   93.67%   91.29%   -2.38%     
==========================================
  Files         166      174       +8     
  Lines       50097    57498    +7401     
==========================================
+ Hits        46928    52493    +5565     
- Misses       3169     5005    +1836     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

volsa added 3 commits May 7, 2025 15:44
Moves the `__body` field right after the "parent" vtable field if it exists.
Also add introduce some further vtable specific codegen tests.
Move `__body` before local methods
Retain metadata of variable name during const-evaluation in complex-ish struct member initializers
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