avoid unsafe Nim features in preparation for --gc:arc (#14431)
This commit is contained in:
parent
6668b43409
commit
c61f746629
2 changed files with 17 additions and 16 deletions
|
|
@ -178,13 +178,13 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType,
|
||||||
internalAssert c.config, header.kind == tyGenericInvocation
|
internalAssert c.config, header.kind == tyGenericInvocation
|
||||||
|
|
||||||
var
|
var
|
||||||
typeMap: LayeredIdTable
|
|
||||||
cl: TReplTypeVars
|
cl: TReplTypeVars
|
||||||
|
|
||||||
initIdTable(cl.symMap)
|
initIdTable(cl.symMap)
|
||||||
initIdTable(cl.localCache)
|
initIdTable(cl.localCache)
|
||||||
initIdTable(typeMap.topLayer)
|
cl.typeMap = LayeredIdTable()
|
||||||
cl.typeMap = addr(typeMap)
|
initIdTable(cl.typeMap.topLayer)
|
||||||
|
|
||||||
cl.info = info
|
cl.info = info
|
||||||
cl.c = c
|
cl.c = c
|
||||||
cl.allowMetaTypes = allowMetaTypes
|
cl.allowMetaTypes = allowMetaTypes
|
||||||
|
|
@ -244,7 +244,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
#addDecl(c, prc)
|
#addDecl(c, prc)
|
||||||
pushInfoContext(c.config, info)
|
pushInfoContext(c.config, info)
|
||||||
var typeMap = initLayeredTypeMap(pt)
|
var typeMap = initLayeredTypeMap(pt)
|
||||||
var cl = initTypeVars(c, addr(typeMap), info, nil)
|
var cl = initTypeVars(c, typeMap, info, nil)
|
||||||
var result = instCopyType(cl, prc.typ)
|
var result = instCopyType(cl, prc.typ)
|
||||||
let originalParams = result.n
|
let originalParams = result.n
|
||||||
result.n = originalParams.shallowCopy
|
result.n = originalParams.shallowCopy
|
||||||
|
|
|
||||||
|
|
@ -68,13 +68,13 @@ proc cacheTypeInst*(inst: PType) =
|
||||||
gt.sym.typeInstCache.add(inst)
|
gt.sym.typeInstCache.add(inst)
|
||||||
|
|
||||||
type
|
type
|
||||||
LayeredIdTable* = object
|
LayeredIdTable* = ref object
|
||||||
topLayer*: TIdTable
|
topLayer*: TIdTable
|
||||||
nextLayer*: ptr LayeredIdTable
|
nextLayer*: LayeredIdTable
|
||||||
|
|
||||||
TReplTypeVars* = object
|
TReplTypeVars* = object
|
||||||
c*: PContext
|
c*: PContext
|
||||||
typeMap*: ptr LayeredIdTable # map PType to PType
|
typeMap*: LayeredIdTable # map PType to PType
|
||||||
symMap*: TIdTable # map PSym to PSym
|
symMap*: TIdTable # map PSym to PSym
|
||||||
localCache*: TIdTable # local cache for remembering already replaced
|
localCache*: TIdTable # local cache for remembering already replaced
|
||||||
# types during instantiation of meta types
|
# types during instantiation of meta types
|
||||||
|
|
@ -92,20 +92,22 @@ proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym
|
||||||
proc replaceTypeVarsN*(cl: var TReplTypeVars, n: PNode; start=0): PNode
|
proc replaceTypeVarsN*(cl: var TReplTypeVars, n: PNode; start=0): PNode
|
||||||
|
|
||||||
proc initLayeredTypeMap*(pt: TIdTable): LayeredIdTable =
|
proc initLayeredTypeMap*(pt: TIdTable): LayeredIdTable =
|
||||||
|
result = LayeredIdTable()
|
||||||
copyIdTable(result.topLayer, pt)
|
copyIdTable(result.topLayer, pt)
|
||||||
|
|
||||||
proc newTypeMapLayer*(cl: var TReplTypeVars): LayeredIdTable =
|
proc newTypeMapLayer*(cl: var TReplTypeVars): LayeredIdTable =
|
||||||
|
result = LayeredIdTable()
|
||||||
result.nextLayer = cl.typeMap
|
result.nextLayer = cl.typeMap
|
||||||
initIdTable(result.topLayer)
|
initIdTable(result.topLayer)
|
||||||
|
|
||||||
proc lookup(typeMap: ptr LayeredIdTable, key: PType): PType =
|
proc lookup(typeMap: LayeredIdTable, key: PType): PType =
|
||||||
var tm = typeMap
|
var tm = typeMap
|
||||||
while tm != nil:
|
while tm != nil:
|
||||||
result = PType(idTableGet(tm.topLayer, key))
|
result = PType(idTableGet(tm.topLayer, key))
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
tm = tm.nextLayer
|
tm = tm.nextLayer
|
||||||
|
|
||||||
template put(typeMap: ptr LayeredIdTable, key, value: PType) =
|
template put(typeMap: LayeredIdTable, key, value: PType) =
|
||||||
idTablePut(typeMap.topLayer, key, value)
|
idTablePut(typeMap.topLayer, key, value)
|
||||||
|
|
||||||
template checkMetaInvariants(cl: TReplTypeVars, t: PType) =
|
template checkMetaInvariants(cl: TReplTypeVars, t: PType) =
|
||||||
|
|
@ -369,8 +371,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
let oldSkipTypedesc = cl.skipTypedesc
|
let oldSkipTypedesc = cl.skipTypedesc
|
||||||
cl.skipTypedesc = true
|
cl.skipTypedesc = true
|
||||||
|
|
||||||
var typeMapLayer = newTypeMapLayer(cl)
|
cl.typeMap = newTypeMapLayer(cl)
|
||||||
cl.typeMap = addr(typeMapLayer)
|
|
||||||
|
|
||||||
for i in 1..<t.len:
|
for i in 1..<t.len:
|
||||||
var x = replaceTypeVarsT(cl, t[i])
|
var x = replaceTypeVarsT(cl, t[i])
|
||||||
|
|
@ -652,7 +653,7 @@ proc instAllTypeBoundOp*(c: PContext, info: TLineInfo) =
|
||||||
inc i
|
inc i
|
||||||
setLen(c.typesWithOps, 0)
|
setLen(c.typesWithOps, 0)
|
||||||
|
|
||||||
proc initTypeVars*(p: PContext, typeMap: ptr LayeredIdTable, info: TLineInfo;
|
proc initTypeVars*(p: PContext, typeMap: LayeredIdTable, info: TLineInfo;
|
||||||
owner: PSym): TReplTypeVars =
|
owner: PSym): TReplTypeVars =
|
||||||
initIdTable(result.symMap)
|
initIdTable(result.symMap)
|
||||||
initIdTable(result.localCache)
|
initIdTable(result.localCache)
|
||||||
|
|
@ -664,7 +665,7 @@ proc initTypeVars*(p: PContext, typeMap: ptr LayeredIdTable, info: TLineInfo;
|
||||||
proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode;
|
proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode;
|
||||||
owner: PSym, allowMetaTypes = false): PNode =
|
owner: PSym, allowMetaTypes = false): PNode =
|
||||||
var typeMap = initLayeredTypeMap(pt)
|
var typeMap = initLayeredTypeMap(pt)
|
||||||
var cl = initTypeVars(p, addr(typeMap), n.info, owner)
|
var cl = initTypeVars(p, typeMap, n.info, owner)
|
||||||
cl.allowMetaTypes = allowMetaTypes
|
cl.allowMetaTypes = allowMetaTypes
|
||||||
pushInfoContext(p.config, n.info)
|
pushInfoContext(p.config, n.info)
|
||||||
result = replaceTypeVarsN(cl, n)
|
result = replaceTypeVarsN(cl, n)
|
||||||
|
|
@ -673,7 +674,7 @@ proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode;
|
||||||
proc replaceTypesForLambda*(p: PContext, pt: TIdTable, n: PNode;
|
proc replaceTypesForLambda*(p: PContext, pt: TIdTable, n: PNode;
|
||||||
original, new: PSym): PNode =
|
original, new: PSym): PNode =
|
||||||
var typeMap = initLayeredTypeMap(pt)
|
var typeMap = initLayeredTypeMap(pt)
|
||||||
var cl = initTypeVars(p, addr(typeMap), n.info, original)
|
var cl = initTypeVars(p, typeMap, n.info, original)
|
||||||
idTablePut(cl.symMap, original, new)
|
idTablePut(cl.symMap, original, new)
|
||||||
pushInfoContext(p.config, n.info)
|
pushInfoContext(p.config, n.info)
|
||||||
result = replaceTypeVarsN(cl, n)
|
result = replaceTypeVarsN(cl, n)
|
||||||
|
|
@ -702,7 +703,7 @@ proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
|
||||||
# Desired result: Foo[int]
|
# Desired result: Foo[int]
|
||||||
# proc (x: T = 0); T -> int ----> proc (x: int = 0)
|
# proc (x: T = 0); T -> int ----> proc (x: int = 0)
|
||||||
var typeMap = initLayeredTypeMap(pt)
|
var typeMap = initLayeredTypeMap(pt)
|
||||||
var cl = initTypeVars(p, addr(typeMap), info, nil)
|
var cl = initTypeVars(p, typeMap, info, nil)
|
||||||
pushInfoContext(p.config, info)
|
pushInfoContext(p.config, info)
|
||||||
result = replaceTypeVarsT(cl, t)
|
result = replaceTypeVarsT(cl, t)
|
||||||
popInfoContext(p.config)
|
popInfoContext(p.config)
|
||||||
|
|
@ -714,7 +715,7 @@ proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
|
||||||
proc prepareMetatypeForSigmatch*(p: PContext, pt: TIdTable, info: TLineInfo,
|
proc prepareMetatypeForSigmatch*(p: PContext, pt: TIdTable, info: TLineInfo,
|
||||||
t: PType): PType =
|
t: PType): PType =
|
||||||
var typeMap = initLayeredTypeMap(pt)
|
var typeMap = initLayeredTypeMap(pt)
|
||||||
var cl = initTypeVars(p, addr(typeMap), info, nil)
|
var cl = initTypeVars(p, typeMap, info, nil)
|
||||||
cl.allowMetaTypes = true
|
cl.allowMetaTypes = true
|
||||||
pushInfoContext(p.config, info)
|
pushInfoContext(p.config, info)
|
||||||
result = replaceTypeVarsT(cl, t)
|
result = replaceTypeVarsT(cl, t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue