IC: further progress

This commit is contained in:
Araq 2018-12-01 00:36:01 +01:00
commit abbafe606e
8 changed files with 60 additions and 33 deletions

View file

@ -898,6 +898,8 @@ type
loc*: TLoc loc*: TLoc
typeInst*: PType # for generic instantiations the tyGenericInst that led to this typeInst*: PType # for generic instantiations the tyGenericInst that led to this
# type. # type.
uniqueId*: int # due to a design mistake, we need to keep the real ID here as it
# required by the --incremental:on mode.
TPair* = object TPair* = object
key*, val*: RootRef key*, val*: RootRef
@ -1268,6 +1270,7 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
result.size = -1 result.size = -1
result.align = -1 # default alignment result.align = -1 # default alignment
result.id = getID() result.id = getID()
result.uniqueId = result.id
result.lockLevel = UnspecifiedLockLevel result.lockLevel = UnspecifiedLockLevel
when debugIds: when debugIds:
registerId(result) registerId(result)
@ -1341,15 +1344,12 @@ proc copyType*(t: PType, owner: PSym, keepId: bool): PType =
proc exactReplica*(t: PType): PType = copyType(t, t.owner, true) proc exactReplica*(t: PType): PType = copyType(t, t.owner, true)
proc copySym*(s: PSym, keepId: bool = false): PSym = proc copySym*(s: PSym): PSym =
result = newSym(s.kind, s.name, s.owner, s.info, s.options) result = newSym(s.kind, s.name, s.owner, s.info, s.options)
#result.ast = nil # BUGFIX; was: s.ast which made problems #result.ast = nil # BUGFIX; was: s.ast which made problems
result.typ = s.typ result.typ = s.typ
if keepId: result.id = getID()
result.id = s.id when debugIds: registerId(result)
else:
result.id = getID()
when debugIds: registerId(result)
result.flags = s.flags result.flags = s.flags
result.magic = s.magic result.magic = s.magic
if s.kind == skModule: if s.kind == skModule:

View file

@ -254,21 +254,26 @@ proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet, indent: int,
if n == nil: if n == nil:
result = rope("null") result = rope("null")
elif containsOrIncl(marker, n.id): elif containsOrIncl(marker, n.id):
result = "\"$1 @$2\"" % [rope(n.name.s), rope( result = "\"$1\"" % [rope(n.name.s)]
strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))]
else: else:
var ast = treeToYamlAux(conf, n.ast, marker, indent + 2, maxRecDepth - 1) var ast = treeToYamlAux(conf, n.ast, marker, indent + 2, maxRecDepth - 1)
result = ropeConstr(indent, [rope("kind"), result = ropeConstr(indent, [rope("kind"),
makeYamlString($n.kind), makeYamlString($n.kind),
rope("name"), makeYamlString(n.name.s), rope("name"), makeYamlString(n.name.s),
rope("typ"), typeToYamlAux(conf, n.typ, marker, #rope("typ"), typeToYamlAux(conf, n.typ, marker,
indent + 2, maxRecDepth - 1), # indent + 2, maxRecDepth - 1),
rope("info"), lineInfoToStr(conf, n.info), rope("info"), lineInfoToStr(conf, n.info),
rope("flags"), flagsToStr(n.flags), rope("flags"), flagsToStr(n.flags),
rope("magic"), makeYamlString($n.magic), rope("magic"), makeYamlString($n.magic),
rope("ast"), ast, rope("options"), rope("ast"), ast, rope("options"),
flagsToStr(n.options), rope("position"), flagsToStr(n.options), rope("position"),
rope(n.position)]) rope(n.position),
rope("k"), makeYamlString($n.loc.k),
rope("storage"), makeYamlString($n.loc.storage),
rope("flags"), makeYamlString($n.loc.flags),
rope("r"), n.loc.r,
rope("lode"), treeToYamlAux(conf, n.loc.lode, marker, indent + 2, maxRecDepth - 1)
])
proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int, proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int,
maxRecDepth: int): Rope = maxRecDepth: int): Rope =
@ -394,10 +399,16 @@ proc debugTree(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int;
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)])
of nkSym: of nkSym:
addf(result, ",$N$1\"sym\": $2_$3", let s = n.sym
[istr, rope(n.sym.name.s), rope(n.sym.id)]) addf(result, ",$N$1\"sym\": $2_$3 k: $4 storage: $5 flags: $6 r: $7",
# [istr, symToYaml(n.sym, indent, maxRecDepth), [istr, rope(s.name.s), rope(s.id),
# rope(n.sym.id)]) rope($s.loc.k),
rope($s.loc.storage),
rope($s.loc.flags),
s.loc.r
])
# [istr, symToYaml(conf, n.sym, indent, maxRecDepth),
# rope(n.sym.id)])
if renderType and n.sym.typ != nil: if renderType and n.sym.typ != nil:
addf(result, ",$N$1\"typ\": $2", [istr, debugType(conf, n.sym.typ, 2)]) addf(result, ",$N$1\"typ\": $2", [istr, debugType(conf, n.sym.typ, 2)])
of nkIdent: of nkIdent:

