Skip to content

Instantly share code, notes, and snippets.

@timotheecour
Last active July 6, 2021 18:46
Show Gist options
  • Save timotheecour/5b8b1f1602ce3876ba38b189fe14e6a6 to your computer and use it in GitHub Desktop.
Save timotheecour/5b8b1f1602ce3876ba38b189fe14e6a6 to your computer and use it in GitHub Desktop.
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 2a2a84e76..857aa13ca 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -1173,9 +1173,15 @@ when defined(useNodeIds):
const nodeIdToDebug* = -1 # 2322968
var gNodeId: int
+var totNode* = 0
+var totSym* = 0
+var sideEffectsMax* = 0
+var sideEffectsTot* = 0
+
proc newNode*(kind: TNodeKind): PNode =
## new node with unknown line info, no type, and no children
result = PNode(kind: kind, info: unknownLineInfo)
+ totNode.inc
when defined(useNodeIds):
result.id = gNodeId
if result.id == nodeIdToDebug:
@@ -1186,6 +1192,7 @@ proc newNode*(kind: TNodeKind): PNode =
proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode =
## new node with line info, no type, and no children
result = PNode(kind: kind, info: info)
+ totNode.inc
when defined(useNodeIds):
result.id = gNodeId
if result.id == nodeIdToDebug:
@@ -1196,6 +1203,7 @@ proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode =
proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode =
## new node with line info, type, and children
result = PNode(kind: kind, info: info)
+ totNode.inc
if children > 0:
newSeq(result.sons, children)
when defined(useNodeIds):
@@ -1246,6 +1254,7 @@ proc newSym*(symKind: TSymKind, name: PIdent, id: ItemId, owner: PSym,
# generates a symbol and initializes the hash field too
result = PSym(name: name, kind: symKind, flags: {}, info: info, itemId: id,
options: options, owner: owner, offset: defaultOffset)
+ totSym.inc
when false:
if id.module == 48 and id.item == 39:
writeStackTrace()
diff --git a/compiler/nim.nim b/compiler/nim.nim
index 91b1bc2db..5b01b0fe9 100644
--- a/compiler/nim.nim
+++ b/compiler/nim.nim
@@ -25,7 +25,7 @@ when defined(windows) and not defined(nimKochBootstrap):
import
commands, options, msgs, extccomp, main, idents, lineinfos, cmdlinehelper,
- pathutils, modulegraphs
+ pathutils, modulegraphs, ast
from browsers import openDefaultBrowser
from nodejs import findNodeJs
@@ -128,4 +128,5 @@ when not defined(selftest):
handleCmdLine(newIdentCache(), conf)
when declared(GC_setMaxPause):
echo GC_getStatistics()
+ echo (totNode: totNode, totSym: totSym, sideEffectsMax: sideEffectsMax, sideEffectsTot: sideEffectsTot)
msgQuit(int8(conf.errorCounter > 0))
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index beb5587f5..17fec5464 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -237,6 +237,8 @@ proc markSideEffect(a: PEffects; reason: PNode | PSym; useLoc: TLineInfo) =
else:
sym = reason
a.c.sideEffects.mgetOrPut(a.owner.id, @[]).add (useLoc, sym)
+ sideEffectsMax = max(sideEffectsMax, a.c.sideEffects.len)
+ sideEffectsTot.inc
when false: markGcUnsafe(a, reason)
proc listGcUnsafety(s: PSym; onlyWarning: bool; cycleCheck: var IntSet; conf: ConfigRef) =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment