Skip to content

Commit 7be3c42

Browse files
committed
Merge remote-tracking branch 'origin/devel' into sig-handler
2 parents 05c1317 + ff9cae8 commit 7be3c42

File tree

22 files changed

+216
-47
lines changed

22 files changed

+216
-47
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ errors.
2323

2424
- With `-d:nimPreviewCStringComparisons`, comparsions (`<`, `>`, `<=`, `>=`) between cstrings switch from reference semantics to value semantics like `==` and `!=`.
2525

26+
- `std/parsesql` has been moved to a nimble package, use `nimble` or `atlas` to install it.
27+
2628
## Standard library additions and changes
2729

2830
[//]: # "Additions:"

compiler/concepts.nim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
271271
var
272272
a = ao
273273
f = fo
274-
274+
if a.isSelf:
275+
if m.magic in {mArrPut, mArrGet}:
276+
return false
277+
a = m.potentialImplementation
275278
if a.kind in bindableTypes:
276279
a = existingBinding(m, ao)
277280
if a == ao and a.kind == tyGenericParam and a.hasElementType and a.elementType.kind != tyNone:
@@ -337,8 +340,11 @@ proc matchType(c: PContext; fo, ao: PType; m: var MatchCon): bool =
337340
result = true
338341
else:
339342
let ak = a.skipTypes(ignorableForArgType - {f.kind})
340-
if ak.kind == f.kind and f.kidsLen == ak.kidsLen:
341-
result = matchKids(c, f, ak, m)
343+
if ak.kind == f.kind:
344+
if f.base.kind == tyNone:
345+
result = true
346+
elif f.kidsLen == ak.kidsLen:
347+
result = matchKids(c, f, ak, m)
342348
of tyGenericInvocation, tyGenericInst:
343349
result = false
344350
let ea = a.skipTypes(ignorableForArgType)

compiler/sempass2.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ proc useVar(a: PEffects, n: PNode) =
379379
# If the variable is explicitly marked as .noinit. do not emit any error
380380
a.init.add s.id
381381
elif s.id notin a.init:
382-
if s.typ.requiresInit:
382+
if s.kind == skResult and tfRequiresInit in s.typ.flags:
383+
localError(a.config, n.info, "'result' requires explicit initialization")
384+
elif s.typ.requiresInit:
383385
message(a.config, n.info, warnProveInit, s.name.s)
384386
elif a.leftPartOfAsgn <= 0:
385387
if strictDefs in a.c.features:

compiler/semstmts.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ template isLocalSym(sym: PSym): bool =
725725
sym.typ.kind == tyTypeDesc or
726726
sfCompileTime in sym.flags) or
727727
sym.kind in {skProc, skFunc, skIterator} and
728-
sfGlobal notin sym.flags
728+
sfGlobal notin sym.flags and sym.typ.callConv == ccClosure
729729

730730
proc usesLocalVar(n: PNode): bool =
731731
case n.kind

compiler/semtypes.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,9 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
11471147
let t = newTypeS(tySink, c, result)
11481148
result = t
11491149
else: discard
1150-
if result.kind == tyRef and c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}:
1150+
if result.kind == tyRef and
1151+
c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and
1152+
tfTriggersCompileTime notin result.flags:
11511153
result.flags.incl tfHasAsgn
11521154

11531155
proc findEnforcedStaticType(t: PType): PType =

compiler/transf.nim

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -828,12 +828,20 @@ proc transformFor(c: PTransf, n: PNode): PNode =
828828
t = formal.ast.typ # better use the type that actually has a destructor.
829829
elif t.destructor == nil and arg.typ.destructor != nil:
830830
t = arg.typ
831-
# generate a temporary and produce an assignment statement:
832-
var temp = newTemp(c, t, formal.info)
833-
#incl(temp.sym.flags, sfCursor)
834-
addVar(v, temp)
835-
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true))
836-
newC.mapping[formal.itemId] = temp
831+
832+
if arg.kind in {nkDerefExpr, nkHiddenDeref}:
833+
# optimizes for `[]` # bug #24093
834+
var temp = newTemp(c, arg[0].typ, formal.info)
835+
addVar(v, temp)
836+
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg[0], true))
837+
newC.mapping[formal.itemId] = newDeref(temp)
838+
else:
839+
# generate a temporary and produce an assignment statement:
840+
var temp = newTemp(c, t, formal.info)
841+
#incl(temp.sym.flags, sfCursor)
842+
addVar(v, temp)
843+
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true))
844+
newC.mapping[formal.itemId] = temp
837845
of paVarAsgn:
838846
assert(skipTypes(formal.typ, abstractInst).kind in {tyVar, tyLent})
839847
newC.mapping[formal.itemId] = arg