View file

@ -1490,7 +1490,7 @@ proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
result = true result = true
if optForceFullMake notin m.config.globalOptions: if optForceFullMake notin m.config.globalOptions:
if not equalsFile(code, cfile.cname): if not equalsFile(code, cfile.cname):
if isDefined(m.config, "nimdiff"): if m.config.symbolFiles == readOnlySf: #isDefined(m.config, "nimdiff"):
if fileExists(cfile.cname): if fileExists(cfile.cname):
copyFile(cfile.cname.string, cfile.cname.string & ".backup") copyFile(cfile.cname.string, cfile.cname.string & ".backup")
echo "diff ", cfile.cname.string, ".backup ", cfile.cname.string echo "diff ", cfile.cname.string, ".backup ", cfile.cname.string

View file

@ -47,7 +47,7 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
internalAssert c.config, sfGenSym in s.flags or s.kind == skType internalAssert c.config, sfGenSym in s.flags or s.kind == skType
var x = PSym(idTableGet(c.mapping, s)) var x = PSym(idTableGet(c.mapping, s))
if x == nil: if x == nil:
x = copySym(s, false) x = copySym(s)
x.owner = c.genSymOwner x.owner = c.genSymOwner
idTablePut(c.mapping, s, x) idTablePut(c.mapping, s, x)
result.add newSymNode(x, if c.instLines: actual.info else: templ.info) result.add newSymNode(x, if c.instLines: actual.info else: templ.info)

View file

