Merge remote-tracking branch 'origin/devel' into compiler-cleanup

This commit is contained in:
Jacek Sieka 2016-08-17 18:49:36 +08:00
commit 4d558e2608
11 changed files with 45 additions and 21 deletions

View file

@ -1944,6 +1944,7 @@ proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) =
putDataIntoDest(p, d, t, tmp) putDataIntoDest(p, d, t, tmp)
# This fixes bug #4551, but we really need better dataflow # This fixes bug #4551, but we really need better dataflow
# analysis to make this 100% safe. # analysis to make this 100% safe.
if t.kind notin {tySequence, tyString}:
d.s = OnStatic d.s = OnStatic
proc expr(p: BProc, n: PNode, d: var TLoc) = proc expr(p: BProc, n: PNode, d: var TLoc) =

View file

@ -578,6 +578,8 @@ proc wrapProcForSpawn*(owner: PSym; spawnExpr: PNode; retType: PType;
var fn = n.sons[0] var fn = n.sons[0]
# templates and macros are in fact valid here due to the nature of # templates and macros are in fact valid here due to the nature of
# the transformation: # the transformation:
if fn.kind == nkClosure:
localError(n.info, "closure in spawn environment is not allowed")
if not (fn.kind == nkSym and fn.sym.kind in {skProc, skTemplate, skMacro, if not (fn.kind == nkSym and fn.sym.kind in {skProc, skTemplate, skMacro,
skMethod, skConverter}): skMethod, skConverter}):
# for indirect calls we pass the function pointer in the scratchObj # for indirect calls we pass the function pointer in the scratchObj

View file

@ -114,8 +114,12 @@ proc semTypeTraits(c: PContext, n: PNode): PNode =
proc semOrd(c: PContext, n: PNode): PNode = proc semOrd(c: PContext, n: PNode): PNode =
result = n result = n
result.typ = makeRangeType(c, firstOrd(n.sons[1].typ), let parType = n.sons[1].typ
lastOrd(n.sons[1].typ), n.info) if isOrdinalType(parType) or parType.kind == tySet:
result.typ = makeRangeType(c, firstOrd(parType), lastOrd(parType), n.info)
else:
localError(n.info, errOrdinalTypeExpected)
result.typ = errorType(c)
proc semBindSym(c: PContext, n: PNode): PNode = proc semBindSym(c: PContext, n: PNode): PNode =
result = copyNode(n) result = copyNode(n)

View file

@ -528,7 +528,7 @@ proc isOwnedProcVar(n: PNode; owner: PSym): bool =
proc trackOperand(tracked: PEffects, n: PNode, paramType: PType) = proc trackOperand(tracked: PEffects, n: PNode, paramType: PType) =
let a = skipConvAndClosure(n) let a = skipConvAndClosure(n)
let op = a.typ let op = a.typ
if op != nil and op.kind == tyProc and n.kind != nkNilLit: if op != nil and op.kind == tyProc and n.skipConv.kind != nkNilLit:
internalAssert op.n.sons[0].kind == nkEffectList internalAssert op.n.sons[0].kind == nkEffectList
var effectList = op.n.sons[0] var effectList = op.n.sons[0]
let s = n.skipConv let s = n.skipConv

View file

@ -985,11 +985,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyGenericBody: of tyGenericBody:
considerPreviousT: considerPreviousT:
let ff = lastSon(f) if a.kind == tyGenericInst and a.sons[0] == f:
var depth = 0
if a.kind == tyGenericInst and (a.sons[0] == f): #or (ff != nil and ff.kind == tyObject and isGenericSubtype(a.sons[0], ff, depth))):
c.inheritancePenalty += depth
bindingRet isGeneric bindingRet isGeneric
let ff = lastSon(f)
if ff != nil: if ff != nil:
result = typeRel(c, ff, a) result = typeRel(c, ff, a)
@ -1006,7 +1004,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
for i in countup(1, sonsLen(f) - 1): for i in countup(1, sonsLen(f) - 1):
if x.sons[i].kind == tyGenericParam: if x.sons[i].kind == tyGenericParam:
internalError("wrong instantiated type!") internalError("wrong instantiated type!")
elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype: return elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
# Workaround for regression #4589
if f.sons[i].kind != tyTypeDesc: return
c.inheritancePenalty += depth c.inheritancePenalty += depth
result = isGeneric result = isGeneric
else: else:
@ -1024,7 +1024,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
# #
# we steal the generic parameters from the tyGenericBody: # we steal the generic parameters from the tyGenericBody:
for i in countup(1, sonsLen(f) - 1): for i in countup(1, sonsLen(f) - 1):
var x = PType(idTableGet(c.bindings, genericBody.sons[i-1])) let x = PType(idTableGet(c.bindings, genericBody.sons[i-1]))
if x == nil: if x == nil:
discard "maybe fine (for eg. a==tyNil)" discard "maybe fine (for eg. a==tyNil)"
elif x.kind in {tyGenericInvocation, tyGenericParam}: elif x.kind in {tyGenericInvocation, tyGenericParam}:

View file

@ -144,10 +144,12 @@ proc elemType*(t: PType): PType =
proc isOrdinalType(t: PType): bool = proc isOrdinalType(t: PType): bool =
assert(t != nil) assert(t != nil)
const
# caution: uint, uint64 are no ordinal types! # caution: uint, uint64 are no ordinal types!
result = t.kind in {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} or baseKinds = {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum}
(t.kind in {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst}) and parentKinds = {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst,
isOrdinalType(t.sons[0]) tyDistinct}
t.kind in baseKinds or (t.kind in parentKinds and isOrdinalType(t.sons[0]))
proc enumHasHoles(t: PType): bool = proc enumHasHoles(t: PType): bool =
var b = t var b = t

View file

@ -44,7 +44,7 @@ __clang__
#if defined(_MSC_VER) #if defined(_MSC_VER)
# pragma warning(disable: 4005 4100 4101 4189 4191 4200 4244 4293 4296 4309) # pragma warning(disable: 4005 4100 4101 4189 4191 4200 4244 4293 4296 4309)
# pragma warning(disable: 4310 4365 4456 4477 4514 4574 4611 4668 4702 4706) # pragma warning(disable: 4310 4365 4456 4477 4514 4574 4611 4668 4702 4706)
# pragma warning(disable: 4710 4711 4774 4800 4820 4996) # pragma warning(disable: 4710 4711 4774 4800 4820 4996 4090)
#endif #endif
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View file

@ -16,6 +16,10 @@ const
MAX_KQUEUE_CHANGE_EVENTS = 64 MAX_KQUEUE_CHANGE_EVENTS = 64
# Maximum number of events that can be returned. # Maximum number of events that can be returned.
MAX_KQUEUE_RESULT_EVENTS = 64 MAX_KQUEUE_RESULT_EVENTS = 64
# SIG_IGN and SIG_DFL declared in posix.nim as variables, but we need them
# to be constants and GC-safe.
SIG_DFL = cast[proc(x: cint) {.noconv,gcsafe.}](0)
SIG_IGN = cast[proc(x: cint) {.noconv,gcsafe.}](1)
when defined(macosx) or defined(freebsd): when defined(macosx) or defined(freebsd):
when defined(macosx): when defined(macosx):

View file

@ -205,6 +205,10 @@ proc newSocket*(fd: SocketHandle, domain: Domain = AF_INET,
if buffered: if buffered:
result.currPos = 0 result.currPos = 0
# Set SO_NOSIGPIPE on OS X.
when defined(macosx):
setSockOptInt(fd, SOL_SOCKET, SO_NOSIGPIPE, 1)
proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket = proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket =
## Creates a new socket. ## Creates a new socket.
## ##
@ -342,8 +346,6 @@ when defineSsl:
result = SSLContext(context: newCTX, extraInternalIndex: 0, result = SSLContext(context: newCTX, extraInternalIndex: 0,
referencedData: initSet[int]()) referencedData: initSet[int]())
result.extraInternalIndex = getExtraDataIndex(result) result.extraInternalIndex = getExtraDataIndex(result)
# The PSK callback functions assume the internal index is 0.
assert result.extraInternalIndex == 0
let extraInternal = new(SslContextExtraInternal) let extraInternal = new(SslContextExtraInternal)
result.setExtraData(result.extraInternalIndex, extraInternal) result.setExtraData(result.extraInternalIndex, extraInternal)
@ -392,6 +394,8 @@ when defineSsl:
## ##
## Only used in PSK ciphersuites. ## Only used in PSK ciphersuites.
ctx.getExtraInternal().clientGetPskFunc = fun ctx.getExtraInternal().clientGetPskFunc = fun
assert ctx.extraInternalIndex == 0,
"The pskClientCallback assumes the extraInternalIndex is 0"
ctx.context.SSL_CTX_set_psk_client_callback( ctx.context.SSL_CTX_set_psk_client_callback(
if fun == nil: nil else: pskClientCallback) if fun == nil: nil else: pskClientCallback)

View file

@ -79,7 +79,7 @@ when not defined(windows):
var rc2 = selector.select(100) var rc2 = selector.select(100)
assert(len(rc2) == 1) assert(len(rc2) == 1)
var read_count = posix.recv(server2_socket, addr (buffer[0]), 128, 0) var read_count = posix.recv(server2_socket, addr buffer[0], 128, 0)
if read_count == -1: if read_count == -1:
raiseOSError(osLastError()) raiseOSError(osLastError())
@ -317,7 +317,7 @@ else:
var rc2 = selector.select(100) var rc2 = selector.select(100)
assert(len(rc2) == 1) assert(len(rc2) == 1)
var read_count = recv(server2_socket, addr (buffer[0]), 128, 0) var read_count = recv(server2_socket, addr buffer[0], 128, 0)
if read_count == -1: if read_count == -1:
raiseOSError(osLastError()) raiseOSError(osLastError())

View file

@ -0,0 +1,7 @@
# bug #4589
import tables
type SimpleTable*[TKey, TVal] = TableRef[TKey, TVal]
template newSimpleTable*(TKey, TVal: typedesc): SimpleTable[TKey, TVal] = newTable[TKey, TVal]()
var fontCache : SimpleTable[string, SimpleTable[int32, int]]
fontCache = newSimpleTable(string, SimpleTable[int32, int])