From d269ccff268b85fa6e1825e630ca47ab3b3a4bd4 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 13 Jun 2026 20:28:43 +0200 Subject: [PATCH] IC: correct instance-name format in design doc The content key is hashed into (setInstanceDisamb), not a separate .key. token; document that the cross-TU merge and DCE already key on the module-suffix-stripped name. Co-Authored-By: Claude Opus 4.8 --- doc/ic.md | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/ic.md b/doc/ic.md index 845785f2ad..41281d9944 100644 --- a/doc/ic.md +++ b/doc/ic.md @@ -57,17 +57,25 @@ NIF symbols and ownership ========================= (See ``../nifspec/doc/nif-spec.md``.) A global symbol is -``..`` or, for a generic instantiation, -``...`` where ``key`` is the instantiation -encoded by the *NIF-trees-as-identifiers* scheme. Two consequences drive the +``..``. For a **generic instantiation** the +`` is not a counter but a *content hash* — `setInstanceDisamb` +(``modulegraphs.nim``) MD5s the generic's identity plus the `typeKey` of every +concrete type argument, masks it to 30 bits and tags it with `InstanceDisambBit`. +So the only part of the name that varies between two modules making the **same** +instantiation (`seq[Foo]`) is the ``. Two consequences drive the backend: -- **Instance names are content-addressed**: the same instantiation (`seq[Foo]`) - produced in different modules yields the *same* `key`, so a deterministic - dedup is possible *by name*. -- **The suffix names an owner module.** Today an instance's owner is the module - whose process minted it (`itemId.module`), which is process-local mint order — - the root of the *single-writer* hazard below. +- **Instance names are content-addressed**: the same instantiation produced in + different modules yields the *same* `.`, so a deterministic dedup + is possible by the *module-suffix-stripped* name. The cross-TU merge + (`ccgtypes.sharedInstanceCName`, keyed via `graph.icSharedSigs`) and the DCE + analysis (`dce.computeLiveSymbols`, its `uniq` set) both already key on this + stripped form. +- **The suffix names a mint-site owner.** Today the `` is the + module *that minted the instance* (the instantiation site), so the same + instance has a different full name in each module that makes it; *which* TU + emits the single definition is then decided at codegen by the + reuse/redirect machinery — the root of the *single-writer* hazard below. The driver: graph construction (`commandIc`) ============================================