saves/loads PSym.ast, constraint and instantiatedFrom

This commit is contained in:
demotomohiro
2025-11-01 23:05:41 +09:00
parent 5f3be1e991
commit ab13900fad
3 changed files with 17 additions and 0 deletions

View File

@@ -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 =

View File

@@ -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) =

View File

@@ -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())