diff --git a/compiler/aliases.nim b/compiler/aliases.nim index 0006c9fe636b9..8b8353060502a 100644 --- a/compiler/aliases.nim +++ b/compiler/aliases.nim @@ -10,7 +10,7 @@ ## Simple alias analysis for the HLO and the code generators. import - ast, astalgo, types, trees, intsets + ast, astalgo, types, trees, ordsets type TAnalysisResult* = enum @@ -59,7 +59,7 @@ proc isPartOfAux(a, b: PType, marker: var IntSet): TAnalysisResult = proc isPartOf(a, b: PType): TAnalysisResult = ## checks iff 'a' can be part of 'b'. Iterates over VALUE types! - var marker = initIntSet() + var marker = initOrdSet[int]() # watch out: parameters reversed because I'm too lazy to change the code... result = isPartOfAux(b, a, marker) diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 6aecb1dcb4892..1eb3df97f762a 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -12,7 +12,7 @@ # the data structures here are used in various places of the compiler. import - ast, hashes, intsets, strutils, options, lineinfos, ropes, idents, rodutils, + ast, hashes, ordsets, strutils, options, lineinfos, ropes, idents, rodutils, msgs proc hashNode*(p: RootRef): Hash @@ -389,15 +389,15 @@ proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int, result.addf("$N$1}", [rspaces(indent)]) proc treeToYaml(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope = - var marker = initIntSet() + var marker = initOrdSet[int]() result = treeToYamlAux(conf, n, marker, indent, maxRecDepth) proc typeToYaml(conf: ConfigRef; n: PType, indent: int = 0, maxRecDepth: int = - 1): Rope = - var marker = initIntSet() + var marker = initOrdSet[int]() result = typeToYamlAux(conf, n, marker, indent, maxRecDepth) proc symToYaml(conf: ConfigRef; n: PSym, indent: int = 0, maxRecDepth: int = - 1): Rope = - var marker = initIntSet() + var marker = initOrdSet[int]() result = symToYamlAux(conf, n, marker, indent, maxRecDepth) import tables diff --git a/compiler/ccgmerge.nim b/compiler/ccgmerge.nim index a87d5b609c85f..2fa16c6bc09de 100644 --- a/compiler/ccgmerge.nim +++ b/compiler/ccgmerge.nim @@ -12,7 +12,7 @@ import ast, ropes, options, strutils, nimlexbase, cgendata, rodutils, - intsets, llstream, tables, modulegraphs, pathutils + ordsets, llstream, tables, modulegraphs, pathutils # Careful! Section marks need to contain a tabulator so that they cannot # be part of C string literals. diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 6c82a140beb10..ee81e34a6a759 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -423,7 +423,7 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet; kind: TSymKind): R result = getTypeDescAux(m, t, check, kind) proc getSeqPayloadType(m: BModule; t: PType): Rope = - var check = initIntSet() + var check = initOrdSet[int]() result = getTypeDescWeak(m, t, check, skParam) & "_Content" #result = getTypeForward(m, t, hashType(t)) & "_Content" @@ -587,7 +587,7 @@ proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope = proc fillObjectFields*(m: BModule; typ: PType) = # sometimes generic objects are not consistently merged. We patch over # this fact here. - var check = initIntSet() + var check = initOrdSet[int]() discard getRecordFields(m, typ, check) proc mangleDynLibProc(sym: PSym): Rope @@ -931,7 +931,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin excl(check, t.id) proc getTypeDesc(m: BModule, typ: PType; kind = skParam): Rope = - var check = initIntSet() + var check = initOrdSet[int]() result = getTypeDescAux(m, typ, check, kind) type @@ -942,7 +942,7 @@ type proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope = assert t.kind == tyProc - var check = initIntSet() + var check = initOrdSet[int]() result = getTempName(m) var rettype, desc: Rope genProcParams(m, t, rettype, desc, check, declareEnvironment=kind != clHalf) @@ -958,7 +958,7 @@ proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope = proc finishTypeDescriptions(m: BModule) = var i = 0 - var check = initIntSet() + var check = initOrdSet[int]() while i < m.typeStack.len: let t = m.typeStack[i] if optSeqDestructors in m.config.globalOptions and t.skipTypes(abstractInst).kind == tySequence: @@ -990,7 +990,7 @@ proc genProcHeader(m: BModule, prc: PSym, asPtr: bool = false): Rope = result.add "static " elif sfImportc notin prc.flags: result.add "N_LIB_PRIVATE " - var check = initIntSet() + var check = initOrdSet[int]() fillLoc(prc.loc, locProc, prc.ast[namePos], mangleName(m, prc), OnUnknown) genProcParams(m, prc.typ, rettype, params, check) # handle the 2 options for hotcodereloading codegen - function pointer diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 9a50b718c7e90..a5b25a9da2a26 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -10,7 +10,7 @@ ## This module implements the C code generator. import - ast, astalgo, hashes, trees, platform, magicsys, extccomp, options, intsets, + ast, astalgo, hashes, trees, platform, magicsys, extccomp, options, ordsets, nversion, nimsets, msgs, bitsets, idents, types, ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth, rodutils, renderer, cgendata, ccgmerge, aliases, @@ -976,7 +976,7 @@ proc getProcTypeCast(m: BModule, prc: PSym): Rope = result = getTypeDesc(m, prc.loc.t) if prc.typ.callConv == ccClosure: var rettype, params: Rope - var check = initIntSet() + var check = initOrdSet[int]() genProcParams(m, prc.typ, rettype, params, check) result = "$1(*)$2" % [rettype, params] @@ -1803,8 +1803,8 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: AbsoluteFile): BModule result.g = g result.tmpBase = rope("TM" & $hashOwner(module) & "_") result.headerFiles = @[] - result.declaredThings = initIntSet() - result.declaredProtos = initIntSet() + result.declaredThings = initOrdSet[int]() + result.declaredProtos = initOrdSet[int]() result.cfilename = filename result.filename = filename result.typeCache = initTable[SigHash, Rope]() diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index 8e509433663c6..bbb2d7d20d285 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -10,7 +10,7 @@ ## This module contains the data structures for the C code generation phase. import - ast, ropes, options, intsets, + ast, ropes, options, ordsets, tables, ndi, lineinfos, pathutils, modulegraphs, sets type @@ -201,7 +201,7 @@ proc newProc*(prc: PSym, module: BModule): BProc = proc newModuleList*(g: ModuleGraph): BModuleList = BModuleList(typeInfoMarker: initTable[SigHash, tuple[str: Rope, owner: PSym]](), - config: g.config, graph: g, nimtvDeclared: initIntSet()) + config: g.config, graph: g, nimtvDeclared: initOrdSet[int]()) iterator cgenModules*(g: BModuleList): BModule = for m in g.modulesClosed: diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 9b871a8983785..66064af186212 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -10,7 +10,7 @@ ## This module implements code generation for methods. import - intsets, options, ast, msgs, idents, renderer, types, magicsys, + ordsets, options, ast, msgs, idents, renderer, types, magicsys, sempass2, strutils, modulegraphs, lineinfos proc genConv(n: PNode, d: PType, downcast: bool; conf: ConfigRef): PNode = @@ -286,7 +286,7 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PS proc generateMethodDispatchers*(g: ModuleGraph): PNode = result = newNode(nkStmtList) for bucket in 0.. 1: initList.add(", ") var it = n[i] diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index c23ca52cb22b8..770173ca04a1f 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -10,7 +10,7 @@ # This file implements lambda lifting for the transformator. import - intsets, strutils, options, ast, astalgo, msgs, + ordsets, strutils, options, ast, astalgo, msgs, idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos, transf, liftdestructors @@ -307,8 +307,8 @@ type graph: ModuleGraph proc initDetectionPass(g: ModuleGraph; fn: PSym): DetectionPass = - result.processed = initIntSet() - result.capturedVars = initIntSet() + result.processed = initOrdSet[int]() + result.capturedVars = initOrdSet[int]() result.ownerToType = initTable[int, PType]() result.processed.incl(fn.id) result.graph = g @@ -513,7 +513,7 @@ type unownedEnvVars: Table[int, PNode] # only required for --newruntime proc initLiftingPass(fn: PSym): LiftingPass = - result.processed = initIntSet() + result.processed = initOrdSet[int]() result.processed.incl(fn.id) result.envVars = initTable[int, PNode]() diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 744f77cf8c3af..f3d68f84199b7 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -10,7 +10,7 @@ # This module implements lookup helpers. import - intsets, ast, astalgo, idents, semdata, types, msgs, options, + ordsets, ast, astalgo, idents, semdata, types, msgs, options, renderer, nimfix/prettybase, lineinfos, strutils proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) @@ -420,7 +420,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = o.mode = oimDone return nil o.symChoiceIndex = 1 - o.inSymChoice = initIntSet() + o.inSymChoice = initOrdSet[int]() incl(o.inSymChoice, result.id) else: discard when false: diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index da2a222a4a138..f2d63570e3574 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -25,7 +25,7 @@ ## - Its dependent module stays the same. ## -import ast, intsets, tables, options, lineinfos, hashes, idents, +import ast, ordsets, tables, options, lineinfos, hashes, idents, incremental, btrees, md5 type @@ -172,7 +172,7 @@ proc createMagic*(g: ModuleGraph; name: string, m: TMagic): PSym = proc newModuleGraph*(cache: IdentCache; config: ConfigRef): ModuleGraph = result = ModuleGraph() initStrTable(result.packageSyms) - result.deps = initIntSet() + result.deps = initOrdSet[int]() result.importDeps = initTable[FileIndex, seq[FileIndex]]() result.modules = @[] result.importStack = @[] @@ -197,7 +197,7 @@ proc newModuleGraph*(cache: IdentCache; config: ConfigRef): ModuleGraph = proc resetAllModules*(g: ModuleGraph) = initStrTable(g.packageSyms) - g.deps = initIntSet() + g.deps = initOrdSet[int]() g.modules = @[] g.importStack = @[] g.inclToMod = initTable[FileIndex, FileIndex]() diff --git a/compiler/optimizer.nim b/compiler/optimizer.nim index 5d1139bfdb378..d43ad7d9ab30f 100644 --- a/compiler/optimizer.nim +++ b/compiler/optimizer.nim @@ -12,7 +12,7 @@ ## - recognize "all paths lead to 'wasMoved(x)'" import - ast, renderer, idents, intsets + ast, renderer, idents, ordsets from trees import exprStructuralEquivalent @@ -72,7 +72,7 @@ proc wasMovedTarget(matches: var IntSet; branch: seq[PNode]; moveTarget: PNode): proc intersect(summary: var seq[PNode]; branch: seq[PNode]) = # keep all 'wasMoved(x)' calls in summary that are also in 'branch': var i = 0 - var matches = initIntSet() + var matches = initOrdSet[int]() while i < summary.len: if wasMovedTarget(matches, branch, summary[i][1].skipAddr): inc i diff --git a/compiler/reorder.nim b/compiler/reorder.nim index 72f8666a2e495..8c51f93900890 100644 --- a/compiler/reorder.nim +++ b/compiler/reorder.nim @@ -1,6 +1,6 @@ import - intsets, ast, idents, algorithm, renderer, strutils, + ordsets, ast, idents, algorithm, renderer, strutils, msgs, modulegraphs, syntaxes, options, modulepaths, lineinfos @@ -404,15 +404,15 @@ proc hasForbiddenPragma(n: PNode): bool = proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode = if n.hasForbiddenPragma: return n - var includedFiles = initIntSet() + var includedFiles = initOrdSet[int]() let mpath = toFullPath(graph.config, module.fileIdx) let n = expandIncludes(graph, module, n, mpath, includedFiles).splitSections result = newNodeI(nkStmtList, n.info) var deps = newSeq[(IntSet, IntSet)](n.len) for i in 0..`_ Implementation of a heap data structure that can be used as a priority queue. -* `intsets `_ - Efficient implementation of a set of ints as a sparse bit set. +* `ordsets `_ + Efficient implementation of a set of int and other ordinals as a sparse bit set. * `lists `_ Nim linked list support. Contains singly and doubly linked lists and diff --git a/drnim/drnim.nim b/drnim/drnim.nim index b4761a3981307..5ed88fe93749c 100644 --- a/drnim/drnim.nim +++ b/drnim/drnim.nim @@ -18,7 +18,7 @@ ]# import std / [ - parseopt, strutils, os, tables, times, intsets, hashes + parseopt, strutils, os, tables, times, ordsets, hashes ] import ".." / compiler / [ @@ -987,7 +987,7 @@ proc traverseIf(c: DrnimContext; n: PNode) = for f in newFacts: c.facts.add((f, condVersion)) # build the 'Phi' information: let varsWithoutFinals = c.varVersions.len - var mutatedVars = initIntSet() + var mutatedVars = initOrdSet[int]() for i in oldVars ..< varsWithoutFinals: let vv = c.varVersions[i] if not mutatedVars.containsOrIncl(vv): diff --git a/lib/pure/collections/intsets.nim b/lib/pure/collections/intsets.nim index cd84dca1a01ef..22b3221fc5b81 100644 --- a/lib/pure/collections/intsets.nim +++ b/lib/pure/collections/intsets.nim @@ -6,7 +6,7 @@ # distribution, for details about the copyright. # -## Deprecated by the generic `IntSet` for ordinal sparse sets. +## Deprecated by the generic `OrdSet[A: Ordinal]` for ordinal sparse sets. ## **See also:** ## * `ordinal sets module `_ for more general int sets @@ -22,6 +22,7 @@ proc initIntSet*(): IntSet = initOrdSet[int]() iterator items*(s: IntSet): int {.inline, deprecated: "use ordsets".} = for i in ordsets.items(s): yield i + # purely delegating proc contains*(s: IntSet, key: int): bool {.deprecated: "use ordsets".} = ordsets.contains(s, key) proc incl*(s: var IntSet, key: int) {.deprecated: "use ordsets".} = ordsets.incl(s, key) diff --git a/lib/pure/collections/ordsets.nim b/lib/pure/collections/ordsets.nim index 963e7ba938a01..ca13abc04f217 100644 --- a/lib/pure/collections/ordsets.nim +++ b/lib/pure/collections/ordsets.nim @@ -60,6 +60,8 @@ type head: PTrunk data: TrunkSeq a: array[0..33, int] # profiling shows that 34 elements are enough + + IntSet* = OrdSet[int] proc mustRehash[T](t: T): bool {.inline.} = let length = t.max + 1 diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 98dedc5ff6538..ea4ae8dd6231d 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -43,7 +43,7 @@ ## that ``=`` performs a copy of the set. ## ## **See also:** -## * `intsets module `_ for efficient int sets +## * `ordsets module `_ for efficient int and other ordinal sets ## * `tables module `_ for hash tables diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim index e74e68b05b1bf..4ca5db4f04197 100644 --- a/lib/pure/marshal.nim +++ b/lib/pure/marshal.nim @@ -61,7 +61,7 @@ Please use alternative packages for serialization. It is possible to reimplement this module using generics and type traits. Please contribute a new implementation.""".} -import streams, typeinfo, json, intsets, tables, unicode +import streams, typeinfo, json, ordsets, tables, unicode proc ptrToInt(x: pointer): int {.inline.} = result = cast[int](x) # don't skip alignment @@ -298,7 +298,7 @@ proc store*[T](s: Stream, data: T) = s.setPosition(0) assert s.readAll() == "[1, 3, 5]" - var stored = initIntSet() + var stored = initOrdSet[int]() var d: T shallowCopy(d, data) storeAny(s, toAny(d), stored) @@ -317,7 +317,7 @@ proc `$$`*[T](x: T): string = let y = $$x assert y == """{"id": 1, "bar": "baz"}""" - var stored = initIntSet() + var stored = initOrdSet[int]() var d: T shallowCopy(d, x) var s = newStringStream() diff --git a/testament/testament.nim b/testament/testament.nim index 4afafb645e61b..77f9c28f37ad8 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -12,7 +12,7 @@ import strutils, pegs, os, osproc, streams, json, backend, parseopt, specs, htmlgen, browsers, terminal, - algorithm, times, md5, sequtils, azure, intsets + algorithm, times, md5, sequtils, azure, ordsets from std/sugar import dup import compiler/nodejs @@ -320,7 +320,7 @@ proc addResult(r: var TResults, test: TTest, target: TTarget, proc checkForInlineErrors(r: var TResults, expected, given: TSpec, test: TTest, target: TTarget) = let pegLine = peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' {[^:]*} ':' \s* {.*}" - var covered = initIntSet() + var covered = initOrdSet[int]() for line in splitLines(given.nimout): if line =~ pegLine: diff --git a/tests/gc/weakrefs.nim b/tests/gc/weakrefs.nim index 81c048d746d14..50cba12243c3a 100644 --- a/tests/gc/weakrefs.nim +++ b/tests/gc/weakrefs.nim @@ -2,7 +2,7 @@ discard """ output: "true" """ -import intsets +import ordsets type TMyObject = object @@ -14,7 +14,7 @@ type var gid: int # for id generation - valid = initIntSet() + valid = initOrdSet[int]() proc finalizer(x: StrongObject) = valid.excl(x.id) diff --git a/tests/js/tstdlib_imports.nim b/tests/js/tstdlib_imports.nim index 7611b7dcb9993..dc8f53ad5f688 100644 --- a/tests/js/tstdlib_imports.nim +++ b/tests/js/tstdlib_imports.nim @@ -14,7 +14,7 @@ import std/[ algorithm, sequtils, # Collections: - critbits, deques, heapqueue, intsets, lists, options, sets, + critbits, deques, heapqueue, ordsets, lists, options, sets, sharedlist, tables, # fails: sharedtables diff --git a/tests/system/tuse_version.nim b/tests/system/tuse_version.nim index 36dac46eca0f3..f9caa10847681 100644 --- a/tests/system/tuse_version.nim +++ b/tests/system/tuse_version.nim @@ -13,7 +13,7 @@ import std/[ algorithm, sequtils, # Collections: - critbits, deques, heapqueue, intsets, lists, options, sets, + critbits, deques, heapqueue, ordsets, lists, options, sets, sharedlist, tables, # Strings: diff --git a/tests/test_nimscript.nims b/tests/test_nimscript.nims index d9f47736681f8..a7ca74a1885d3 100644 --- a/tests/test_nimscript.nims +++ b/tests/test_nimscript.nims @@ -13,7 +13,7 @@ import std/[ algorithm, sequtils, # Collections: - critbits, deques, heapqueue, intsets, lists, options, sets, + critbits, deques, heapqueue, ordsets, lists, options, sets, sharedlist, tables, # fails: sharedtables diff --git a/tools/heapdumprepl.nim b/tools/heapdumprepl.nim index dbaef2f2cd3ce..595f54116bf4c 100644 --- a/tools/heapdumprepl.nim +++ b/tools/heapdumprepl.nim @@ -1,6 +1,6 @@ include prelude -import intsets +import ordsets type NodeKind = enum @@ -36,7 +36,7 @@ proc parseHex(s: string): int = discard parseutils.parseHex(s, result, 0) proc reachable(g: Graph; stack: var seq[int]; goal: int): bool = - var t = initIntSet() + var t = initOrdSet[int]() while stack.len > 0: let it = stack.pop if not t.containsOrIncl(it):