Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring and yak shaving. #13687

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
712cb76
first step to remove all instances of `compiles`
krux02 Mar 7, 2020
94d4f79
toSeq without `compiles`
krux02 Mar 7, 2020
7cede93
add workaround #13417
krux02 Mar 7, 2020
70a75ad
added temporary debug stuff
krux02 Mar 8, 2020
2d3f84b
experimental fix
krux02 Mar 9, 2020
0b82257
fix another bug
krux02 Mar 9, 2020
eaed2e3
minor removal of
krux02 Mar 9, 2020
d1b53da
minor cleanup
krux02 Mar 9, 2020
6296db1
cleanup in tests
krux02 Mar 10, 2020
05f7fee
WIP
krux02 Mar 10, 2020
abf3f1a
fix test toString
krux02 Mar 11, 2020
08e8b80
finish cleanup test tostring
krux02 Mar 11, 2020
20515e6
fix for tconcepts_issues
krux02 Mar 11, 2020
15a0c2e
WIP
krux02 Mar 13, 2020
f6f5ded
Merge branch 'remove-compiles-from-compiler' of github.com:krux02/Nim…
krux02 Mar 13, 2020
61d3807
magic typeIsRecursive
krux02 Mar 15, 2020
8e2d6c5
add two tests
krux02 Mar 15, 2020
5c2954f
cycle detection works
krux02 Mar 16, 2020
c93544c
fix in for loop inlining
krux02 Mar 17, 2020
150b9d6
restrict cycle detection on pointer types
krux02 Mar 18, 2020
da70460
some more adoptions and fixes
krux02 Mar 18, 2020
8a71755
last test fixes
krux02 Mar 18, 2020
2e0369a
Merge branch 'devel' into remove-compiles-from-compiler
krux02 Mar 18, 2020
6ae9f9c
small cleanup
krux02 Mar 18, 2020
f4ab177
simplify cycle detection
krux02 Mar 18, 2020
5c5bbfe
implement as typetrait
krux02 Mar 19, 2020
0726d1f
Merge branch 'devel' into remove-compiles-from-compiler
krux02 Mar 19, 2020
675f4b2
fix for last regression
krux02 Mar 19, 2020
ae73bb4
add dollar for proc values
krux02 Mar 19, 2020
267cd65
fix for cstrig
krux02 Mar 19, 2020
6ddb8e5
add test for unchecked array
krux02 Mar 20, 2020
d71bb0c
reintroduce accidental removal of runnable example
krux02 Mar 21, 2020
9b3ede6
apply feedback
krux02 Mar 21, 2020
bd9694e
apply feedback
krux02 Mar 21, 2020
b83dea3
hadle openarray explicitly
krux02 Mar 23, 2020
d778c35
Merge branch 'devel' into remove-compiles-from-compiler
krux02 Mar 24, 2020
5586a09
print pointer as hex
krux02 Mar 25, 2020
e8e3c2c
apply requested changes
krux02 Mar 26, 2020
590e225
stuff
krux02 Mar 27, 2020
99fd44d
fixes in tests
krux02 Mar 27, 2020
a9fb475
fix regression
krux02 Apr 14, 2020
dc4b8a8
Merge branch 'remove-compiles-from-compiler' of github.com:krux02/Nim…
krux02 Apr 14, 2020
59c15eb
undeprecate initSharedTable
krux02 Apr 15, 2020
15e449e
add assert
krux02 Apr 15, 2020
5b53c8e
Merge branch 'devel' into remove-compiles-from-compiler
krux02 Apr 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ template `[]`*(n: Indexable, i: BackwardsIndex): Indexable = n[n.len - i.int]
template `[]=`*(n: Indexable, i: BackwardsIndex; x: Indexable) = n[n.len - i.int] = x

when defined(useNodeIds):
const nodeIdToDebug* = -1 # 2322968
const nodeIdToDebug* = -1
var gNodeId: int

proc newNode*(kind: TNodeKind): PNode =
Expand Down
34 changes: 34 additions & 0 deletions compiler/astalgo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ type
currentLine: int
firstItem: bool
useColor: bool
compressBuiltinTypes: bool
res: string

