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:
Andreas Rumpf 2020-10-25 08:50:47 +01:00 • committed by GitHub
commit 226595515c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 853 additions and 903 deletions

View file

@ -136,7 +136,8 @@ proc storeAny*(s: var string; t: PType; a: PNode; conf: ConfigRef) =
proc loadAny(p: var JsonParser, t: PType,
tab: var Table[BiggestInt, PNode];
cache: IdentCache;
conf: ConfigRef): PNode =
conf: ConfigRef;
idgen: IdGenerator): PNode =
case t.kind
of tyNone: assert false
of tyBool:
@ -170,7 +171,7 @@ proc loadAny(p: var JsonParser, t: PType,
next(p)
result = newNode(nkBracket)
while p.kind != jsonArrayEnd and p.kind != jsonEof:
result.add loadAny(p, t.elemType, tab, cache, conf)
result.add loadAny(p, t.elemType, tab, cache, conf, idgen)
if p.kind == jsonArrayEnd: next(p)
else: raiseParseErr(p, "']' end of array expected")
of tySequence:
@ -182,7 +183,7 @@ proc loadAny(p: var JsonParser, t: PType,
next(p)
result = newNode(nkBracket)
while p.kind != jsonArrayEnd and p.kind != jsonEof:
result.add loadAny(p, t.elemType, tab, cache, conf)
result.add loadAny(p, t.elemType, tab, cache, conf, idgen)
if p.kind == jsonArrayEnd: next(p)
else: raiseParseErr(p, "")
else:
@ -198,7 +199,7 @@ proc loadAny(p: var JsonParser, t: PType,
next(p)
if i >= t.len:
raiseParseErr(p, "too many fields to tuple type " & typeToString(t))
result.add loadAny(p, t[i], tab, cache, conf)
result.add loadAny(p, t[i], tab, cache, conf, idgen)
inc i
if p.kind == jsonObjectEnd: next(p)
else: raiseParseErr(p, "'}' end of object expected")
@ -219,8 +220,8 @@ proc loadAny(p: var JsonParser, t: PType,
if pos >= result.len:
setLen(result.sons, pos + 1)
let fieldNode = newNode(nkExprColonExpr)
fieldNode.add newSymNode(newSym(skField, ident, nil, unknownLineInfo))
fieldNode.add loadAny(p, field.typ, tab, cache, conf)
fieldNode.add newSymNode(newSym(skField, ident, nextId(idgen), nil, unknownLineInfo))
fieldNode.add loadAny(p, field.typ, tab, cache, conf, idgen)
result[pos] = fieldNode
if p.kind == jsonObjectEnd: next(p)
else: raiseParseErr(p, "'}' end of object expected")
@ -229,7 +230,7 @@ proc loadAny(p: var JsonParser, t: PType,
next(p)
result = newNode(nkCurly)
while p.kind != jsonArrayEnd and p.kind != jsonEof:
result.add loadAny(p, t.lastSon, tab, cache, conf)
result.add loadAny(p, t.lastSon, tab, cache, conf, idgen)
next(p)
if p.kind == jsonArrayEnd: next(p)
else: raiseParseErr(p, "']' end of array expected")
@ -248,7 +249,7 @@ proc loadAny(p: var JsonParser, t: PType,
if p.kind == jsonInt:
let idx = p.getInt
next(p)
result = loadAny(p, t.lastSon, tab, cache, conf)
result = loadAny(p, t.lastSon, tab, cache, conf, idgen)
tab[idx] = result
else: raiseParseErr(p, "index for ref type expected")
if p.kind == jsonArrayEnd: next(p)
@ -276,14 +277,14 @@ proc loadAny(p: var JsonParser, t: PType,
return
raiseParseErr(p, "float expected")
of tyRange, tyGenericInst, tyAlias, tySink:
result = loadAny(p, t.lastSon, tab, cache, conf)
result = loadAny(p, t.lastSon, tab, cache, conf, idgen)
else:
internalError conf, "cannot marshal at compile-time " & t.typeToString
proc loadAny*(s: string; t: PType; cache: IdentCache; conf: ConfigRef): PNode =
proc loadAny*(s: string; t: PType; cache: IdentCache; conf: ConfigRef; idgen: IdGenerator): PNode =
var tab = initTable[BiggestInt, PNode]()
var p: JsonParser
open(p, newStringStream(s), "unknown file")
next(p)
result = loadAny(p, t, tab, cache, conf)
result = loadAny(p, t, tab, cache, conf, idgen)
close(p)