This commit is contained in:
Araq 2014-11-16 20:32:05 +01:00
commit 8349cee613
5 changed files with 56 additions and 15 deletions

View file

@ -1055,7 +1055,7 @@ proc discardSons(father: PNode) =
father.sons = nil father.sons = nil
when defined(useNodeIds): when defined(useNodeIds):
const nodeIdToDebug* = 310841 # 612794 const nodeIdToDebug* = -1 # 884953 # 612794
#612840 # 612905 # 614635 # 614637 # 614641 #612840 # 612905 # 614635 # 614637 # 614641
# 423408 # 423408
#429107 # 430443 # 441048 # 441090 # 441153 #429107 # 430443 # 441048 # 441090 # 441153

View file

@ -157,8 +157,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
# #
# The solution would be to move this logic into semtypinst, but # The solution would be to move this logic into semtypinst, but
# at this point semtypinst have to become part of sem, because it # at this point semtypinst have to become part of sem, because it
# will need to use openScope, addDecl, etc # will need to use openScope, addDecl, etc.
#
addDecl(c, prc) addDecl(c, prc)
pushInfoContext(info) pushInfoContext(info)
@ -223,7 +222,11 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
n.sons[genericParamsPos] = ast.emptyNode n.sons[genericParamsPos] = ast.emptyNode
var oldPrc = genericCacheGet(fn, entry[]) var oldPrc = genericCacheGet(fn, entry[])
if oldPrc == nil: if oldPrc == nil:
fn.procInstCache.safeAdd(entry) # we MUST not add potentially wrong instantiations to the caching mechanism.
# This means recursive instantiations behave differently when in
# a ``compiles`` context but this is the lesser evil. See
# bug #1055 (tevilcompiles).
if c.inCompilesContext == 0: fn.procInstCache.safeAdd(entry)
c.generics.add(makeInstPair(fn, entry)) c.generics.add(makeInstPair(fn, entry))
if n.sons[pragmasPos].kind != nkEmpty: if n.sons[pragmasPos].kind != nkEmpty:
pragma(c, result, n.sons[pragmasPos], allRoutinePragmas) pragma(c, result, n.sons[pragmasPos], allRoutinePragmas)

View file

@ -118,6 +118,34 @@ Thus we need to serialize this graph as RTTI for C code generation.
Look at the file ``lib/system/hti.nim`` for more information. Look at the file ``lib/system/hti.nim`` for more information.
Debugging the compiler
======================
You can of course use GDB or Visual Studio to debug the
compiler (via ``--debuginfo --lineDir:on``). However, there
are also lots of procs that aid in debugging:
.. code-block:: nim
# pretty prints the Nim AST
echo renderTree(someNode)
# outputs some JSON representation
debug(someNode)
# pretty prints some type
echo typeToString(someType)
debug(someType)
echo symbol.name.s
debug(symbol)
# pretty prints the nimrod ast, but annotates symbol IDs:
echo renderTree(someNode, {renderIds})
if n.info ?? "temp.nim":
# only output when it comes from "temp.nim"
echo renderTree(n)
if n.info ?? "temp.nim":
# why does it process temp.nim here?
writeStackTrace()
The compiler's architecture The compiler's architecture
=========================== ===========================
@ -255,13 +283,11 @@ turned on".
Debugging Nim's memory management Debugging Nim's memory management
==================================== =================================
The following paragraphs are mostly a reminder for myself. Things to keep The following paragraphs are mostly a reminder for myself. Things to keep
in mind: in mind:
* Segmentation faults can have multiple reasons: One that is frequently
forgotten is that *stack overflow* can trigger one!
* If an assertion in Nim's memory manager or GC fails, the stack trace * If an assertion in Nim's memory manager or GC fails, the stack trace
keeps allocating memory! Thus a stack overflow may happen, hiding the keeps allocating memory! Thus a stack overflow may happen, hiding the
real issue. real issue.
@ -304,8 +330,8 @@ modifying a ``TCellSet`` during traversation leads to undefined behaviour.
type type
TCellSet # hidden TCellSet # hidden
proc CellSetInit(s: var TCellSet) # initialize a new set proc cellSetInit(s: var TCellSet) # initialize a new set
proc CellSetDeinit(s: var TCellSet) # empty the set and free its memory proc cellSetDeinit(s: var TCellSet) # empty the set and free its memory
proc incl(s: var TCellSet, elem: PCell) # include an element proc incl(s: var TCellSet, elem: PCell) # include an element
proc excl(s: var TCellSet, elem: PCell) # exclude an element proc excl(s: var TCellSet, elem: PCell) # exclude an element
@ -493,7 +519,7 @@ Accumulator
----------- -----------
.. code-block:: nim .. code-block:: nim
proc GetAccumulator(start: int): proc (): int {.closure} = proc getAccumulator(start: int): proc (): int {.closure} =
var i = start var i = start
return lambda: int = return lambda: int =
inc i inc i

View file

@ -728,7 +728,7 @@ proc renderTocEntry(d: PDoc, e: TTocEntry, result: var string) =
"\\item\\label{$1_toc} $2\\ref{$1}\n", [e.refname, e.header]) "\\item\\label{$1_toc} $2\\ref{$1}\n", [e.refname, e.header])
proc renderTocEntries*(d: var TRstGenerator, j: var int, lvl: int, proc renderTocEntries*(d: var TRstGenerator, j: var int, lvl: int,
result: var string) = result: var string) =
var tmp = "" var tmp = ""
while j <= high(d.tocPart): while j <= high(d.tocPart):
var a = abs(d.tocPart[j].n.level) var a = abs(d.tocPart[j].n.level)

View file

@ -0,0 +1,12 @@
# bug #1055
import unittest
type TMatrix*[N,M: static[int], T] = object
data*: array[0..N*M-1, T]
proc `==`*(a: distinct TMatrix; b: distinct TMatrix): bool =
result = a.data == b.data
test "c":
var a = TMatrix[2,2,int](data: [1,2,3,4])
var b = TMatrix[2,2,int](data: [1,2,3,4])
check(a == b)