proc indentMore(this: var DebugPrinter) =
Expand Down Expand Up @@ -541,7 +542,37 @@ proc value(this: var DebugPrinter; value: PSym) =

this.closeCurly

proc builtinTypeSubstitution(this: var DebugPrinter; substitution: string) =
if this.useColor:
this.res.add backrefStyle
this.res.add substitution
if this.useColor:
this.res.add resetStyle

proc value(this: var DebugPrinter; value: PType) =
# these shortcuts for builtin types are done before ``earlyExit`` because they are shorter that backreference links
if this.compressBuiltinTypes and value != nil:
case value.kind
of tyBool: this.builtinTypeSubstitution "<bool>"; return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a template or macro to reduce repetitions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No thanks, I prefer repetition here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.builtinTypeSubstitution(($value.kind)[2..^1].toLowerAscii)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Araq, I know about this shorter code. But I really don't like unnecessary string allocations. Your version allocates two intermediate temporary strings, where my version creates none. Did you take that into account?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can cache these into a RT (or even CT) table and avoid allocs as well as code duplication.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you take that into account?

Yeah I did, allocations for debug code are irrelevant.

of tyChar: this.builtinTypeSubstitution "<char>"; return
of tyPointer: this.builtinTypeSubstitution "<pointer>"; return
of tyString: this.builtinTypeSubstitution "<string>"; return
of tyCString: this.builtinTypeSubstitution "<cstring>"; return
of tyInt: this.builtinTypeSubstitution "<int>"; return
of tyInt8: this.builtinTypeSubstitution "<int8>"; return
of tyInt16: this.builtinTypeSubstitution "<int16>"; return
of tyInt32: this.builtinTypeSubstitution "<int32>"; return
of tyInt64: this.builtinTypeSubstitution "<int64>"; return
of tyFloat: this.builtinTypeSubstitution "<float>"; return
of tyFloat32: this.builtinTypeSubstitution "<float32>"; return
of tyFloat64,: this.builtinTypeSubstitution "<float64>"; return
of tyUInt: this.builtinTypeSubstitution "<uint>"; return
of tyUInt8: this.builtinTypeSubstitution "<uint8>"; return
of tyUInt16: this.builtinTypeSubstitution "<uint16>"; return
of tyUInt32: this.builtinTypeSubstitution "<uint32>"; return
of tyUInt64: this.builtinTypeSubstitution "<uint64>"; return
else:
discard
earlyExit(this, value)

this.openCurly
Expand Down Expand Up @@ -634,6 +665,7 @@ when declared(echo):
this.visited = initTable[pointer, int]()
this.renderSymType = true
this.useColor = not defined(windows)
this.compressBuiltinTypes = true
this.value(n)
echo($this.res)

Expand All @@ -642,6 +674,7 @@ when declared(echo):
this.visited = initTable[pointer, int]()
this.renderSymType = true
this.useColor = not defined(windows)
this.compressBuiltinTypes = true
this.value(n)
echo($this.res)

Expand All @@ -650,6 +683,7 @@ when declared(echo):
this.visited = initTable[pointer, int]()
#this.renderSymType = true
this.useColor = not defined(windows)
this.compressBuiltinTypes = true
this.value(n)
echo($this.res)

Expand Down
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasExceptionsQuery")
defineSymbol("nimHasIsNamedTuple")
defineSymbol("nimHashOrdinalFixed")
defineSymbol("nimHasTypeIsRecursive")

when defined(nimHasLibFFI):
# Renaming as we can't conflate input vs output define flags; e.g. this
Expand Down
13 changes: 5 additions & 8 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,9 @@ template hashNimExe(): string = $secureHashFile(os.getAppFilename())
proc writeJsonBuildInstructions*(conf: ConfigRef) =
template lit(x: untyped) = f.write x
template str(x: untyped) =
when compiles(escapeJson(x, buf)):
buf.setLen 0
escapeJson(x, buf)
f.write buf
else:
f.write escapeJson(x)
buf.setLen 0
escapeJson(x, buf)
f.write buf

proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) =
var comma = false
Expand Down Expand Up @@ -1031,7 +1028,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
pastStart = true
lit "\L"