@ -83,7 +83,7 @@ proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): i
db.exec(sql"delete from statics where module = ?", module[0]) db.exec(sql"delete from statics where module = ?", module[0])
proc pushType(w: var Writer, t: PType) = proc pushType(w: var Writer, t: PType) =
if not containsOrIncl(w.tmarks, t.id): if not containsOrIncl(w.tmarks, t.uniqueId):
w.tstack.add(t) w.tstack.add(t)
proc pushSym(w: var Writer, s: PSym) = proc pushSym(w: var Writer, s: PSym) =
@ -126,7 +126,7 @@ proc encodeNode(g: ModuleGraph; fInfo: TLineInfo, n: PNode,
encodeVInt(cast[int32](f), result) encodeVInt(cast[int32](f), result)
if n.typ != nil: if n.typ != nil:
result.add('^') result.add('^')
encodeVInt(n.typ.id, result) encodeVInt(n.typ.uniqueId, result)
pushType(w, n.typ) pushType(w, n.typ)
case n.kind case n.kind
of nkCharLit..nkUInt64Lit: of nkCharLit..nkUInt64Lit:
@ -187,7 +187,10 @@ proc encodeType(g: ModuleGraph, t: PType, result: var string) =
add(result, '[') add(result, '[')
encodeVInt(ord(t.kind), result) encodeVInt(ord(t.kind), result)
add(result, '+') add(result, '+')
encodeVInt(t.id, result) encodeVInt(t.uniqueId, result)
if t.id != t.uniqueId:
add(result, '+')
encodeVInt(t.id, result)
if t.n != nil: if t.n != nil:
encodeNode(g, unknownLineInfo(), t.n, result) encodeNode(g, unknownLineInfo(), t.n, result)
if t.flags != {}: if t.flags != {}:
@ -236,12 +239,16 @@ proc encodeType(g: ModuleGraph, t: PType, result: var string) =
encodeVInt(s.id, result) encodeVInt(s.id, result)
pushSym(w, s) pushSym(w, s)
encodeLoc(g, t.loc, result) encodeLoc(g, t.loc, result)
if t.typeInst != nil:
add(result, '\21')
encodeVInt(t.typeInst.uniqueId, result)
pushType(w, t.typeInst)
for i in countup(0, sonsLen(t) - 1): for i in countup(0, sonsLen(t) - 1):
if t.sons[i] == nil: if t.sons[i] == nil:
add(result, "^()") add(result, "^()")
else: else:
add(result, '^') add(result, '^')
encodeVInt(t.sons[i].id, result) encodeVInt(t.sons[i].uniqueId, result)
pushType(w, t.sons[i]) pushType(w, t.sons[i])
proc encodeLib(g: ModuleGraph, lib: PLib, info: TLineInfo, result: var string) = proc encodeLib(g: ModuleGraph, lib: PLib, info: TLineInfo, result: var string) =
@ -260,7 +267,7 @@ proc encodeInstantiations(g: ModuleGraph; s: seq[PInstantiation];
pushSym(w, t.sym) pushSym(w, t.sym)
for tt in t.concreteTypes: for tt in t.concreteTypes:
result.add('\17') result.add('\17')
encodeVInt(tt.id, result) encodeVInt(tt.uniqueId, result)
pushType(w, tt) pushType(w, tt)
result.add('\20') result.add('\20')
encodeVInt(t.compilesId, result) encodeVInt(t.compilesId, result)
@ -278,7 +285,7 @@ proc encodeSym(g: ModuleGraph, s: PSym, result: var string) =
encodeStr(s.name.s, result) encodeStr(s.name.s, result)
if s.typ != nil: if s.typ != nil:
result.add('^') result.add('^')
encodeVInt(s.typ.id, result) encodeVInt(s.typ.uniqueId, result)
pushType(w, s.typ) pushType(w, s.typ)
result.add('?') result.add('?')
if s.info.col != -1'i16: encodeVInt(s.info.col, result) if s.info.col != -1'i16: encodeVInt(s.info.col, result)
@ -313,7 +320,7 @@ proc encodeSym(g: ModuleGraph, s: PSym, result: var string) =
of skType, skGenericParam: of skType, skGenericParam:
for t in s.typeInstCache: for t in s.typeInstCache:
result.add('\14') result.add('\14')
encodeVInt(t.id, result) encodeVInt(t.uniqueId, result)
pushType(w, t) pushType(w, t)
of routineKinds: of routineKinds:
encodeInstantiations(g, s.procInstCache, result) encodeInstantiations(g, s.procInstCache, result)
@ -364,7 +371,7 @@ proc storeType(g: ModuleGraph; t: PType) =
let m = if t.owner != nil: getModule(t.owner) else: nil let m = if t.owner != nil: getModule(t.owner) else: nil
let mid = if m == nil: 0 else: abs(m.id) let mid = if m == nil: 0 else: abs(m.id)
db.exec(sql"insert into types(nimid, module, data) values (?, ?, ?)", db.exec(sql"insert into types(nimid, module, data) values (?, ?, ?)",
t.id, mid, buf) t.uniqueId, mid, buf)
proc transitiveClosure(g: ModuleGraph) = proc transitiveClosure(g: ModuleGraph) =
var i = 0 var i = 0
@ -380,7 +387,7 @@ proc transitiveClosure(g: ModuleGraph) =
let t = w.tstack.pop() let t = w.tstack.pop()
storeType(g, t) storeType(g, t)
when false: when false:
echo "popped type ", typeToString(t), " ", t.id echo "popped type ", typeToString(t), " ", t.uniqueId
else: else:
break break
inc i inc i
@ -583,13 +590,18 @@ proc loadType(g; id: int; info: TLineInfo): PType =
result.kind = TTypeKind(decodeVInt(b.s, b.pos)) result.kind = TTypeKind(decodeVInt(b.s, b.pos))
if b.s[b.pos] == '+': if b.s[b.pos] == '+':
inc(b.pos) inc(b.pos)
result.id = decodeVInt(b.s, b.pos) result.uniqueId = decodeVInt(b.s, b.pos)
setId(result.id) setId(result.uniqueId)
#if debugIds: registerID(result) #if debugIds: registerID(result)
else: else:
internalError(g.config, info, "decodeType: no id") internalError(g.config, info, "decodeType: no id")
if b.s[b.pos] == '+':
inc(b.pos)
result.id = decodeVInt(b.s, b.pos)
else:
result.id = result.uniqueId
# here this also avoids endless recursion for recursive type # here this also avoids endless recursion for recursive type
g.incr.r.types.add(result.id, result) g.incr.r.types.add(result.uniqueId, result)
if b.s[b.pos] == '(': result.n = decodeNode(g, b, unknownLineInfo()) if b.s[b.pos] == '(': result.n = decodeNode(g, b, unknownLineInfo())
if b.s[b.pos] == '$': if b.s[b.pos] == '$':
inc(b.pos) inc(b.pos)
@ -640,6 +652,10 @@ proc loadType(g; id: int; info: TLineInfo): PType =
let y = loadSym(g, decodeVInt(b.s, b.pos), info) let y = loadSym(g, decodeVInt(b.s, b.pos), info)
result.methods.add((x, y)) result.methods.add((x, y))
decodeLoc(g, b, result.loc, info) decodeLoc(g, b, result.loc, info)
if b.s[b.pos] == '\21':
inc(b.pos)
let d = decodeVInt(b.s, b.pos)
result.typeInst = loadType(g, d, info)
while b.s[b.pos] == '^': while b.s[b.pos] == '^':
inc(b.pos) inc(b.pos)
if b.s[b.pos] == '(': if b.s[b.pos] == '(':

View file

@ -118,7 +118,7 @@ proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
n.sym = x n.sym = x
elif s.owner.kind == skPackage: elif s.owner.kind == skPackage:
#echo "copied this ", s.name.s #echo "copied this ", s.name.s
x = copySym(s, false) x = copySym(s)
x.owner = owner x.owner = owner
idTablePut(symMap, s, x) idTablePut(symMap, s, x)
n.sym = x n.sym = x
@ -337,7 +337,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
c.matchedConcept = nil c.matchedConcept = nil
let oldScope = c.currentScope let oldScope = c.currentScope
while not isTopLevel(c): c.currentScope = c.currentScope.parent while not isTopLevel(c): c.currentScope = c.currentScope.parent
result = copySym(fn, false) result = copySym(fn)
incl(result.flags, sfFromGeneric) incl(result.flags, sfFromGeneric)
result.owner = fn result.owner = fn
result.ast = n result.ast = n

View file

@ -392,7 +392,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
localError(c.config, n.info, errTypeExpected) localError(c.config, n.info, errTypeExpected)
return errorSym(c, n) return errorSym(c, n)
result = result.typ.sym.copySym result = result.typ.sym.copySym
result.typ = copyType(result.typ, result.typ.owner, true) result.typ = exactReplica(result.typ)
result.typ.flags.incl tfUnresolved result.typ.flags.incl tfUnresolved
if result.kind == skGenericParam: if result.kind == skGenericParam:

View file

@ -233,7 +233,7 @@ proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym =
#result = PSym(idTableGet(cl.symMap, s)) #result = PSym(idTableGet(cl.symMap, s))
#if result == nil: #if result == nil:
result = copySym(s, false) result = copySym(s)
incl(result.flags, sfFromGeneric) incl(result.flags, sfFromGeneric)
#idTablePut(cl.symMap, s, result) #idTablePut(cl.symMap, s, result)
result.owner = s.owner result.owner = s.owner