Browse Source

docs: record multiple-inheritance cost breakdown (Tier 1 vs Tier 2)

OOP.txt future-work note: single inheritance stays 230 by choice; if MI
is ever wanted, the cost is dominated by pointer adjustment for
upcasting to a non-first base. Tier 1 = multi-parent inclusion with
primary-base polymorphism only (no adjustment, ~1 day); Tier 2 = full
MI with adjustment + this-thunks and a diamond decision (several days).
features.md points at it.
Eric Streit 1 week ago
parent
commit
636084360b
2 changed files with 31 additions and 1 deletions
  1. 29 0
      docs/OOP.txt
  2. 2 1
      docs/features.md

+ 29 - 0
docs/OOP.txt

@@ -49,6 +49,35 @@ NOTES (V3 implementation, m2compiler-V3):
   a class BEGIN ... END init body runs once at startup (as
   <Class>_init).
 - Still 230: extra parents (multiple inheritance is out of scope).
+
+FUTURE WORK -- multiple inheritance (not planned; recorded for later):
+
+  Single inheritance is a deliberate choice; extra parents stay 230.
+  If MI is ever wanted, the cost is dominated by ONE thing: pointer
+  adjustment for upcasting to a non-first base.
+
+    * Tier 1 -- "multiple inclusion" (~1 day): CLASS C (A, B) lays out
+      A's fields then B's, and both sets of methods are callable as
+      obj.M, but you may only upcast along the FIRST parent
+      (POINTER TO B := c stays rejected).  No pointer adjustment, so
+      the fixpoint stays a reliable guard.  Mostly SymTab/QbeGen:
+      tparent -> a parent list (ParentCount/ParentAt), and
+      FindField / ClassMethodNode / IsSubclass / BuildVTable /
+      ComputeOffsets / TypeSizeD iterating the set; plus an ambiguity
+      check when two paths declare the same name (~10-15 functions).
+
+    * Tier 2 -- full MI with polymorphic upcasting (several days,
+      higher risk): adds address adjustment on every upcast (pointer
+      assignment, VAR/value actuals, =/#, NEW) and this-adjusting
+      thunks for virtual calls through a secondary base; also forces a
+      decision on DIAMONDS -- note CLASS Multi (Shape, Circle) below
+      IS a diamond (Circle already inherits Shape), needing shared-base
+      dedup or an outright rejection.  Clarion reference semantics for
+      multi-parent classes are not fully specified here, so Tier 2
+      would partly be inventing semantics.
+
+  Recommendation: Tier 1 only if a real corpus needs multi-parent
+  inclusion; otherwise leave MI out.
 	
 
 

+ 2 - 1
docs/features.md

@@ -109,7 +109,8 @@ Legend: ✅ done · 🔄 partial · ⏸ not started / deferred.
   dynamic dispatch via vtables** (with subtype pointer assignment),
   bare sibling-method calls (a call on `THIS`), and a class
   `BEGIN … END` init body (runs at startup). ⏸ Multiple parents
-  (deliberately single inheritance only). See
+  (deliberately single inheritance only; a Tier-1/Tier-2 cost breakdown
+  for future MI is recorded in `docs/OOP.txt`). See
   `docs/summary_class-lowering.md`, `docs/summary_virtual-dispatch.md`,
   `docs/summary_class-finish.md`.
 - ✅ `VAL` conversions across `INTEGER`/`CHAR`/`BOOLEAN`/enum,