proc depfiles(conf: ConfigRef; f: File) =
proc depfiles(conf: ConfigRef; f: File; buf: var string) =
var i = 0
for it in conf.m.fileInfos:
let path = it.fullPath.string
Expand Down Expand Up @@ -1071,7 +1068,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
lit ",\L\"cmdline\": "
str conf.commandLine
lit ",\L\"depfiles\":[\L"
depfiles(conf, f)
depfiles(conf, f, buf)
lit "],\L\"nimexe\": \L"
str hashNimExe()
lit "\L"
Expand Down
7 changes: 1 addition & 6 deletions compiler/guards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,7 @@ macro `=~`(x: PNode, pat: untyped): bool =

var conds = newTree(nnkBracket)
m(x, pat, conds)
when compiles(nestList(ident"and", conds)):
result = nestList(ident"and", conds)
#elif declared(macros.toNimIdent):
# result = nestList(toNimIdent"and", conds)
else:
result = nestList(!"and", conds)
result = nestList(ident"and", conds)

proc isMinusOne(n: PNode): bool =
n.kind in {nkCharLit..nkUInt64Lit} and n.intVal == -1
Expand Down
28 changes: 9 additions & 19 deletions compiler/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ type
TPassClose* = proc (graph: ModuleGraph; p: PPassContext, n: PNode): PNode {.nimcall.}
TPassProcess* = proc (p: PPassContext, topLevelStmt: PNode): PNode {.nimcall.}

TPass* = tuple[open: TPassOpen,
process: TPassProcess,
close: TPassClose,
isFrontend: bool]

TPass* = object
open*: TPassOpen
process*: TPassProcess
close*: TPassClose
isFrontend*: bool

