'nim check' stability improvements

This commit is contained in:
Araq 2019-07-14 16:11:42 +02:00
commit 58e0dad371
4 changed files with 17 additions and 8 deletions

View file

@ -65,12 +65,12 @@ proc toBitSet*(conf: ConfigRef; s: PNode, b: var TBitSet) =
bitSetInit(b, int(getSize(conf, s.typ))) bitSetInit(b, int(getSize(conf, s.typ)))
for i in 0 ..< sonsLen(s): for i in 0 ..< sonsLen(s):
if s.sons[i].kind == nkRange: if s.sons[i].kind == nkRange:
j = getOrdValue(s.sons[i].sons[0]) j = getOrdValue(s.sons[i].sons[0], first)
while j <= getOrdValue(s.sons[i].sons[1]): while j <= getOrdValue(s.sons[i].sons[1], first):
bitSetIncl(b, j - first) bitSetIncl(b, j - first)
inc(j) inc(j)
else: else:
bitSetIncl(b, getOrdValue(s.sons[i]) - first) bitSetIncl(b, getOrdValue(s.sons[i], first) - first)
proc toTreeSet*(conf: ConfigRef; s: TBitSet, settype: PType, info: TLineInfo): PNode = proc toTreeSet*(conf: ConfigRef; s: TBitSet, settype: PType, info: TLineInfo): PNode =
var var

View file

@ -2461,7 +2461,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
# we end up here if the argument can be converted into the varargs # we end up here if the argument can be converted into the varargs
# formal (eg. seq[T] -> varargs[T]) but we have already instantiated # formal (eg. seq[T] -> varargs[T]) but we have already instantiated
# a container # a container
assert arg.kind == nkHiddenStdConv #assert arg.kind == nkHiddenStdConv # for 'nim check'
# this assertion can be off
localError(c.config, n.sons[a].info, "cannot convert $1 to $2" % [ localError(c.config, n.sons[a].info, "cannot convert $1 to $2" % [
typeToString(n.sons[a].typ), typeToString(formal.typ) ]) typeToString(n.sons[a].typ), typeToString(formal.typ) ])
m.state = csNoMatch m.state = csNoMatch

View file

@ -77,12 +77,12 @@ proc isPureObject*(typ: PType): bool =
t = t.sons[0].skipTypes(skipPtrs) t = t.sons[0].skipTypes(skipPtrs)
result = t.sym != nil and sfPure in t.sym.flags result = t.sym != nil and sfPure in t.sym.flags
proc getOrdValue*(n: PNode): BiggestInt = proc getOrdValue*(n: PNode; onError = high(BiggestInt)): BiggestInt =
case n.kind case n.kind
of nkCharLit..nkUInt64Lit: n.intVal of nkCharLit..nkUInt64Lit: n.intVal
of nkNilLit: 0 of nkNilLit: 0
of nkHiddenStdConv: getOrdValue(n.sons[1]) of nkHiddenStdConv: getOrdValue(n.sons[1], onError)
else: high(BiggestInt) else: onError
proc getFloatValue*(n: PNode): BiggestFloat = proc getFloatValue*(n: PNode): BiggestFloat =
case n.kind case n.kind

View file

@ -2061,13 +2061,21 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
for i in 0 ..< gp.len: for i in 0 ..< gp.len:
let genericParam = gp[i].sym let genericParam = gp[i].sym
let posInCall = macroSym.typ.len + i let posInCall = macroSym.typ.len + i
if posInCall < call.len:
yield (genericParam, call[posInCall]) yield (genericParam, call[posInCall])
# to prevent endless recursion in macro instantiation # to prevent endless recursion in macro instantiation
const evalMacroLimit = 1000 const evalMacroLimit = 1000
proc errorNode(owner: PSym, n: PNode): PNode =
result = newNodeI(nkEmpty, n.info)
result.typ = newType(tyError, owner)
result.typ.flags.incl tfCheckedForDestructor
proc evalMacroCall*(module: PSym; g: ModuleGraph; proc evalMacroCall*(module: PSym; g: ModuleGraph;
n, nOrig: PNode, sym: PSym): PNode = n, nOrig: PNode, sym: PSym): PNode =
if g.config.errorCounter > 0: return errorNode(module, n)
# XXX globalError() is ugly here, but I don't know a better solution for now # XXX globalError() is ugly here, but I don't know a better solution for now
inc(g.config.evalMacroCounter) inc(g.config.evalMacroCounter)
if g.config.evalMacroCounter > evalMacroLimit: if g.config.evalMacroCounter > evalMacroLimit: