Skip to content

Commit a78dd18

Browse files
committed
wip
1 parent 07819df commit a78dd18

File tree

5 files changed

+36
-42
lines changed

5 files changed

+36
-42
lines changed

compiler/ast2nif.nim

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,26 @@ proc buildExportBuf(w: var Writer): TokenBuf =
664664
result.add identToken(pool.strings.getOrIncl(name), NoLineInfo)
665665
result.addParRi()
666666

667+
proc translateOpsLog(w: var Writer; opsLog: seq[LogEntry]): IndexSections =
668+
result = IndexSections(hooks: default array[AttachedOp, seq[HookIndexEntry]], converters: @[], classes: @[])
669+
for entry in opsLog:
670+
let key = pool.syms.getOrIncl(entry.typ.typeKey(w.infos.config))
671+
let sym = pool.syms.getOrIncl(w.toNifSymName(entry.sym))
672+
case entry.kind
673+
of HookEntry:
674+
result.hooks[toAttachedOp(entry.op)].add HookIndexEntry(isGeneric: entry.isGeneric, typ: key, hook: sym)
675+
of ConverterEntry:
676+
result.converters.add (key, sym)
677+
of MethodEntry:
678+
discard "to implement"
679+
of EnumToStrEntry:
680+
discard "to implement"
681+
682+
667683
let replayTag = registerTag("replay")
668684

