This commit is contained in:
araq
2025-12-17 11:39:19 +01:00
parent d73043eae6
commit 90b323ab6a
5 changed files with 19 additions and 2 deletions

View File

@@ -182,6 +182,7 @@ proc toNifSymName(w: var Writer; sym: PSym): string =
let module = if sym.kindImpl == skPackage: w.currentModule else: sym.itemId.module
result.add modname(module, w.infos.config)
proc globalName(sym: PSym; config: ConfigRef): string =
result = sym.name.s
result.add '.'
@@ -682,6 +683,8 @@ proc writeOp(w: var Writer; content: var TokenBuf; op: LogEntry) =
discard "to implement"
of EnumToStrEntry:
discard "to implement"
of GenericInstEntry:
discard "will only be written later to ensure it is materialized"
proc writeNifModule*(config: ConfigRef; thisModule: int32; n: PNode;
opsLog: seq[LogEntry];

View File

@@ -996,7 +996,7 @@ proc newStrNode*(strVal: string; info: TLineInfo): PNode =
type
LogEntryKind* = enum
HookEntry, ConverterEntry, MethodEntry, EnumToStrEntry
HookEntry, ConverterEntry, MethodEntry, EnumToStrEntry, GenericInstEntry
LogEntry* = object
kind*: LogEntryKind
op*: TTypeAttachedOp

View File

@@ -3363,7 +3363,7 @@ proc genConstSetup(p: BProc; sym: PSym): bool =
useHeader(m, sym)
if sym.loc.k == locNone:
fillBackendName(p.module, sym)
ensureMutable sym
backendEnsureMutable sym
fillLoc(sym.locImpl, locData, sym.astdef, OnStatic)
if m.hcrOn: incl(sym, lfIndirect)
result = lfNoDecl notin sym.loc.flags

View File

@@ -451,6 +451,14 @@ proc addMethodToGeneric*(g: ModuleGraph; module: int; t: PType; col: int; m: PSy
let ownerModule = if t.sym != nil: t.sym.itemId.module.int else: module
g.opsLog.add LogEntry(kind: MethodEntry, module: ownerModule, key: key, sym: m)
proc logGenericInstance*(g: ModuleGraph; inst: PSym) =
## Log a generic instance so it gets written to the NIF file.
## This is needed when generic instances are created during compile-time
## evaluation and may be referenced from other modules compiled in the same run.
if g.config.cmd in {cmdNifC, cmdM}:
let ownerModule = inst.itemId.module.int
g.opsLog.add LogEntry(kind: GenericInstEntry, module: ownerModule, sym: inst)
proc hasDisabledAsgn*(g: ModuleGraph; t: PType): bool =
let op = getAttachedOp(g, t, attachedAsgn)
result = op != nil and sfError in op.flags
@@ -840,6 +848,8 @@ when not defined(nimKochBootstrap):
discard "todo"
of EnumToStrEntry:
discard "todo"
of GenericInstEntry:
raiseAssert "GenericInstEntry should not be in the NIF index"
# Register methods per type from NIF index
discard "todo"
cachedModules.add fileIdx

View File

@@ -450,6 +450,10 @@ proc generateInstance(c: PContext, fn: PSym, pt: LayeredIdTable,
entry.compilesId = c.compilesContextId
addToGenericProcCache(c, fn, entry)
c.generics.add(makeInstPair(fn, entry))
# Log the generic instance so it gets written to the NIF file.
# This is needed for cyclic module dependencies where generic instances
# may be created in one module but referenced from another.
logGenericInstance(c.graph, result)
# bug #12985 bug #22913
# TODO: use the context of the declaration of generic functions instead
# TODO: consider fixing options as well