koch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const
1313
# examples of possible values for repos: Head, ea82b54
1414
NimbleStableCommit = "9207e8b2bbdf66b5a4d1020214cff44d2d30df92" # 0.20.1
1515
AtlasStableCommit = "26cecf4d0cc038d5422fc1aa737eec9c8803a82b" # 0.9
16-
ChecksumsStableCommit = "f8f6bd34bfa3fe12c64b919059ad856a96efcba0" # 2.0.1
16+
ChecksumsStableCommit = "0b8e46379c5bc1bf73d8b3011908389c60fb9b98" # 2.0.1
1717
SatStableCommit = "faf1617f44d7632ee9601ebc13887644925dcc01"
1818

1919
NimonyStableCommit = "1dbabac403ae32e185ee4c29f006d04e04b50c6d" # unversioned \

lib/pure/asyncfile.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ proc write*(f: AsyncFile, data: string): Future[void] =
428428
dealloc buffer
429429
buffer = nil
430430
)
431-
ol.offset = DWORD(f.offset and 0xffffffff)
431+
ol.offset = cast[DWORD](f.offset and 0xffffffff)
432432
ol.offsetHigh = DWORD(f.offset shr 32)
433433
f.offset.inc(data.len)
434434

lib/pure/collections/sequtils.nim

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ macro evalOnceAs(expAlias, exp: untyped,
116116
newProc(name = genSym(nskTemplate, $expAlias), params = [getType(untyped)],
117117
body = val, procType = nnkTemplateDef))
118118

119+
template unCheckedInc(x) =
120+
{.push overflowChecks: off.}
121+
inc(x)
122+
{.pop.}
123+
119124
func concat*[T](seqs: varargs[seq[T]]): seq[T] =
120125
## Takes several sequences' items and returns them inside a new sequence.
121126
## All sequences must be of the same type.
@@ -139,7 +144,7 @@ func concat*[T](seqs: varargs[seq[T]]): seq[T] =
139144
for s in items(seqs):
140145
for itm in items(s):
141146
result[i] = itm
142-
inc(i)
147+
unCheckedInc(i)
143148

144149
func addUnique*[T](s: var seq[T], x: sink T) =
145150
## Adds `x` to the container `s` if it is not already present.
@@ -170,7 +175,7 @@ func count*[T](s: openArray[T], x: T): int =
170175
result = 0
171176
for itm in items(s):
172177
if itm == x:
173-
inc result
178+
unCheckedInc result
174179

175180
func cycle*[T](s: openArray[T], n: Natural): seq[T] =
176181
## Returns a new sequence with the items of the container `s` repeated
@@ -188,7 +193,7 @@ func cycle*[T](s: openArray[T], n: Natural): seq[T] =
188193
for x in 0 ..< n:
189194
for e in s:
190195
result[o] = e
191-
inc o
196+
unCheckedInc o
192197