669685
proc writeNifModule*(config: ConfigRef; thisModule: int32; n: PNode;
670-
hooks: array[AttachedOp, seq[HookIndexEntry]];
671-
converters: seq[(nifstreams.SymId, nifstreams.SymId)];
686+
opsLog: seq[LogEntry];
672687
classes: seq[ClassIndexEntry];
673688
replayActions: seq[PNode] = @[]) =
674689
var w = Writer(infos: LineInfoWriter(config: config), currentModule: thisModule)
@@ -702,17 +717,9 @@ proc writeNifModule*(config: ConfigRef; thisModule: int32; n: PNode;
702717

703718
# Build index with export, hook, converter, and method information
704719
let exportBuf = buildExportBuf(w)
705-
createIndex(d, dest[0].info, false,
706-
IndexSections(hooks: hooks, converters: converters, classes: classes, exportBuf: exportBuf))
707-
708-
# Don't unload symbols/types yet - they may be needed by other modules that haven't
709-
# had their NIF files written. For recursive module dependencies (like system.nim),
710-
# we need all NIFs to exist before we can safely unload and reload.
711-
# TODO: Implement deferred unloading at end of compilation for memory savings.
712-
#for typ in w.writtenTypes:
713-
# forcePartial(typ)
714-
#for sym in w.writtenSyms:
715-
# forcePartial(sym)
720+
var sections = translateOpsLog(w, opsLog)
721+
sections.exportBuf = exportBuf
722+
createIndex(d, dest[0].info, false, sections)
716723

717724

718725
# --------------------------- Loader (lazy!) -----------------------------------------------
@@ -1443,8 +1450,7 @@ proc tryResolveCompilerProc*(c: var DecodeContext; name: string; moduleFileIdx:
14431450
result = resolveSym(c, symName, true)
14441451

14451452
proc loadNifModule*(c: var DecodeContext; f: FileIndex; interf, interfHidden: var TStrTable;
1446-
hooks: var Table[nifstreams.SymId, HooksPerType];
1447-
converters: var seq[(string, string)];
1453+
logOps: var seq[LogEntry];
14481454
classes: var seq[ClassIndexEntry];
14491455
loadFullAst: bool = false): PNode =
14501456
let suffix = moduleSuffix(c.infos.config, f)

compiler/astdef.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ type
10001000
LogEntry* = object
10011001
kind*: LogEntryKind
10021002
op*: TTypeAttachedOp
1003+
isGeneric*: bool
10031004
typ*: PType
10041005
sym*: PSym
10051006

compiler/modulegraphs.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ proc getAttachedOp*(g: ModuleGraph; t: PType; op: TTypeAttachedOp): PSym =
367367

368368
proc setAttachedOp*(g: ModuleGraph; module: int; t: PType; op: TTypeAttachedOp; value: PSym) =
369369
## we also need to record this to the packed module.
370+
if not g.attachedOps[op].contains(t.itemId):
371+
g.opsLog.add LogEntry(kind: HookEntry, op: op, typ: t, sym: value)
370372
g.attachedOps[op][t.itemId] = LazySym(sym: value)
371-
g.opsLog.add LogEntry(kind: HookEntry, op: op, typ: t, sym: value)
372373

373374
proc setAttachedOp*(g: ModuleGraph; module: int; typeId: ItemId; op: TTypeAttachedOp; value: PSym) =
374375
## Overload that takes ItemId directly, useful for registering hooks from NIF index.
@@ -780,6 +781,10 @@ proc moduleFromRodFile*(g: ModuleGraph; fileIdx: FileIndex;
780781
else:
781782
result = nil
782783

784+
proc processLogOps*(g: ModuleGraph; logOps: seq[LogEntry]) =
785+
for x in logOps:
786+
discard
787+
783788
when not defined(nimKochBootstrap):
784789
proc moduleFromNifFile*(g: ModuleGraph; fileIdx: FileIndex;
785790
cachedModules: var seq[FileIndex];

compiler/pipelines.nim

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,6 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator
254254
for (m, n) in PCtx(graph.vm).vmstateDiff:
255255
if m == module:
256256
replayActions.add n
257-
# Collect hooks from the module graph for the current module
258-
var hooks = default array[AttachedOp, seq[HookIndexEntry]]
259-
for op in TTypeAttachedOp:
260-
if op == attachedDeepCopy: continue # Not supported in nimony
261-
let nimonyOp = toAttachedOp(op)
262-
for typeId, lazySym in graph.attachedOps[op]:
263-
if typeId.module == module.position.int32:
264-
let sym = lazySym.sym
265-
if sym != nil:
266-
hooks[nimonyOp].add toHookIndexEntry(graph.config, typeId, sym)
267-
# Collect converters from the module's interface
268-
var converters: seq[(nifstreams.SymId, nifstreams.SymId)] = @[]
269-
for lazySym in graph.ifaces[module.position].converters:
270-
let sym = lazySym.sym
271-
if sym != nil:
272-
let entry = toConverterIndexEntry(graph.config, sym)
273-
if entry[0] != nifstreams.SymId(0):
274-
converters.add entry
275257
# Collect methods per type for classes
276258
var classes: seq[ClassIndexEntry] = @[]
277259
for typeId, methodList in graph.methodsPerType:
@@ -288,7 +270,7 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator
288270
cls: toClassSymId(graph.config, typeId),
289271
methods: methods
290272
)
291-
writeNifModule(graph.config, module.position.int32, topLevelStmts, hooks, converters, classes, replayActions)
273+
writeNifModule(graph.config, module.position.int32, topLevelStmts, move(graph.opsLog), classes, replayActions)
292274

293275
if graph.config.backend notin {backendC, backendCpp, backendObjc} and graph.config.cmd != cmdM:
294276
# We only write rod files here if no C-like backend is active.

lib/system.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ else:
390390
## Generic `destructor`:idx: implementation that can be overridden.
391391
discard
392392

393-
when defined(nimAllowNonVarDestructor) and arcLikeMem:
394-
proc `=destroy`*(x: string) {.inline, magic: "Destroy", enforceNoRaises.} =
395-
discard
393+
when defined(nimAllowNonVarDestructor) and arcLikeMem:
394+
proc `=destroy`*(x: string) {.inline, magic: "Destroy", enforceNoRaises.} =
395+
discard
396396

397-
proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} =
398-
discard
397+
proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} =
398+
discard
399399

400-
proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} =
401-
discard
400+
proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} =
401+
discard
402402

403403
when defined(nimHasDup):
404404
proc `=dup`*[T](x: T): T {.inline, magic: "Dup".} =

0 commit comments

Comments
 (0)