Skip to content

Commit

Permalink
Merge branch 'nim-lang:devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
maleyva1 authored Jun 28, 2024
2 parents 498e32f + 828cd58 commit b9295c1
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 128 deletions.
115 changes: 0 additions & 115 deletions .github/workflows/ci_bench.yml

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ proc genObjectInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo
typeToString(typ))
genTypeInfoAux(m, typ, origType, name, info)
var tmp = getNimNode(m)
if not isImportedType(typ):
if (not isImportedType(typ)) or tfCompleteStruct in typ.flags:
genObjectFields(m, typ, origType, typ.n, tmp, info)
m.s[cfsTypeInit3].addf("$1.node = &$2;$n", [tiNameForHcr(m, name), tmp])
var t = typ.baseClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = isOpImpl(c, n, flags)

proc semOpAux(c: PContext, n: PNode) =
const flags = {efDetermineType}
const flags = {efDetermineType, efAllowSymChoice}
for i in 1..<n.len:
var a = n[i]
if a.kind == nkExprEqExpr and a.len == 2:
Expand Down
2 changes: 2 additions & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2102,12 +2102,14 @@ when not defined(js):
proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] =
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## of length `len`.
if a == nil: return @[]
newSeq(result, len)
for i in 0..len-1: result[i] = $a[i]

proc cstringArrayToSeq*(a: cstringArray): seq[string] =
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## terminated by `nil`.
if a == nil: return @[]
var L = 0
while a[L] != nil: inc(L)
result = cstringArrayToSeq(a, L)
Expand Down
16 changes: 10 additions & 6 deletions lib/system/alloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -789,13 +789,13 @@ when defined(gcDestructors):
# Well, not for the entire list, but for `max` elements of the list because
# we split the list in order to achieve bounded response times.
var it = c.freeList
var x = 0
var total = 0
while it != nil:
inc x, size
inc total, size
let chunk = cast[PSmallChunk](pageAddr(it))
inc(chunk.free, x)
inc(chunk.free, size)
it = it.next
dec(a.occ, x)
dec(a.occ, total)

proc freeDeferredObjects(a: var MemRegion; root: PBigChunk) =
var it = root
Expand Down Expand Up @@ -904,7 +904,7 @@ proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
trackSize(c.size)
sysAssert(isAccessible(a, result), "rawAlloc 14")
sysAssert(allocInv(a), "rawAlloc: end")
when logAlloc: cprintf("var pointer_%p = alloc(%ld)\n", result, requestedSize)
when logAlloc: cprintf("var pointer_%p = alloc(%ld) # %p\n", result, requestedSize, addr a)

proc rawAlloc0(a: var MemRegion, requestedSize: int): pointer =
result = rawAlloc(a, requestedSize)
Expand Down Expand Up @@ -953,22 +953,26 @@ proc rawDealloc(a: var MemRegion, p: pointer) =
c.size = SmallChunkSize
freeBigChunk(a, cast[PBigChunk](c))
else:
when logAlloc: cprintf("dealloc(pointer_%p) # SMALL FROM %p CALLER %p\n", p, c.owner, addr(a))