const
cb64 = [
Expand Down Expand Up @@ -135,24 +135,14 @@ proc hash*(x: FileIndex): Hash {.borrow.}

when defined(nimfind):
template onUse*(info: TLineInfo; s: PSym) =
when compiles(c.c.graph):
if c.c.graph.onUsage != nil: c.c.graph.onUsage(c.c.graph, s, info)
else:
if c.graph.onUsage != nil: c.graph.onUsage(c.graph, s, info)
if c.graph.onUsage != nil: c.graph.onUsage(c.graph, s, info)

template onDef*(info: TLineInfo; s: PSym) =
when compiles(c.c.graph):
if c.c.graph.onDefinition != nil: c.c.graph.onDefinition(c.c.graph, s, info)
else:
if c.graph.onDefinition != nil: c.graph.onDefinition(c.graph, s, info)
if c.graph.onDefinition != nil: c.graph.onDefinition(c.graph, s, info)

template onDefResolveForward*(info: TLineInfo; s: PSym) =
when compiles(c.c.graph):
if c.c.graph.onDefinitionResolveForward != nil:
c.c.graph.onDefinitionResolveForward(c.c.graph, s, info)
else:
if c.graph.onDefinitionResolveForward != nil:
c.graph.onDefinitionResolveForward(c.graph, s, info)
if c.graph.onDefinitionResolveForward != nil:
c.graph.onDefinitionResolveForward(c.graph, s, info)

else:
template onUse*(info: TLineInfo; s: PSym) = discard
Expand Down
4 changes: 4 additions & 0 deletions compiler/semmagic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
localError(c.config, traitCall.info,
"distinctBase expects a distinct type as argument. The given type was " & typeToString(operand))
result = newType(tyError, context).toNode(traitCall.info)
of "isRecursivePointer":
let operand = operand.skipTypes({tyGenericInst})
let cond = isRecursivePointer(operand)
result = newIntNodeT(toInt128(ord(cond)), traitCall, c.graph)
else:
localError(c.config, traitCall.info, "unknown trait: " & s)
result = newNodeI(nkEmpty, traitCall.info)
Expand Down
17 changes: 8 additions & 9 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,14 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
# inline context.
if formal.kind == tyTypeDesc: return paDirectMapping
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
case arg.kind
of nkStmtListExpr:
return paComplexOpenarray
case arg.skipHidden.kind
of nkBracket:
return paFastAsgnTakeTypeFromArg
of nkSym:
return paDirectMapping
else:
return paDirectMapping # XXX really correct?
# what if ``arg`` has side-effects?
return paComplexOpenarray

case arg.kind
of nkEmpty..nkNilLit:
result = paDirectMapping
Expand Down Expand Up @@ -644,7 +644,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
# generate access statements for the parameters (unless they are constant)
pushTransCon(c, newC)
for i in 1..<call.len:
var arg = transform(c, call[i])
let arg = transform(c, call[i])
let ff = skipTypes(iter.typ, abstractInst)
# can happen for 'nim check':
if i >= ff.n.len: return result
Expand All @@ -671,9 +671,8 @@ proc transformFor(c: PTransf, n: PNode): PNode =
idNodeTablePut(newC.mapping, formal, arg)
# XXX BUG still not correct if the arg has a side effect!
of paComplexOpenarray:
let typ = newType(tySequence, formal.owner)
Araq marked this conversation as resolved.
Show resolved Hide resolved
addSonSkipIntLit(typ, formal.typ[0])
var temp = newTemp(c, typ, formal.info)
# arrays will deep copy here (pretty bad).
var temp = newTemp(c, arg.typ, formal.info)
addVar(v, temp)
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
idNodeTablePut(newC.mapping, formal, temp)
Expand Down
24 changes: 22 additions & 2 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
of tyUncheckedArray:
result = "UncheckedArray[" & typeToString(t[0]) & ']'
of tySequence:
result = "seq[" & typeToString(t[0]) & ']'
Araq marked this conversation as resolved.
Show resolved Hide resolved
if t.sym != nil and prefer != preferResolved:
result = t.sym.name.s
else:
result = "seq[" & typeToString(t[0]) & ']'
of tyOpt:
result = "opt[" & typeToString(t[0]) & ']'
of tyOrdinal:
Expand Down Expand Up @@ -1623,7 +1626,7 @@ proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
if isTupleRecursive(t[i], cycleDetectorCopy):
return true
of tyAlias, tyRef, tyPtr, tyGenericInst, tyVar, tyLent, tySink,
tyArray, tyUncheckedArray, tySequence:
tyArray, tyUncheckedArray, tySequence, tyDistinct:
return isTupleRecursive(t.lastSon, cycleDetector)
else:
return false
Expand All @@ -1632,6 +1635,23 @@ proc isTupleRecursive*(t: PType): bool =
var cycleDetector = initIntSet()
isTupleRecursive(t, cycleDetector)

proc isRecursivePointer(typ: PType, isPointer: bool): bool =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the isPointer here? Isn't that the proc's job to decide?

Copy link
Contributor

@Clyybber Clyybber Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this is only used for recursing, the exported overload without the isPointer argument is right below this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about is. Initially I had a version with value is SomePointer and value.isRecursive. But it didn't work out because of distinct types. A distinct ref not being a ref anymore really hurts here. Neither isNil nor == nil work on a distinct ref. My next thought was: "I only really care about cyclic types when the type is also a pointer type, value types can't be cyclic by definition". So I move the "distinct" resolution to the compiler because it was eventually simpler, and probably also a faster implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this explanation. Rename the isPointer parameter to something that makes it obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is recursive. And isPointer is just the state of the recursive fold on the type tree. After all we don't care about the result of canFormAcycle isn't a pointer type after all.

Copy link
Contributor Author

@krux02 krux02 Mar 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Araq would it help if I rename this proc to isPointerAux?

if typ == nil:
return false
case typ.kind:
krux02 marked this conversation as resolved.
Show resolved Hide resolved
of tyObject, tyTuple:
return isPointer and canFormAcycle(typ)
of tyRef, tyPtr:
return isRecursivePointer(typ.lastSon, isPointer = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinite recursoin for the illegal type T = ptr T. I think this can matter for nim check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a tag for illegal types that I can just check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, ideally such a type would be a tyError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a test for such a type. If illegal types are correctly marked as tyError, then this shouldn't be an infinite recursion.

of tyAlias, tyGenericInst, tyVar, tyLent, tySink, tyArray, tyUncheckedArray, tySequence, tyDistinct:
return isRecursivePointer(typ.lastSon, isPointer)
else:
return false

proc isRecursivePointer*(t: PType): bool =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this overload and just defined:
proc isRecursivePointer(typ: PType, isPointer = false): bool =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but I prefer it the way it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotheecour The explanation for why I prefer it this way is, I don't want the isPointer parameter on the exported proc isRecursivePointer. After all it is just an implementation detail. Somthing that just confused @Araq.

isRecursivePointer(t, false)


proc isException*(t: PType): bool =
# check if `y` is object type and it inherits from Exception
assert(t != nil)
Expand Down
23 changes: 11 additions & 12 deletions compiler/unittest_light.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ proc mismatch*[T](lhs: T, rhs: T): string =
result.add "\n"
result.add "lhs:{" & replaceInvisible(
$lhs) & "}\nrhs:{" & replaceInvisible($rhs) & "}\n"
when compiles(lhs.len):
when T is (string | seq | array):
Araq marked this conversation as resolved.
Show resolved Hide resolved
if lhs.len != rhs.len:
result.add "lhs.len: " & $lhs.len & " rhs.len: " & $rhs.len & "\n"
when compiles(lhs[0]):
var i = 0
while i < lhs.len and i < rhs.len:
if lhs[i] != rhs[i]: break
i.inc
result.add "first mismatch index: " & $i & "\n"
if i < lhs.len and i < rhs.len:
result.add "lhs[i]: {" & quoted($lhs[i]) & "}\nrhs[i]: {" & quoted(
$rhs[i]) & "}\n"
result.add "lhs[0..<i]:{" & replaceInvisible($lhs[
0..<i]) & "}"
var i = 0
while i < lhs.len and i < rhs.len:
if lhs[i] != rhs[i]: break
i.inc
result.add "first mismatch index: " & $i & "\n"
if i < lhs.len and i < rhs.len:
result.add "lhs[i]: {" & quoted($lhs[i]) & "}\nrhs[i]: {" & quoted(
$rhs[i]) & "}\n"
result.add "lhs[0..<i]:{" & replaceInvisible($lhs[
0..<i]) & "}"

proc assertEquals*[T](lhs: T, rhs: T) =
when false: # can be useful for debugging to see all that's fed to this.
Expand Down
4 changes: 0 additions & 4 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,6 @@ proc `$`*(arg: LineInfo): string =
# BUG: without `result = `, gives compile error
result = arg.filename & "(" & $arg.line & ", " & $arg.column & ")"

#proc lineinfo*(n: NimNode): LineInfo {.magic: "NLineInfo", noSideEffect.}
# ## returns the position the node appears in the original source file
# ## in the form filename(line, col)

proc getLine(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.}
proc getColumn(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.}
proc getFile(arg: NimNode): string {.magic: "NLineInfo", noSideEffect.}
Expand Down
44 changes: 0 additions & 44 deletions lib/pure/collections/chains.nim

This file was deleted.

6 changes: 1 addition & 5 deletions lib/pure/collections/critbits.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ proc `[]=`*[T](c: var CritBitTree[T], key: string, val: T) =
template get[T](c: CritBitTree[T], key: string): T =
let n = rawGet(c, key)
if n == nil:
when compiles($key):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the other version much better than relying on the new "fact" that "everything has a dollar operator" (which isn't true in your PR either btw, callback types cannot be stringified).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point with the callback type. As I said, this everything can be printed should be an RFC and I will provide it. Still changes like this were important to detect cases non printable types and find solutions for them.

raise newException(KeyError, "key not found: " & $key)
else:
raise newException(KeyError, "key not found")

raise newException(KeyError, "key not found: " & $key)
n.val

proc `[]`*[T](c: CritBitTree[T], key: string): T {.inline.} =
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/collections/deques.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ template initImpl(result: typed, initialSize: int) =
assert isPowerOfTwo(initialSize)
result.mask = initialSize-1
newSeq(result.data, initialSize)

template checkIfInitialized(deq: typed) =
when compiles(defaultInitialSize):
when defaultInitialSize > 0:
if deq.mask == 0:
initImpl(deq, defaultInitialSize)

Expand Down
Loading