IC: further progress

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

View File

@@ -898,6 +898,8 @@ type
loc*: TLoc
typeInst*: PType # for generic instantiations the tyGenericInst that led to this
# 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
key*, val*: RootRef
@@ -1268,6 +1270,7 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
result.size = -1
result.align = -1 # default alignment
result.id = getID()
result.uniqueId = result.id
result.lockLevel = UnspecifiedLockLevel
when debugIds:
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 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.ast = nil # BUGFIX; was: s.ast which made problems
result.typ = s.typ
if keepId:
result.id = s.id
else:
result.id = getID()
when debugIds: registerId(result)
result.id = getID()
when debugIds: registerId(result)
result.flags = s.flags
result.magic = s.magic
if s.kind == skModule:

View File

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

View File

@@ -1490,7 +1490,7 @@ proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
result = true
if optForceFullMake notin m.config.globalOptions:
if not equalsFile(code, cfile.cname):
if isDefined(m.config, "nimdiff"):
if m.config.symbolFiles == readOnlySf: #isDefined(m.config, "nimdiff"):
if fileExists(cfile.cname):
copyFile(cfile.cname.string, cfile.cname.string & ".backup")
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
var x = PSym(idTableGet(c.mapping, s))
if x == nil:
x = copySym(s, false)
x = copySym(s)
x.owner = c.genSymOwner
idTablePut(c.mapping, s, x)
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])
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)
proc pushSym(w: var Writer, s: PSym) =
@@ -126,7 +126,7 @@ proc encodeNode(g: ModuleGraph; fInfo: TLineInfo, n: PNode,
encodeVInt(cast[int32](f), result)
if n.typ != nil:
result.add('^')
encodeVInt(n.typ.id, result)
encodeVInt(n.typ.uniqueId, result)
pushType(w, n.typ)
case n.kind
of nkCharLit..nkUInt64Lit:
@@ -187,7 +187,10 @@ proc encodeType(g: ModuleGraph, t: PType, result: var string) =
add(result, '[')
encodeVInt(ord(t.kind), 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:
encodeNode(g, unknownLineInfo(), t.n, result)
if t.flags != {}:
@@ -236,12 +239,16 @@ proc encodeType(g: ModuleGraph, t: PType, result: var string) =
encodeVInt(s.id, result)
pushSym(w, s)
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):
if t.sons[i] == nil:
add(result, "^()")
else:
add(result, '^')
encodeVInt(t.sons[i].id, result)
encodeVInt(t.sons[i].uniqueId, result)
pushType(w, t.sons[i])
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)
for tt in t.concreteTypes:
result.add('\17')
encodeVInt(tt.id, result)
encodeVInt(tt.uniqueId, result)
pushType(w, tt)
result.add('\20')
encodeVInt(t.compilesId, result)
@@ -278,7 +285,7 @@ proc encodeSym(g: ModuleGraph, s: PSym, result: var string) =
encodeStr(s.name.s, result)
if s.typ != nil:
result.add('^')
encodeVInt(s.typ.id, result)
encodeVInt(s.typ.uniqueId, result)
pushType(w, s.typ)
result.add('?')
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:
for t in s.typeInstCache:
result.add('\14')
encodeVInt(t.id, result)
encodeVInt(t.uniqueId, result)
pushType(w, t)
of routineKinds:
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 mid = if m == nil: 0 else: abs(m.id)
db.exec(sql"insert into types(nimid, module, data) values (?, ?, ?)",
t.id, mid, buf)
t.uniqueId, mid, buf)
proc transitiveClosure(g: ModuleGraph) =
var i = 0
@@ -380,7 +387,7 @@ proc transitiveClosure(g: ModuleGraph) =
let t = w.tstack.pop()
storeType(g, t)
when false:
echo "popped type ", typeToString(t), " ", t.id
echo "popped type ", typeToString(t), " ", t.uniqueId
else:
break
inc i
@@ -583,13 +590,18 @@ proc loadType(g; id: int; info: TLineInfo): PType =
result.kind = TTypeKind(decodeVInt(b.s, b.pos))
if b.s[b.pos] == '+':
inc(b.pos)
result.id = decodeVInt(b.s, b.pos)
setId(result.id)
result.uniqueId = decodeVInt(b.s, b.pos)
setId(result.uniqueId)
#if debugIds: registerID(result)
else:
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
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] == '$':
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)
result.methods.add((x, y))
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] == '^':
inc(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
elif s.owner.kind == skPackage:
#echo "copied this ", s.name.s
x = copySym(s, false)
x = copySym(s)
x.owner = owner
idTablePut(symMap, s, x)
n.sym = x
@@ -337,7 +337,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
c.matchedConcept = nil
let oldScope = c.currentScope
while not isTopLevel(c): c.currentScope = c.currentScope.parent
result = copySym(fn, false)
result = copySym(fn)
incl(result.flags, sfFromGeneric)
result.owner = fn
result.ast = n

View File

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

View File

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