when defined(gcDestructors):
addToSharedFreeList(c, f, s div MemAlign)
sysAssert(((cast[int](p) and PageMask) - smallChunkOverhead()) %%
s == 0, "rawDealloc 2")
else:
# set to 0xff to check for usage after free bugs:
when overwriteFree: nimSetMem(p, -1'i32, c.size -% bigChunkOverhead())
when logAlloc: cprintf("dealloc(pointer_%p) # BIG %p\n", p, c.owner)
when defined(gcDestructors):
if c.owner == addr(a):
deallocBigChunk(a, cast[PBigChunk](c))
else:
addToSharedFreeListBigChunks(c.owner[], cast[PBigChunk](c))
else:
deallocBigChunk(a, cast[PBigChunk](c))

sysAssert(allocInv(a), "rawDealloc: end")
when logAlloc: cprintf("dealloc(pointer_%p)\n", p)
#when logAlloc: cprintf("dealloc(pointer_%p)\n", p)

when not defined(gcDestructors):
proc isAllocatedPtr(a: MemRegion, p: pointer): bool =
Expand Down
10 changes: 8 additions & 2 deletions lib/system/sysstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} =
proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} =
let n = max(newLen, 0)
if s == nil:
result = mnewString(n)
if n == 0:
return s
else:
result = mnewString(n)
elif n <= s.space:
result = s
else:
Expand Down Expand Up @@ -301,7 +304,10 @@ proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {.
compilerRtl.} =
sysAssert typ.kind == tySequence, "setLengthSeqV2: type is not a seq"
if s == nil:
result = cast[PGenericSeq](newSeq(typ, newLen))
if newLen == 0:
result = s
else:
result = cast[PGenericSeq](newSeq(typ, newLen))
else:
let elemSize = typ.base.size
let elemAlign = typ.base.align
Expand Down
7 changes: 5 additions & 2 deletions tests/ccgbugs/t13062.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type
fulfilled: Atomic[bool]

var x: Pledge
when defined(gcRefc):
when defined(cpp):
# TODO: fixme
discard "it doesn't work for refc/orc because of contrived `Atomic` in cpp"
elif defined(gcRefc):
doAssert x.repr == "[p = nil]"
elif not defined(cpp): # fixme # bug #20081
else: # fixme # bug #20081
doAssert x.repr == "Pledge(p: nil)"
28 changes: 28 additions & 0 deletions tests/ccgbugs/tcgbug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ success
M1 M2
ok
'''
matrix: "--mm:refc;--mm:orc"
"""

type
Expand Down Expand Up @@ -133,3 +134,30 @@ proc foo = # bug #23280
doAssert L mod 6 == 0

foo()

block: # bug #9940
{.emit:"""/*TYPESECTION*/
typedef struct { int base; } S;
""".}

type S {.importc: "S", completeStruct.} = object
base: cint
proc init(x:ptr S) =
x.base = 1

type
Foo = object
a: seq[float]
b: seq[float]
c: seq[float]
d: seq[float]
s: S

proc newT(): Foo =
var t: Foo
t.s.addr.init
doAssert t.s.base == 1
t

var t = newT()
doAssert t.s.base == 1
37 changes: 37 additions & 0 deletions tests/lookups/t23749.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
discard """
action: compile
"""

{.pragma: callback, gcsafe, raises: [].}

type
DataProc* = proc(val: openArray[byte]) {.callback.}
GetProc = proc (db: RootRef, key: openArray[byte], onData: DataProc): bool {.nimcall, callback.}
KvStoreRef* = ref object
obj: RootRef
getProc: GetProc

template get(dbParam: KvStoreRef, key: openArray[byte], onData: untyped): bool =
let db = dbParam
db.getProc(db.obj, key, onData)

func decode(input: openArray[byte], maxSize = 128): seq[byte] =
@[]

proc getSnappySSZ(db: KvStoreRef, key: openArray[byte]): string =
var status = "not found"
proc decode(data: openArray[byte]) =
status =
if true: "found"
else: "corrupted"
discard db.get(key, decode)
status


var ksr: KvStoreRef
var k = [byte(1), 2, 3, 4, 5]

proc foo(): string =
getSnappySSZ(ksr, toOpenArray(k, 1, 3))

echo foo()
2 changes: 1 addition & 1 deletion tests/stdlib/thashes.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
matrix: "--mm:refc; --mm:orc; --backend:cpp; --backend:js --jsbigint64:on; --backend:js --jsbigint64:off"
matrix: "--mm:refc; --mm:orc; --backend:cpp; --backend:js --jsbigint64:on; --backend:js --jsbigint64:off; --backend:c -d:nimPreviewHashFarm; --backend:cpp -d:nimPreviewHashFarm; --backend:js -d:nimPreviewHashFarm"
"""

import std/hashes
Expand Down

0 comments on commit b9295c1

Please sign in to comment.