Skip to content

Commit

Permalink
Remove confusing <//> (nim-lang#17830)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Apr 26, 2021
1 parent 9e6f2d7 commit 68e522e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
5 changes: 1 addition & 4 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1290,10 +1290,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
put(g, tkSpaces, Space)
infixArgument(g, n, 2)
of nkPrefix:
if n.len > 0 and n[0].kind == nkIdent and n[0].ident.s == "<//>":
discard "XXX Remove this hack after 0.20 has been released!"
else:
gsub(g, n, 0)
gsub(g, n, 0)
if n.len > 1:
let opr = if n[0].kind == nkIdent: n[0].ident
elif n[0].kind == nkSym: n[0].sym.name
Expand Down
14 changes: 7 additions & 7 deletions lib/pure/collections/lists.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type
## A node of a doubly linked list.
##
## It consists of a `value` field, and pointers to `next` and `prev`.
next*: <//>(DoublyLinkedNode[T])
next*: DoublyLinkedNode[T]
prev* {.cursor.}: DoublyLinkedNode[T]
value*: T
DoublyLinkedNode*[T] = ref DoublyLinkedNodeObj[T]
Expand All @@ -77,23 +77,23 @@ type
## A node of a singly linked list.
##
## It consists of a `value` field, and a pointer to `next`.
next*: <//>(SinglyLinkedNode[T])
next*: SinglyLinkedNode[T]
value*: T
SinglyLinkedNode*[T] = ref SinglyLinkedNodeObj[T]

SinglyLinkedList*[T] = object
## A singly linked list.
head*: <//>(SinglyLinkedNode[T])
head*: SinglyLinkedNode[T]
tail* {.cursor.}: SinglyLinkedNode[T]

DoublyLinkedList*[T] = object
## A doubly linked list.
head*: <//>(DoublyLinkedNode[T])
head*: DoublyLinkedNode[T]
tail* {.cursor.}: DoublyLinkedNode[T]

SinglyLinkedRing*[T] = object
## A singly linked ring.
head*: <//>(SinglyLinkedNode[T])
head*: SinglyLinkedNode[T]
tail* {.cursor.}: SinglyLinkedNode[T]

DoublyLinkedRing*[T] = object
Expand Down Expand Up @@ -148,7 +148,7 @@ proc initDoublyLinkedRing*[T](): DoublyLinkedRing[T] =

discard

proc newDoublyLinkedNode*[T](value: T): <//>(DoublyLinkedNode[T]) =
proc newDoublyLinkedNode*[T](value: T): DoublyLinkedNode[T] =
## Creates a new doubly linked node with the given `value`.
runnableExamples:
let n = newDoublyLinkedNode[int](5)
Expand All @@ -157,7 +157,7 @@ proc newDoublyLinkedNode*[T](value: T): <//>(DoublyLinkedNode[T]) =
new(result)
result.value = value

proc newSinglyLinkedNode*[T](value: T): <//>(SinglyLinkedNode[T]) =
proc newSinglyLinkedNode*[T](value: T): SinglyLinkedNode[T] =
## Creates a new singly linked node with the given `value`.
runnableExamples:
let n = newSinglyLinkedNode[int](5)
Expand Down
14 changes: 7 additions & 7 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ iterator allValues*[A, B](t: Table[A, B]; key: A): B {.deprecated:
# -------------------------------------------------------------------


proc newTable*[A, B](initialSize = defaultInitialSize): <//>TableRef[A, B] =
proc newTable*[A, B](initialSize = defaultInitialSize): TableRef[A, B] =
## Creates a new ref hash table that is empty.
##
## See also:
Expand All @@ -810,7 +810,7 @@ proc newTable*[A, B](initialSize = defaultInitialSize): <//>TableRef[A, B] =
new(result)
result[] = initTable[A, B](initialSize)

proc newTable*[A, B](pairs: openArray[(A, B)]): <//>TableRef[A, B] =
proc newTable*[A, B](pairs: openArray[(A, B)]): TableRef[A, B] =
## Creates a new ref hash table that contains the given `pairs`.
##
## `pairs` is a container consisting of `(key, value)` tuples.
Expand All @@ -826,7 +826,7 @@ proc newTable*[A, B](pairs: openArray[(A, B)]): <//>TableRef[A, B] =
new(result)
result[] = toTable[A, B](pairs)

proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): <//>TableRef[C, B] =
proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): TableRef[C, B] =
## Index the collection with the proc provided.
# TODO: As soon as supported, change collection: A to collection: A[B]
result = newTable[C, B]()
Expand Down Expand Up @@ -1790,7 +1790,7 @@ iterator mvalues*[A, B](t: var OrderedTable[A, B]): var B =
# --------------------------- OrderedTableRef -------------------------------
# ---------------------------------------------------------------------------

proc newOrderedTable*[A, B](initialSize = defaultInitialSize): <//>OrderedTableRef[A, B] =
proc newOrderedTable*[A, B](initialSize = defaultInitialSize): OrderedTableRef[A, B] =
## Creates a new ordered ref hash table that is empty.
##
## See also:
Expand All @@ -1805,7 +1805,7 @@ proc newOrderedTable*[A, B](initialSize = defaultInitialSize): <//>OrderedTableR
new(result)
result[] = initOrderedTable[A, B](initialSize)

