Merge branch 'devel' into sighashes

This commit is contained in:
Araq 2016-12-19 11:35:45 +01:00
commit 237252f90c
14 changed files with 115 additions and 25 deletions

View file

@ -386,6 +386,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
var istr = rspaces(indent + 2) var istr = rspaces(indent + 2)
result = "{$N$1\"kind\": $2" % result = "{$N$1\"kind\": $2" %
[istr, makeYamlString($n.kind)] [istr, makeYamlString($n.kind)]
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
if maxRecDepth != 0: if maxRecDepth != 0:
case n.kind case n.kind
of nkCharLit..nkUInt64Lit: of nkCharLit..nkUInt64Lit:
@ -418,7 +419,6 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
addf(result, "$N$1$2", [rspaces(indent + 4), debugTree(n.sons[i], addf(result, "$N$1$2", [rspaces(indent + 4), debugTree(n.sons[i],
indent + 4, maxRecDepth - 1, renderType)]) indent + 4, maxRecDepth - 1, renderType)])
addf(result, "$N$1]", [istr]) addf(result, "$N$1]", [istr])
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
addf(result, "$N$1}", [rspaces(indent)]) addf(result, "$N$1}", [rspaces(indent)])
proc debug(n: PSym) = proc debug(n: PSym) =

View file

