This commit is contained in:
Araq
2025-11-12 14:04:33 +01:00
parent 9039ab4a3e
commit 99d8669971
3 changed files with 59 additions and 52 deletions

View File

@@ -1618,54 +1618,3 @@ type
template initSymMapping*(): SymMapping = initIdTable[PSym]()
template initTypeMapping*(): TypeMapping = initIdTable[PType]()
proc forcePartial*(s: PSym) =
## Resets all impl-fields to their default values and sets state to Partial.
## This is useful for creating a stub symbol that can be lazily loaded later.
## The fields itemId, name, and disamb are preserved.
s.state = Partial
case s.kindImpl
of routineKinds:
s.gcUnsafetyReasonImpl = nil
s.transformedBodyImpl = nil
of skLet, skVar, skField, skForVar:
s.guardImpl = nil
s.bitsizeImpl = 0
s.alignmentImpl = 0 # for alignment
else: discard
s.magicImpl = mNone
s.typImpl = nil
s.infoImpl = unknownLineInfo
s.ownerFieldImpl = nil
s.flagsImpl = {}
s.astImpl = nil
s.optionsImpl = {}
s.positionImpl = 0
s.offsetImpl = 0
s.locImpl = TLoc()
s.annexImpl = nil
s.constraintImpl = nil
s.instantiatedFromImpl = nil
when defined(nimsuggest):
s.endInfoImpl = unknownLineInfo
s.hasUserSpecifiedTypeImpl = false
s.allUsagesImpl = @[]
when hasFFI:
s.cnameImpl = ""
proc forcePartial*(t: PType) =
## Resets all impl-fields to their default values and sets state to Partial.
## This is useful for creating a stub type that can be lazily loaded later.
## The fields itemId, kind, uniqueId are preserved.
t.state = Partial
t.callConvImpl = ccNimCall
t.flagsImpl = {}
t.sonsImpl = @[]
t.nImpl = nil
t.ownerFieldImpl = nil
t.symImpl = nil
t.sizeImpl = defaultSize
t.alignImpl = defaultAlignment
t.paddingAtEndImpl = 0'i16
t.locImpl = TLoc()
t.typeInstImpl = nil

View File

@@ -305,6 +305,7 @@ proc writeSymNode(w: var Writer; dest: var TokenBuf; n: PNode; sym: PSym) =
sym.state = Sealed
if n.typField != n.sym.typImpl:
dest.buildTree hiddenTypeTag, trLineInfo(w, n.info):
writeType(w, dest, n.typField)
writeSymDef(w, dest, sym)
else:
writeSymDef(w, dest, sym)
@@ -314,6 +315,7 @@ proc writeSymNode(w: var Writer; dest: var TokenBuf; n: PNode; sym: PSym) =
let info = trLineInfo(w, n.info)
if n.typField != n.sym.typImpl:
dest.buildTree hiddenTypeTag, info:
writeType(w, dest, n.typField)
dest.addSymUse pool.syms.getOrIncl(w.toNifSymName(sym)), info
else:
dest.addSymUse pool.syms.getOrIncl(w.toNifSymName(sym)), info
@@ -807,7 +809,12 @@ proc loadNode(c: var DecodeContext; n: var Cursor): PNode =
# special NIF introduced tag?
case pool.tags[n.tagId]
of hiddenTypeTagName:
discard
inc n
let typ = c.loadTypeStub n
let info = c.infos.oldLineInfo(n.info)
result = newSymNode(c.loadSymStub n, info)
result.typField = typ
skipParRi n
of symDefTagName:
let name = n.firstSon
assert name.kind == SymbolDef

View File

@@ -980,3 +980,54 @@ proc newSymNode*(sym: PSym, info: TLineInfo): PNode =
result.sym = sym
result.typField = sym.typImpl
result.info = info
proc forcePartial*(s: PSym) =
## Resets all impl-fields to their default values and sets state to Partial.
## This is useful for creating a stub symbol that can be lazily loaded later.
## The fields itemId, name, and disamb are preserved.
s.state = Partial
case s.kindImpl
of routineKinds:
s.gcUnsafetyReasonImpl = nil
s.transformedBodyImpl = nil
of skLet, skVar, skField, skForVar:
s.guardImpl = nil
s.bitsizeImpl = 0
s.alignmentImpl = 0 # for alignment
else: discard
s.magicImpl = mNone
s.typImpl = nil
s.infoImpl = unknownLineInfo
s.ownerFieldImpl = nil
s.flagsImpl = {}
s.astImpl = nil
s.optionsImpl = {}
s.positionImpl = 0
s.offsetImpl = 0
s.locImpl = TLoc()
s.annexImpl = nil
s.constraintImpl = nil
s.instantiatedFromImpl = nil
when defined(nimsuggest):
s.endInfoImpl = unknownLineInfo
s.hasUserSpecifiedTypeImpl = false
s.allUsagesImpl = @[]
when hasFFI:
s.cnameImpl = ""
proc forcePartial*(t: PType) =
## Resets all impl-fields to their default values and sets state to Partial.
## This is useful for creating a stub type that can be lazily loaded later.
## The fields itemId, kind, uniqueId are preserved.
t.state = Partial
t.callConvImpl = ccNimCall
t.flagsImpl = {}
t.sonsImpl = @[]
t.nImpl = nil
t.ownerFieldImpl = nil
t.symImpl = nil
t.sizeImpl = defaultSize
t.alignImpl = defaultAlignment
t.paddingAtEndImpl = 0'i16
t.locImpl = TLoc()
t.typeInstImpl = nil