proc newOrderedTable*[A, B](pairs: openArray[(A, B)]): <//>OrderedTableRef[A, B] =
proc newOrderedTable*[A, B](pairs: openArray[(A, B)]): OrderedTableRef[A, B] =
## Creates a new ordered ref hash table that contains the given `pairs`.
##
## `pairs` is a container consisting of `(key, value)` tuples.
Expand Down Expand Up @@ -2610,7 +2610,7 @@ iterator mvalues*[A](t: var CountTable[A]): var int =

proc inc*[A](t: CountTableRef[A], key: A, val = 1)

proc newCountTable*[A](initialSize = defaultInitialSize): <//>CountTableRef[A] =
proc newCountTable*[A](initialSize = defaultInitialSize): CountTableRef[A] =
## Creates a new ref count table that is empty.
##
## See also:
Expand All @@ -2621,7 +2621,7 @@ proc newCountTable*[A](initialSize = defaultInitialSize): <//>CountTableRef[A] =
new(result)
result[] = initCountTable[A](initialSize)

proc newCountTable*[A](keys: openArray[A]): <//>CountTableRef[A] =
proc newCountTable*[A](keys: openArray[A]): CountTableRef[A] =
## Creates a new ref count table with every member of a container `keys`
## having a count of how many times it occurs in that container.
result = newCountTable[A](keys.len)
Expand Down
10 changes: 5 additions & 5 deletions lib/pure/parsecfg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,17 @@ proc next*(c: var CfgParser): CfgEvent {.rtl, extern: "npc$1".} =

# ---------------- Configuration file related operations ----------------
type
Config* = OrderedTableRef[string, <//>OrderedTableRef[string, string]]
Config* = OrderedTableRef[string, OrderedTableRef[string, string]]

proc newConfig*(): Config =
## Creates a new configuration table.
## Useful when wanting to create a configuration file.
result = newOrderedTable[string, <//>OrderedTableRef[string, string]]()
result = newOrderedTable[string, OrderedTableRef[string, string]]()

proc loadConfig*(stream: Stream, filename: string = "[stream]"): <//>Config =
proc loadConfig*(stream: Stream, filename: string = "[stream]"): Config =
## Loads the specified configuration from stream into a new Config instance.
## `filename` parameter is only used for nicer error messages.
var dict = newOrderedTable[string, <//>OrderedTableRef[string, string]]()
var dict = newOrderedTable[string, OrderedTableRef[string, string]]()
var curSection = "" ## Current section,
## the default value of the current section is "",
## which means that the current section is a common
Expand Down Expand Up @@ -536,7 +536,7 @@ proc loadConfig*(stream: Stream, filename: string = "[stream]"): <//>Config =
close(p)
result = dict

proc loadConfig*(filename: string): <//>Config =
proc loadConfig*(filename: string): Config =
## Loads the specified configuration file into a new Config instance.
let file = open(filename, fmRead)
let fileStream = newFileStream(file)
Expand Down
6 changes: 3 additions & 3 deletions lib/pure/unittest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ proc resetOutputFormatters* {.since: (1, 1).} =
formatters = @[]

proc newConsoleOutputFormatter*(outputLevel: OutputLevel = outputLevelDefault,
colorOutput = true): <//>ConsoleOutputFormatter =
colorOutput = true): ConsoleOutputFormatter =
ConsoleOutputFormatter(
outputLevel: outputLevel,
colorOutput: colorOutput
Expand Down Expand Up @@ -246,7 +246,7 @@ proc colorOutput(): bool =
deprecateEnvVarHere()
result = false

proc defaultConsoleFormatter*(): <//>ConsoleOutputFormatter =
proc defaultConsoleFormatter*(): ConsoleOutputFormatter =
var colorOutput = colorOutput()
var outputLevel = nimUnittestOutputLevel.parseEnum[:OutputLevel]
when declared(stdout):
Expand Down Expand Up @@ -315,7 +315,7 @@ proc xmlEscape(s: string): string =
else:
result.add(c)

proc newJUnitOutputFormatter*(stream: Stream): <//>JUnitOutputFormatter =
proc newJUnitOutputFormatter*(stream: Stream): JUnitOutputFormatter =
## Creates a formatter that writes report to the specified stream in
## JUnit format.
## The ``stream`` is NOT closed automatically when the test are finished,
Expand Down
4 changes: 0 additions & 4 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,6 @@ when defined(nimOwnedEnabled) and not defined(nimscript):
proc unown*[T](x: T): T {.magic: "Unown", noSideEffect.}
## Use the expression `x` ignoring its ownership attribute.

# This is only required to make 0.20 compile with the 0.19 line.
template `<//>`*(t: untyped): untyped = owned(t)

else:
template unown*(x: typed): untyped = x
Expand All @@ -908,8 +906,6 @@ else:
new(r)
return r

# This is only required to make 0.20 compile with the 0.19 line.
template `<//>`*(t: untyped): untyped = t

template disarm*(x: typed) =
## Useful for `disarming` dangling pointers explicitly for `--newruntime`.
Expand Down
7 changes: 6 additions & 1 deletion tests/destructor/tnewruntime_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ putEnv("HEAPTRASHING", "Indeed")

let s1 = getAllocStats()


proc newTableOwned[A, B](initialSize = defaultInitialSize): owned(TableRef[A, B]) =
new(result)
result[] = initTable[A, B](initialSize)

proc main =
var w = newTable[string, owned Node]()
var w = newTableOwned[string, owned Node]()
w["key"] = Node(field: "value")
echo w["key"][]
echo getEnv("HEAPTRASHING")
Expand Down

0 comments on commit 68e522e

Please sign in to comment.