diff --git a/compiler/ast.nim b/compiler/ast.nim index c165a7cfb7..97334013fd 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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 diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index 9daffb83df..0b89dad2cc 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -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 diff --git a/compiler/astdef.nim b/compiler/astdef.nim index e057e8d3bf..fb32178223 100644 --- a/compiler/astdef.nim +++ b/compiler/astdef.nim @@ -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