explicit ID generation for easier IC (#15559)
* refactoring: idents don't need inheritance * refactoring: adding an IdGenerator (part 1) * refactoring: adding an IdGenerator (part 2) * refactoring: adding an IdGenerator (part 3) * refactoring: adding an IdGenerator (part 4) * refactoring: adding an IdGenerator (part 5) * refactoring: adding an IdGenerator (part 5) * IdGenerator must be a ref type; hello world works again * make bootstrapping work again * progress: add back the 'exactReplica' ideas * added back the missing exactReplica hacks * make tcompilerapi work again * make important packages green * attempt to fix the build for 32 bit machines (probably need a better solution here)
This commit is contained in:
parent
7252a50fef
commit
226595515c
67 changed files with 853 additions and 903 deletions
|
|
@ -24,8 +24,9 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): str
|
|||
localError(conf, info, "cannot open file: " & file)
|
||||
result = ""
|
||||
|
||||
proc atomicTypeX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo): PNode =
|
||||
let sym = newSym(skType, getIdent(cache, name), t.owner, info)
|
||||
proc atomicTypeX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo;
|
||||
idgen: IdGenerator): PNode =
|
||||
let sym = newSym(skType, getIdent(cache, name), nextId(idgen), t.owner, info)
|
||||
sym.magic = m
|
||||
sym.typ = t
|
||||
result = newSymNode(sym)
|
||||
|
|
@ -35,44 +36,46 @@ proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
|
|||
result = newSymNode(s)
|
||||
result.info = info
|
||||
|
||||
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGenerator;
|
||||
inst=false; allowRecursionX=false): PNode
|
||||
|
||||
proc mapTypeToBracketX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo;
|
||||
idgen: IdGenerator;
|
||||
inst=false): PNode =
|
||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||
result.add atomicTypeX(cache, name, m, t, info)
|
||||
result.add atomicTypeX(cache, name, m, t, info, idgen)
|
||||
for i in 0..<t.len:
|
||||
if t[i] == nil:
|
||||
let void = atomicTypeX(cache, "void", mVoid, t, info)
|
||||
void.typ = newType(tyVoid, t.owner)
|
||||
let void = atomicTypeX(cache, "void", mVoid, t, info, idgen)
|
||||
void.typ = newType(tyVoid, nextId(idgen), t.owner)
|
||||
result.add void
|
||||
else:
|
||||
result.add mapTypeToAstX(cache, t[i], info, inst)
|
||||
result.add mapTypeToAstX(cache, t[i], info, idgen, inst)
|
||||
|
||||
proc objectNode(cache: IdentCache; n: PNode): PNode =
|
||||
proc objectNode(cache: IdentCache; n: PNode; idgen: IdGenerator): PNode =
|
||||
if n.kind == nkSym:
|
||||
result = newNodeI(nkIdentDefs, n.info)
|
||||
result.add n # name
|
||||
result.add mapTypeToAstX(cache, n.sym.typ, n.info, true, false) # type
|
||||
result.add mapTypeToAstX(cache, n.sym.typ, n.info, idgen, true, false) # type
|
||||
result.add newNodeI(nkEmpty, n.info) # no assigned value
|
||||
else:
|
||||
result = copyNode(n)
|
||||
for i in 0..<n.safeLen:
|
||||
result.add objectNode(cache, n[i])
|
||||
result.add objectNode(cache, n[i], idgen)
|
||||
|
||||
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||
idgen: IdGenerator;
|
||||
inst=false; allowRecursionX=false): PNode =
|
||||
var allowRecursion = allowRecursionX
|
||||
template atomicType(name, m): untyped = atomicTypeX(cache, name, m, t, info)
|
||||
template atomicType(name, m): untyped = atomicTypeX(cache, name, m, t, info, idgen)
|
||||
template atomicType(s): untyped = atomicTypeX(s, info)
|
||||
template mapTypeToAst(t,info): untyped = mapTypeToAstX(cache, t, info, inst)
|
||||
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(cache, t, info, inst, true)
|
||||
template mapTypeToAst(t,info): untyped = mapTypeToAstX(cache, t, info, idgen, inst)
|
||||
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(cache, t, info, idgen, inst, true)
|
||||
template mapTypeToAst(t,i,info): untyped =
|
||||
if i<t.len and t[i]!=nil: mapTypeToAstX(cache, t[i], info, inst)
|
||||
if i<t.len and t[i]!=nil: mapTypeToAstX(cache, t[i], info, idgen, inst)
|
||||
else: newNodeI(nkEmpty, info)
|
||||
template mapTypeToBracket(name, m, t, info): untyped =
|
||||
mapTypeToBracketX(cache, name, m, t, info, inst)
|
||||
mapTypeToBracketX(cache, name, m, t, info, idgen, inst)
|
||||
template newNodeX(kind): untyped =
|
||||
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
|
||||
template newIdentDefs(n,t): untyped =
|
||||
|
|
@ -134,14 +137,14 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
|||
for i in 1..<t.len-1:
|
||||
result.add mapTypeToAst(t[i], info)
|
||||
else:
|
||||
result = mapTypeToAstX(cache, t.lastSon, info, inst, allowRecursion)
|
||||
result = mapTypeToAstX(cache, t.lastSon, info, idgen, inst, allowRecursion)
|
||||
of tyGenericBody:
|
||||
if inst:
|
||||
result = mapTypeToAstR(t.lastSon, info)
|
||||
else:
|
||||
result = mapTypeToAst(t.lastSon, info)
|
||||
of tyAlias:
|
||||
result = mapTypeToAstX(cache, t.lastSon, info, inst, allowRecursion)
|
||||
result = mapTypeToAstX(cache, t.lastSon, info, idgen, inst, allowRecursion)
|
||||
of tyOrdinal:
|
||||
result = mapTypeToAst(t.lastSon, info)
|
||||
of tyDistinct:
|
||||
|
|
@ -169,7 +172,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
|||
nn.add mapTypeToAst(t[0], info)
|
||||
result.add nn
|
||||
if t.n.len > 0:
|
||||
result.add objectNode(cache, t.n)
|
||||
result.add objectNode(cache, t.n, idgen)
|
||||
else:
|
||||
result.add newNodeI(nkEmpty, info)
|
||||
else:
|
||||
|
|
@ -298,15 +301,15 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
|||
of tyOwned: result = mapTypeToBracket("owned", mBuiltinType, t, info)
|
||||
of tyOptDeprecated: doAssert false
|
||||
|
||||
proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, inst=false, allowRecursionX=true)
|
||||
proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGenerator): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, idgen, inst=false, allowRecursionX=true)
|
||||
|
||||
# the "Inst" version includes generic parameters in the resulting type tree
|
||||
# and also tries to look like the corresponding Nim type declaration
|
||||
proc opMapTypeInstToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, inst=true, allowRecursionX=false)
|
||||
proc opMapTypeInstToAst*(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGenerator): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, idgen, inst=true, allowRecursionX=false)
|
||||
|
||||
# the "Impl" version includes generic parameters in the resulting type tree
|
||||
# and also tries to look like the corresponding Nim type implementation
|
||||
proc opMapTypeImplToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, inst=true, allowRecursionX=true)
|
||||
proc opMapTypeImplToAst*(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGenerator): PNode =
|
||||
result = mapTypeToAstX(cache, t, info, idgen, inst=true, allowRecursionX=true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue