Skip to content

Commit

Permalink
Merge branch 'devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
heterodoxic authored May 7, 2023
2 parents 774c08b + 71f2e1a commit 3ed925e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
9 changes: 3 additions & 6 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ proc canFormAcycleAux(marker: var IntSet, typ: PType, startId: int): bool =
result = true
elif not containsOrIncl(marker, t.id):
for i in 0..<t.len:
result = canFormAcycleAux(marker, t[i], abs startId)
result = canFormAcycleAux(marker, t[i], startId)
if result: return
if t.n != nil: result = canFormAcycleNode(marker, t.n, abs startId)
if t.n != nil: result = canFormAcycleNode(marker, t.n, startId)
# Inheritance can introduce cyclic types, however this is not relevant
# as the type that is passed to 'new' is statically known!
# er but we use it also for the write barrier ...
Expand All @@ -415,10 +415,7 @@ proc isFinal*(t: PType): bool =
proc canFormAcycle*(typ: PType): bool =
var marker = initIntSet()
let t = skipTypes(typ, abstractInst+{tyOwned}-{tyTypeDesc})
# startId begins with a negative value that is only in the first recursion
# and the following recursions set to its real value. This fixes
# bug #21753:
result = canFormAcycleAux(marker, t, -t.id)
result = canFormAcycleAux(marker, t, t.id)

proc mutateTypeAux(marker: var IntSet, t: PType, iter: TTypeMutator,
closure: RootRef): PType
Expand Down
19 changes: 11 additions & 8 deletions lib/system/cellseqs_v1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ type
d: PCellArray

proc contains(s: CellSeq, c: PCell): bool {.inline.} =
for i in 0 .. s.len-1:
if s.d[i] == c: return true
for i in 0 ..< s.len:
if s.d[i] == c:
return true
return false

proc resize(s: var CellSeq) =
s.cap = s.cap * 3 div 2
let d = cast[PCellArray](alloc(s.cap * sizeof(PCell)))
copyMem(d, s.d, s.len * sizeof(PCell))
dealloc(s.d)
s.d = d

proc add(s: var CellSeq, c: PCell) {.inline.} =
if s.len >= s.cap:
s.cap = s.cap * 3 div 2
var d = cast[PCellArray](alloc(s.cap * sizeof(PCell)))
copyMem(d, s.d, s.len * sizeof(PCell))
dealloc(s.d)
s.d = d
# XXX: realloc?
resize(s)
s.d[s.len] = c
inc(s.len)

Expand Down
10 changes: 5 additions & 5 deletions lib/system/orc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const
when defined(nimStressOrc):
const rootsThreshold = 10 # broken with -d:nimStressOrc: 10 and for havlak iterations 1..8
else:
var rootsThreshold {.threadvar.}: int
var rootsThreshold = defaultThreshold

proc partialCollect(lowMark: int) =
when false:
Expand Down Expand Up @@ -392,13 +392,13 @@ proc collectCycles() =
# of the cycle collector's effectiveness:
# we're effective when we collected 50% or more of the nodes
# we touched. If we're effective, we can reset the threshold:
if j.keepThreshold and rootsThreshold <= 0:
if j.keepThreshold and rootsThreshold <= defaultThreshold:
discard
elif j.freed * 2 >= j.touched:
when not defined(nimFixedOrc):
rootsThreshold = max(rootsThreshold div 3 * 2, 16)
else:
rootsThreshold = 0
rootsThreshold = defaultThreshold
#cfprintf(cstderr, "[collectCycles] freed %ld, touched %ld new threshold %ld\n", j.freed, j.touched, rootsThreshold)
elif rootsThreshold < high(int) div 4:
rootsThreshold = rootsThreshold * 3 div 2
Expand All @@ -411,7 +411,7 @@ proc registerCycle(s: Cell; desc: PNimTypeV2) =
if roots.d == nil: init(roots)
add(roots, s, desc)

if roots.len >= rootsThreshold+defaultThreshold:
if roots.len >= rootsThreshold:
collectCycles()
when logOrc:
writeCell("[added root]", s, desc)
Expand All @@ -427,7 +427,7 @@ proc GC_enableOrc*() =
## Enables the cycle collector subsystem of `--gc:orc`. This is a `--gc:orc`
## specific API. Check with `when defined(gcOrc)` for its existence.
when not defined(nimStressOrc):
rootsThreshold = 0
rootsThreshold = defaultThreshold

proc GC_disableOrc*() =
## Disables the cycle collector subsystem of `--gc:orc`. This is a `--gc:orc`
Expand Down
2 changes: 1 addition & 1 deletion tests/arc/tasyncleak.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
outputsub: "(allocCount: 4050, deallocCount: 4048)"
outputsub: "(allocCount: 4302, deallocCount: 4300)"
cmd: "nim c --gc:orc -d:nimAllocStats $file"
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/arc/topt_no_cursor.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
nimoutFull: true
cmd: '''nim c -r --warnings:off --hints:off --mm:arc --expandArc:newTarget --expandArc:delete --expandArc:p1 --expandArc:tt --hint:Performance:off --assertions:off --expandArc:extractConfig --expandArc:mergeShadowScope --expandArc:check $file'''
cmd: '''nim c -r --warnings:off --hints:off --gc:arc --expandArc:newTarget --expandArc:delete --expandArc:p1 --expandArc:tt --hint:Performance:off --assertions:off --expandArc:extractConfig --expandArc:mergeShadowScope --expandArc:check $file'''
nimout: '''
--expandArc: newTarget
Expand Down

0 comments on commit 3ed925e

Please sign in to comment.