193198
proc repeat*[T](x: T, n: Natural): seq[T] =
194199
## Returns a new sequence with the item `x` repeated `n` times.
@@ -321,6 +326,26 @@ func minmax*[T](x: openArray[T], cmp: proc(a, b: T): int): (T, T) {.effectsOf: c
321326
elif cmp(result[1], x[i]) < 0: result[1] = x[i]
322327

323328

329+
template findIt*(s, predicate: untyped): int =
330+
## Iterates through a container and returns the index of the first item that
331+
## fulfills the predicate, or -1
332+
##
333+
## Unlike the `find`, the predicate needs to be an expression using
334+
## the `it` variable for testing, like: `findIt([3, 2, 1], it == 2)`.
335+
var
336+
res = -1
337+
i = 0
338+
339+
# We must use items here since both `find` and `anyIt` are defined in terms
340+
# of `items`
341+
# (and not `pairs`)
342+
for it {.inject.} in items(s):
343+
if predicate:
344+
res = i
345+
break
346+
unCheckedInc(i)
347+
res
348+
324349
template zipImpl(s1, s2, retType: untyped): untyped =
325350
proc zip*[S, T](s1: openArray[S], s2: openArray[T]): retType =
326351
## Returns a new sequence with a combination of the two input containers.
@@ -417,7 +442,7 @@ func distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
417442

418443
if extra == 0 or spread == false:
419444
# Use an algorithm which overcounts the stride and minimizes reading limits.
420-
if extra > 0: inc(stride)
445+
if extra > 0: unCheckedInc(stride)
421446
for i in 0 ..< num:
422447
result[i] = newSeq[T]()
423448
for g in first ..< min(s.len, first + stride):
@@ -429,7 +454,7 @@ func distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
429454
last = first + stride
430455
if extra > 0:
431456
extra -= 1
432-
inc(last)
457+
unCheckedInc(last)
433458
result[i] = newSeq[T]()
434459
for g in first ..< last:
435460
result[i].add(s[g])
@@ -586,7 +611,7 @@ proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
586611
s[pos] = move(s[i])
587612
else:
588613
shallowCopy(s[pos], s[i])
589-
inc(pos)
614+
unCheckedInc(pos)
590615
setLen(s, pos)
591616

592617
func delete*[T](s: var seq[T]; slice: Slice[int]) =
@@ -617,8 +642,8 @@ func delete*[T](s: var seq[T]; slice: Slice[int]) =
617642
s[i] = move(s[j])
618643
else:
619644
s[i].shallowCopy(s[j])
620-
inc(i)
621-
inc(j)
645+
unCheckedInc(i)
646+
unCheckedInc(j)
622647
setLen(s, newLen)
623648
when nimvm: defaultImpl()
624649
else:
@@ -649,8 +674,8 @@ func delete*[T](s: var seq[T]; first, last: Natural) {.deprecated: "use `delete(
649674
s[i] = move(s[j])
650675
else:
651676
s[i].shallowCopy(s[j])
652-
inc(i)
653-
inc(j)
677+
unCheckedInc(i)
678+
unCheckedInc(j)
654679
setLen(s, newLen)
655680

656681
func insert*[T](dest: var seq[T], src: openArray[T], pos = 0) =
@@ -681,10 +706,10 @@ func insert*[T](dest: var seq[T], src: openArray[T], pos = 0) =
681706
dec(i)
682707
dec(j)
683708
# Insert items from `dest` into `dest` at `pos`
684-
inc(j)
709+
unCheckedInc(j)
685710
for item in src:
686711
dest[j] = item
687-
inc(j)
712+
unCheckedInc(j)
688713

689714

690715
template filterIt*(s, pred: untyped): untyped =
@@ -715,7 +740,7 @@ template filterIt*(s, pred: untyped): untyped =
715740
var result = newSeq[typeof(s[0])]()
716741
for it {.inject.} in items(s):
717742
if pred: result.add(it)
718-
result
743+
move result
719744

720745
template keepItIf*(varSeq: seq, pred: untyped) =
721746
## Keeps the items in the passed sequence (must be declared as a `var`)
@@ -743,7 +768,7 @@ template keepItIf*(varSeq: seq, pred: untyped) =
743768
varSeq[pos] = move(varSeq[i])
744769
else:
745770
shallowCopy(varSeq[pos], varSeq[i])
746-
inc(pos)
771+
unCheckedInc(pos)
747772
setLen(varSeq, pos)
748773

749774
since (1, 1):
@@ -842,12 +867,7 @@ template anyIt*(s, pred: untyped): bool =
842867
assert numbers.anyIt(it > 8) == true
843868
assert numbers.anyIt(it > 9) == false
844869

845-
var result = false
846-
for it {.inject.} in items(s):
847-
if pred:
848-
result = true
849-
break
850-
result
870+
findIt(s, pred) != -1
851871

852872
template toSeq1(s: not iterator): untyped =
853873
# overload for typed but not iterator
@@ -875,7 +895,7 @@ template toSeq2(iter: iterator): untyped =
875895
var result = newSeq[typeof(iter2)](iter2.len)
876896
for x in iter2:
877897
result[i] = x
878-
inc i
898+
unCheckedInc i
879899
result
880900
else:
881901
type OutType = typeof(iter2())
@@ -920,7 +940,7 @@ template toSeq*(iter: untyped): untyped =
920940
var i = 0
921941
for x in iter2:
922942
result[i] = x
923-
inc i
943+
unCheckedInc i
924944
result
925945
else:
926946
var result: seq[typeof(iter)] = @[]

lib/pure/collections/tables.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ template withValue*[A, B](t: Table[A, B], key: A,
707707
mixin rawGet
708708
var hc: Hash
709709
var index = rawGet(t, key, hc)
710-
if index > 0:
710+
if index >= 0:
711711
let value {.cursor, inject.} = t.data[index].val
712712
body1
713713
else:

0 commit comments

Comments
 (0)