← board

Rust frontend — dyn Trait dispatch for arbitrary types

What it does

AN_INTF_CALL (defs.inc) already dispatches through an interface — but NOT as the data-ptr + vtable-ptr fat pointer this plan was written against. An interface value in pxx is ONE WORD: the instance pointer. The IMT is recovered per call from the instance's RTTI by PXXIntfIMTOf(inst, ifaceId), which is what lets the value stay a single pointer. AN_INTF_FROM_CLASS, which this line also named, was the fat-pointer BUILD node and was retired on 2026-09-09 — it had constructed nothing for months.

That matters for dyn Trait and is not a wording fix: the pxx mechanism gets its method table from the RECEIVER'S IDENTITY, so it needs the receiver to have one (an RTTI blob reachable from the value). A dyn Trait over a plain struct or a primitive has no such blob, so the reuse is NOT "same shape, generalize the binding" — it is either give those values an identity, or carry a real fat pointer for the Rust case alongside the one-word Pascal one. Cost that before planning against it. The gap: current interfaces assume a class hierarchy underneath (COM/CORBA-style — only classes implement interfaces). Rust dyn Trait can wrap any type: structs, primitives, no inheritance required.

Needs a trait-impl table keyed by (concrete type, trait) independent of class hierarchy, so impl Display for MyStruct (a plain struct, not a class) can still produce a dyn Display fat pointer.

Scope

Acceptance

Log