Skip to content

feat: Interface Upcasting#1629

Merged
volsa merged 4 commits intomasterfrom
vosa/polymorphism-interface-upcast
Mar 18, 2026
Merged

feat: Interface Upcasting#1629
volsa merged 4 commits intomasterfrom
vosa/polymorphism-interface-upcast

Conversation

@volsa
Copy link
Copy Markdown
Member

@volsa volsa commented Mar 9, 2026

Allow for upcasting between interfaces, e.g.

VAR
  refA: IA; // defined as `INTERFACE IA`
  refB: IB; // defined as `INTERFACE IB EXTENDS IA`
END_VAR

refA := refB;

@volsa volsa marked this pull request as ready for review March 11, 2026 16:17
@volsa volsa marked this pull request as draft March 11, 2026 16:17
Enable assigning a child interface variable to a parent interface
variable (e.g. refIA := refIB where IB EXTENDS IA) by embedding
flattened __upcast_<ancestor> pointer fields in each itable struct.

Table generation (table/interface.rs):
- Each itable struct now includes a POINTER TO __VOID field per proper
  ancestor interface, sorted alphabetically and placed before the
  function pointer fields
- Each itable instance initializes these fields to point directly to
  the corresponding ancestor itable instance for the same POU, giving
  O(1) upcast resolution regardless of hierarchy depth

Dispatch lowering (dispatch/interface.rs):
- Interface-to-interface assignments copy .data directly and read the
  target itable pointer through the __upcast_* field on the RHS itable
- Call arguments where a child interface is passed for a parent
  interface parameter allocate a temp fat pointer with the upcasted
  table
- Same-interface assignments and arguments remain unchanged (memcpy)
@volsa volsa force-pushed the vosa/polymorphism-interface-upcast branch from aa116ca to b14ff29 Compare March 17, 2026 15:36
@volsa volsa marked this pull request as ready for review March 17, 2026 15:56
@volsa volsa merged commit 0b29e89 into master Mar 18, 2026
33 checks passed
@volsa volsa deleted the vosa/polymorphism-interface-upcast branch March 18, 2026 15:22
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