From ab13900fadb7e77e133708a1e8d5c3761906f255 Mon Sep 17 00:00:00 2001 From: demotomohiro Date: Sat, 1 Nov 2025 23:05:41 +0900 Subject: [PATCH] saves/loads PSym.ast, constraint and instantiatedFrom --- compiler/icnif/nifdecoder.nim | 3 +++ compiler/icnif/nifencoder.nim | 3 +++ tests/icnif/tencode_node2node.nim | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/compiler/icnif/nifdecoder.nim b/compiler/icnif/nifdecoder.nim index 0203b6e37d..6c5e8b7834 100644 --- a/compiler/icnif/nifdecoder.nim +++ b/compiler/icnif/nifdecoder.nim @@ -149,12 +149,15 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym = result.typ = c.fromNifType n result.setOwner(c.fromNifSymbol n) + result.ast = c.fromNif n expect n, Ident result.loc.k = pool.strings[n.litId].parseLocKind() incExpect n, StringLit result.loc.snippet.add pool.strings[n.litId] inc n + result.constraint = c.fromNif n + result.instantiatedFrom = c.fromNifSymbol n skipParRi n proc fromNifTypeDef(c: var DecodeContext; n: var Cursor): PType = diff --git a/compiler/icnif/nifencoder.nim b/compiler/icnif/nifencoder.nim index 78e9951f70..eec6cab689 100644 --- a/compiler/icnif/nifencoder.nim +++ b/compiler/icnif/nifencoder.nim @@ -81,8 +81,11 @@ proc toNifDef(c: var EncodeContext; sym: PSym) = c.dest.addIntLit sym.position c.toNif sym.typ c.toNif sym.owner + c.toNif sym.ast # drastically increase output NIF size! c.dest.addIdent toNifTag(sym.loc.k) c.dest.addStrLit sym.loc.snippet + c.toNif sym.constraint + c.toNif sym.instantiatedFrom c.dest.addParRi proc toNifDef(c: var EncodeContext; typ: PType) = diff --git a/tests/icnif/tencode_node2node.nim b/tests/icnif/tencode_node2node.nim index 2ff7db2598..95923a20c0 100644 --- a/tests/icnif/tencode_node2node.nim +++ b/tests/icnif/tencode_node2node.nim @@ -185,6 +185,15 @@ proc eql(x, y: PSym; c: var EqlContext): bool = debug(x.owner) debug(y.owner) result = false + elif not eql(x.ast, y.ast, c): + echo "symbol ast mismatch" + result = false + elif not eql(x.constraint, y.constraint, c): + echo "symbol constraint mismatch" + result = false + elif not eql(x.instantiatedFrom, y.instantiatedFrom, c): + echo "symbol instantiatedFrom mismatch" + result = false else: if x.kind in {skLet, skVar, skField, skForVar}: if not eql(x.guard, y.guard, c): @@ -338,6 +347,8 @@ proc testNifEncDec(graph: ModuleGraph; src: string) = #debug(n) let nif = saveNifToBuffer(n, graph.config) #echo nif + #echo "NIF size of ", src, ": ", nif.len + #writeFile(src & ".nif", nif) # Don't reuse the ModuleGraph used for semcheck when load NIF. var graphForLoad = newModuleGraph(newIdentCache(), newConfigRefForTest())