Skip to content

Commit b48513b

Browse files
committed
saves/loads PSym.ast, constraint and instantiatedFrom
1 parent efbbfff commit b48513b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/icnif/nifdecoder.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym =
149149

150150
result.typ = c.fromNifType n
151151
result.setOwner(c.fromNifSymbol n)
152+
result.ast = c.fromNif n
152153

153154
expect n, Ident
154155
result.loc.k = pool.strings[n.litId].parseLocKind()
155156
incExpect n, StringLit
156157
result.loc.snippet.add pool.strings[n.litId]
157158
inc n
159+
result.constraint = c.fromNif n
160+
result.instantiatedFrom = c.fromNifSymbol n
158161
skipParRi n
159162

160163
proc fromNifTypeDef(c: var DecodeContext; n: var Cursor): PType =

compiler/icnif/nifencoder.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ proc toNifDef(c: var EncodeContext; sym: PSym) =
8181
c.dest.addIntLit sym.position
8282
c.toNif sym.typ
8383
c.toNif sym.owner
84+
c.toNif sym.ast # drastically increase output NIF size!
8485
c.dest.addIdent toNifTag(sym.loc.k)
8586
c.dest.addStrLit sym.loc.snippet
87+
c.toNif sym.constraint
88+
c.toNif sym.instantiatedFrom
8689
c.dest.addParRi
8790

8891
proc toNifDef(c: var EncodeContext; typ: PType) =

tests/icnif/tencode_node2node.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ proc eql(x, y: PSym; c: var EqlContext): bool =
185185
debug(x.owner)
186186
debug(y.owner)
187187
result = false
188+
elif not eql(x.ast, y.ast, c):
189+
echo "symbol ast mismatch"
190+
result = false
191+
elif not eql(x.constraint, y.constraint, c):
192+
echo "symbol constraint mismatch"
193+
result = false
194+
elif not eql(x.instantiatedFrom, y.instantiatedFrom, c):
195+
echo "symbol instantiatedFrom mismatch"
196+
result = false
188197
else:
189198
if x.kind in {skLet, skVar, skField, skForVar}:
190199
if not eql(x.guard, y.guard, c):
@@ -338,6 +347,8 @@ proc testNifEncDec(graph: ModuleGraph; src: string) =
338347
#debug(n)
339348
let nif = saveNifToBuffer(n, graph.config)
340349
#echo nif
350+
#echo "NIF size of ", src, ": ", nif.len
351+
#writeFile(src & ".nif", nif)
341352

342353
# Don't reuse the ModuleGraph used for semcheck when load NIF.
343354
var graphForLoad = newModuleGraph(newIdentCache(), newConfigRefForTest())

0 commit comments

Comments
 (0)