@ -184,24 +184,27 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool =
result = true result = true
proc genLineDir(p: BProc, t: PNode) = proc genLineDir(p: BProc, t: PNode) =
let info = t.info var tt = t
#if t.kind in nkCallKinds+{nkStmtListExpr} and t.len > 1: t[1].info #while tt.kind in {nkStmtListExpr}+nkCallKinds:
#else: t.info # tt = tt.lastSon
var line = info.safeLineNm if tt.kind in nkCallKinds and tt.len > 1:
tt = tt.sons[1]
let line = tt.info.safeLineNm
if optEmbedOrigSrc in gGlobalOptions: if optEmbedOrigSrc in gGlobalOptions:
add(p.s(cpsStmts), ~"//" & info.sourceLine & rnl) add(p.s(cpsStmts), ~"//" & tt.info.sourceLine & rnl)
genCLineDir(p.s(cpsStmts), info.toFullPath, line) genCLineDir(p.s(cpsStmts), tt.info.toFullPath, line)
if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
(p.prc == nil or sfPure notin p.prc.flags): (p.prc == nil or sfPure notin p.prc.flags):
if freshLineInfo(p, info): if freshLineInfo(p, tt.info):
linefmt(p, cpsStmts, "#endb($1, $2);$n", linefmt(p, cpsStmts, "#endb($1, $2);$n",
line.rope, makeCString(toFilename(info))) line.rope, makeCString(toFilename(tt.info)))
elif ({optLineTrace, optStackTrace} * p.options == elif ({optLineTrace, optStackTrace} * p.options ==
{optLineTrace, optStackTrace}) and {optLineTrace, optStackTrace}) and
(p.prc == nil or sfPure notin p.prc.flags) and info.fileIndex >= 0: (p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex >= 0:
if freshLineInfo(p, info): if freshLineInfo(p, tt.info):
linefmt(p, cpsStmts, "nimln($1, $2);$n", linefmt(p, cpsStmts, "nimln($1, $2);$n",
line.rope, info.quotedFilename) line.rope, tt.info.quotedFilename)
proc postStmtActions(p: BProc) {.inline.} = proc postStmtActions(p: BProc) {.inline.} =
add(p.s(cpsStmts), p.module.injectStmt) add(p.s(cpsStmts), p.module.injectStmt)

View file

@ -104,6 +104,25 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
var evalTemplateCounter* = 0 var evalTemplateCounter* = 0
# to prevent endless recursion in templates instantiation # to prevent endless recursion in templates instantiation
proc wrapInComesFrom*(info: TLineInfo; res: PNode): PNode =
when true:
result = res
result.info = info
if result.kind in {nkStmtList, nkStmtListExpr} and result.len > 0:
result.lastSon.info = info
when false:
# this hack is required to
var x = result
while x.kind == nkStmtListExpr: x = x.lastSon
if x.kind in nkCallKinds:
for i in 1..<x.len:
if x[i].kind in nkCallKinds:
x.sons[i].info = info
else:
result = newNodeI(nkPar, info)
result.add res
result.flags.incl nfNone
proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode = proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
inc(evalTemplateCounter) inc(evalTemplateCounter)
if evalTemplateCounter > 100: if evalTemplateCounter > 100:
@ -132,5 +151,5 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
#if ctx.instLines: result.info = n.info #if ctx.instLines: result.info = n.info
for i in countup(0, safeLen(body) - 1): for i in countup(0, safeLen(body) - 1):
evalTemplateAux(body.sons[i], args, ctx, result) evalTemplateAux(body.sons[i], args, ctx, result)
result = wrapInComesFrom(n.info, result)
dec(evalTemplateCounter) dec(evalTemplateCounter)

View file

@ -369,6 +369,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
result = evalMacroCall(c.module, c.cache, n, nOrig, sym) result = evalMacroCall(c.module, c.cache, n, nOrig, sym)
if efNoSemCheck notin flags: if efNoSemCheck notin flags:
result = semAfterMacroCall(c, result, sym, flags) result = semAfterMacroCall(c, result, sym, flags)
result = wrapInComesFrom(nOrig.info, result)
popInfoContext() popInfoContext()
proc forceBool(c: PContext, n: PNode): PNode = proc forceBool(c: PContext, n: PNode): PNode =

View file

@ -769,7 +769,7 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
of nkCast: of nkCast:
var a = getConstExpr(m, n.sons[1]) var a = getConstExpr(m, n.sons[1])
if a == nil: return if a == nil: return
if n.typ.kind in NilableTypes: if n.typ != nil and n.typ.kind in NilableTypes:
# we allow compile-time 'cast' for pointer types: # we allow compile-time 'cast' for pointer types:
result = a result = a
result.typ = n.typ result.typ = n.typ

View file

@ -172,7 +172,9 @@ proc sumGeneric(t: PType): int =
inc result inc result
of tyGenericInvocation, tyTuple, tyProc: of tyGenericInvocation, tyTuple, tyProc:
result += ord(t.kind == tyGenericInvocation) result += ord(t.kind == tyGenericInvocation)
for i in 0 .. <t.len: result += t.sons[i].sumGeneric for i in 0 .. <t.len:
if t.sons[i] != nil:
result += t.sons[i].sumGeneric
break break
of tyGenericParam, tyExpr, tyStatic, tyStmt: break of tyGenericParam, tyExpr, tyStatic, tyStmt: break
of tyAlias: t = t.lastSon of tyAlias: t = t.lastSon

View file

@ -57,10 +57,11 @@ proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo;
result.qualifiedPath = @[] result.qualifiedPath = @[]
if not isLocal and s.kind != skModule: if not isLocal and s.kind != skModule:
let ow = s.owner let ow = s.owner
if ow.kind != skModule and ow.owner != nil: if ow != nil and ow.kind != skModule and ow.owner != nil:
let ow2 = ow.owner let ow2 = ow.owner
result.qualifiedPath.add(ow2.origModuleName) result.qualifiedPath.add(ow2.origModuleName)
result.qualifiedPath.add(ow.origModuleName) if ow != nil:
result.qualifiedPath.add(ow.origModuleName)
result.qualifiedPath.add(s.name.s) result.qualifiedPath.add(s.name.s)
if s.typ != nil: if s.typ != nil:

View file

@ -45,12 +45,12 @@ proc advice*(s: var ThreadPoolState): ThreadPoolAdvice =
procKernelDiff = procKernel - s.prevProcKernel procKernelDiff = procKernel - s.prevProcKernel
procUserDiff = procUser - s.prevProcUser procUserDiff = procUser - s.prevProcUser
sysTotal = int(sysKernelDiff + sysUserDiff) sysTotal = sysKernelDiff + sysUserDiff
procTotal = int(procKernelDiff + procUserDiff) procTotal = procKernelDiff + procUserDiff
# total CPU usage < 85% --> create a new worker thread. # total CPU usage < 85% --> create a new worker thread.
# Measurements show that 100% and often even 90% is not reached even # Measurements show that 100% and often even 90% is not reached even
# if all my cores are busy. # if all my cores are busy.
if sysTotal == 0 or procTotal / sysTotal < 0.85: if sysTotal == 0 or procTotal.float / sysTotal.float < 0.85:
result = doCreateThread result = doCreateThread
s.prevSysKernel = sysKernel s.prevSysKernel = sysKernel
s.prevSysUser = sysUser s.prevSysUser = sysUser

View file

@ -100,7 +100,8 @@ type
freeChunksList: PBigChunk # XXX make this a datastructure with O(1) access freeChunksList: PBigChunk # XXX make this a datastructure with O(1) access
chunkStarts: IntSet chunkStarts: IntSet
root, deleted, last, freeAvlNodes: PAvlNode root, deleted, last, freeAvlNodes: PAvlNode
locked: bool # if locked, we cannot free pages. locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages.
nextChunkSize: int
{.deprecated: [TLLChunk: LLChunk, TAvlNode: AvlNode, TMemRegion: MemRegion].} {.deprecated: [TLLChunk: LLChunk, TAvlNode: AvlNode, TMemRegion: MemRegion].}
# shared: # shared:
@ -275,9 +276,25 @@ proc pageAddr(p: pointer): PChunk {.inline.} =
#sysAssert(Contains(allocator.chunkStarts, pageIndex(result))) #sysAssert(Contains(allocator.chunkStarts, pageIndex(result)))
proc requestOsChunks(a: var MemRegion, size: int): PBigChunk = proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
if not a.blockChunkSizeIncrease:
a.nextChunkSize =
if a.currMem < 64 * 1024: PageSize*4
else: a.nextChunkSize*2
var size = size
if size > a.nextChunkSize:
result = cast[PBigChunk](osAllocPages(size))
else:
result = cast[PBigChunk](osTryAllocPages(a.nextChunkSize))
if result == nil:
result = cast[PBigChunk](osAllocPages(size))
a.blockChunkSizeIncrease = true
else:
size = a.nextChunkSize
incCurrMem(a, size) incCurrMem(a, size)
inc(a.freeMem, size) inc(a.freeMem, size)
result = cast[PBigChunk](osAllocPages(size))
sysAssert((cast[ByteAddress](result) and PageMask) == 0, "requestOsChunks 1") sysAssert((cast[ByteAddress](result) and PageMask) == 0, "requestOsChunks 1")
#zeroMem(result, size) #zeroMem(result, size)
result.next = nil result.next = nil
@ -432,6 +449,9 @@ proc getBigChunk(a: var MemRegion, size: int): PBigChunk =
splitChunk(a, result, size) splitChunk(a, result, size)
else: else:
result = requestOsChunks(a, size) result = requestOsChunks(a, size)
# if we over allocated split the chunk:
if result.size > size:
splitChunk(a, result, size)
result.prevSize = 0 # XXX why is this needed? result.prevSize = 0 # XXX why is this needed?
result.used = true result.used = true
incl(a, a.chunkStarts, pageIndex(result)) incl(a, a.chunkStarts, pageIndex(result))

View file

@ -0,0 +1,13 @@
discard """
errormsg: "value of type 'bool' has to be discarded"
line: 13
file: "tdont_show_system.nim"
"""
# bug #4308
#proc getGameTile: int =
# 1 > 0
# bug #4905 subsumes the problem of #4308:
true notin {false}

View file

@ -0,0 +1,11 @@
discard """
outputsub: '''tproper_stacktrace.nim(7) tproper_stacktrace'''
exitcode: 1
"""
template fuzzy(x) =
echo x[] != 9
var p: ptr int
fuzzy p

View file

@ -1,6 +1,6 @@
discard """ discard """
tfile: "tnot.nim" file: "tnot.nim"
tline: 14 line: 14
errormsg: "type mismatch" errormsg: "type mismatch"
""" """
# BUG: following compiles, but should not: # BUG: following compiles, but should not:

View file

@ -1,6 +1,5 @@
discard """ discard """
output: "ok" output: "ok"
disabled: "true"
""" """
import tables, lists import tables, lists

21
tests/system/trealloc.nim Normal file
View file

@ -0,0 +1,21 @@
discard """
output: '''success'''
"""
# bug #4818
# Test that this completes without OOM.
const BUFFER_SIZE = 5000
var buffer = cast[ptr uint16](alloc(BUFFER_SIZE))
var total_size: int64 = 0
for i in 0 .. 4000:
let size = BUFFER_SIZE * i
#echo "requesting ", size
total_size += size.int64
buffer = cast[ptr uint16](realloc(buffer, size))
#echo totalSize, " total: ", getTotalMem(), " occupied: ", getOccupiedMem(), " free: ", getFreeMem()
dealloc(buffer)
echo "success"