Tables, use sink val arguments more actively (#15625)
This commit is contained in:
parent
d22ab0fb96
commit
04f8fcfbd0
3 changed files with 30 additions and 29 deletions
|
|
@ -514,8 +514,9 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
|
|||
#elif n.kind in nkSymChoices:
|
||||
# echo "came here"
|
||||
let paramType = paramType.skipTypesOrNil(abstractInst)
|
||||
if paramType != nil and tfNotNil in paramType.flags and
|
||||
n.typ != nil and tfNotNil notin n.typ.flags:
|
||||
if paramType != nil and tfNotNil in paramType.flags and n.typ != nil:
|
||||
let ntyp = n.typ.skipTypesOrNil({tyVar, tyLent, tySink})
|
||||
if ntyp != nil and tfNotNil notin ntyp.flags:
|
||||
if isAddrNode(n):
|
||||
# addr(x[]) can't be proven, but addr(x) can:
|
||||
if not containsNode(n, {nkDerefExpr, nkHiddenDeref}): return
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ proc rawGetDeep[X, A](t: X, key: A, hc: var Hash): int {.inline.} =
|
|||
rawGetDeepImpl()
|
||||
|
||||
proc rawInsert[X, A, B](t: var X, data: var KeyValuePairSeq[A, B],
|
||||
key: A, val: B, hc: Hash, h: Hash) =
|
||||
key: A, val: sink B, hc: Hash, h: Hash) =
|
||||
rawInsertImpl()
|
||||
|
||||
template checkIfInitialized() =
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ proc initTable*[A, B](initialSize = defaultInitialSize): Table[A, B] =
|
|||
b = initTable[char, seq[int]]()
|
||||
initImpl(result, initialSize)
|
||||
|
||||
proc `[]=`*[A, B](t: var Table[A, B], key: A, val: B) =
|
||||
proc `[]=`*[A, B](t: var Table[A, B], key: A, val: sink B) =
|
||||
## Inserts a ``(key, value)`` pair into ``t``.
|
||||
##
|
||||
## See also:
|
||||
|
|
@ -484,7 +484,7 @@ proc len*[A, B](t: Table[A, B]): int =
|
|||
|
||||
result = t.counter
|
||||
|
||||
proc add*[A, B](t: var Table[A, B], key: A, val: B) {.deprecated:
|
||||
proc add*[A, B](t: var Table[A, B], key: A, val: sink B) {.deprecated:
|
||||
"Deprecated since v1.4; it was more confusing than useful, use `[]=`".} =
|
||||
## Puts a new ``(key, value)`` pair into ``t`` even if ``t[key]`` already exists.
|
||||
##
|
||||
|
|
@ -839,7 +839,7 @@ proc `[]`*[A, B](t: TableRef[A, B], key: A): var B =
|
|||
|
||||
result = t[][key]
|
||||
|
||||
proc `[]=`*[A, B](t: TableRef[A, B], key: A, val: B) =
|
||||
proc `[]=`*[A, B](t: TableRef[A, B], key: A, val: sink B) =
|
||||
## Inserts a ``(key, value)`` pair into ``t``.
|
||||
##
|
||||
## See also:
|
||||
|
|
@ -968,7 +968,7 @@ proc len*[A, B](t: TableRef[A, B]): int =
|
|||
|
||||
result = t.counter
|
||||
|
||||
proc add*[A, B](t: TableRef[A, B], key: A, val: B) {.deprecated:
|
||||
proc add*[A, B](t: TableRef[A, B], key: A, val: sink B) {.deprecated:
|
||||
"Deprecated since v1.4; it was more confusing than useful, use `[]=`".} =
|
||||
## Puts a new ``(key, value)`` pair into ``t`` even if ``t[key]`` already exists.
|
||||
##
|
||||
|
|
@ -1217,7 +1217,7 @@ proc rawGet[A, B](t: OrderedTable[A, B], key: A, hc: var Hash): int =
|
|||
|
||||
proc rawInsert[A, B](t: var OrderedTable[A, B],
|
||||
data: var OrderedKeyValuePairSeq[A, B],
|
||||
key: A, val: B, hc: Hash, h: Hash) =
|
||||
key: A, val: sink B, hc: Hash, h: Hash) =
|
||||
rawInsertImpl()
|
||||
data[h].next = -1
|
||||
if t.first < 0: t.first = h
|
||||
|
|
@ -1268,7 +1268,7 @@ proc initOrderedTable*[A, B](initialSize = defaultInitialSize): OrderedTable[A,
|
|||
b = initOrderedTable[char, seq[int]]()
|
||||
initImpl(result, initialSize)
|
||||
|
||||
proc `[]=`*[A, B](t: var OrderedTable[A, B], key: A, val: B) =
|
||||
proc `[]=`*[A, B](t: var OrderedTable[A, B], key: A, val: sink B) =
|
||||
## Inserts a ``(key, value)`` pair into ``t``.
|
||||
##
|
||||
## See also:
|
||||
|
|
@ -1455,7 +1455,7 @@ proc len*[A, B](t: OrderedTable[A, B]): int {.inline.} =
|
|||
|
||||
result = t.counter
|
||||
|
||||
proc add*[A, B](t: var OrderedTable[A, B], key: A, val: B) {.deprecated:
|
||||
proc add*[A, B](t: var OrderedTable[A, B], key: A, val: sink B) {.deprecated:
|
||||
"Deprecated since v1.4; it was more confusing than useful, use `[]=`".} =
|
||||
## Puts a new ``(key, value)`` pair into ``t`` even if ``t[key]`` already exists.
|
||||
##
|
||||
|
|
@ -1810,7 +1810,7 @@ proc `[]`*[A, B](t: OrderedTableRef[A, B], key: A): var B =
|
|||
echo a['z']
|
||||
result = t[][key]
|
||||
|
||||
proc `[]=`*[A, B](t: OrderedTableRef[A, B], key: A, val: B) =
|
||||
proc `[]=`*[A, B](t: OrderedTableRef[A, B], key: A, val: sink B) =
|
||||
## Inserts a ``(key, value)`` pair into ``t``.
|
||||
##
|
||||
## See also:
|
||||
|
|
@ -1939,7 +1939,7 @@ proc len*[A, B](t: OrderedTableRef[A, B]): int {.inline.} =
|
|||
|
||||
result = t.counter
|
||||
|
||||
proc add*[A, B](t: OrderedTableRef[A, B], key: A, val: B) {.deprecated:
|
||||
proc add*[A, B](t: OrderedTableRef[A, B], key: A, val: sink B) {.deprecated:
|
||||
"Deprecated since v1.4; it was more confusing than useful, use `[]=`".} =
|
||||
## Puts a new ``(key, value)`` pair into ``t`` even if ``t[key]`` already exists.
|
||||
##
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue