nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.54k stars 1.47k forks source link

internal error: getTypeDescAux(tyGenericParam) #16148

Open pb-cdunn opened 3 years ago

pb-cdunn commented 3 years ago

Build fails for devel. Works for older versions.

Example

Error: internal error: getTypeDescAux(tyGenericParam)
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details

I see the same problem in #13378 (10 Feb), so it must happen from time to time. I don't know where it occurs yet.

Additional Information

$ nim --version
Nim Compiler Version 1.5.1 [MacOSX: amd64]
Compiled at 2020-11-26
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 3e7077ac7d2f4867ecabff09b730b6bc9356979d
active boot switches: -d:release

It works fine with 1.4.0 and 1.2.6, and was working with slightly older devel. E.g it works fine at

bc3c0487d (origin/devel, origin/HEAD) remove ioutils mention in changelog (#15907)

I wish I knew how to fix that "No stack traceback available" problem via choosenim. I'm trying to build nim myself now ...

$ ./koch boot -d:debug
$ make # my code
Error: internal error: getTypeDescAux(tyGenericParam)
Traceback (most recent call last)
/Users/cdunn/repo/gh/Nim/compiler/nim.nim(119) nim
/Users/cdunn/repo/gh/Nim/compiler/nim.nim(84) handleCmdLine
/Users/cdunn/repo/gh/Nim/compiler/main.nim(240) mainCommand
...
/Users/cdunn/repo/gh/Nim/compiler/ccgstmts.nim(1581) genStmts
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2772) expr
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2545) genStmtList
/Users/cdunn/repo/gh/Nim/compiler/ccgstmts.nim(1581) genStmts
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2773) expr
/Users/cdunn/repo/gh/Nim/compiler/ccgstmts.nim(440) genIf
/Users/cdunn/repo/gh/Nim/compiler/cgen.nim(632) initLocExprSingleUse
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2740) expr
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2254) genMagicExpr
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(615) binaryArith
/Users/cdunn/repo/gh/Nim/compiler/cgen.nim(619) initLocExpr
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(2720) expr
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(103) genLiteral
/Users/cdunn/repo/gh/Nim/compiler/ccgexprs.nim(77) genLiteral
/Users/cdunn/repo/gh/Nim/compiler/ccgtypes.nim(936) getTypeDesc
/Users/cdunn/repo/gh/Nim/compiler/ccgtypes.nim(760) getTypeDescAux
/Users/cdunn/repo/gh/Nim/compiler/ccgtypes.nim(929) getTypeDescAux
/Users/cdunn/repo/gh/Nim/compiler/msgs.nim(584) internalErrorImpl
/Users/cdunn/repo/gh/Nim/compiler/msgs.nim(540) liMessage
/Users/cdunn/repo/gh/Nim/compiler/msgs.nim(406) handleError
/Users/cdunn/repo/gh/Nim/compiler/msgs.nim(395) quit

I guess that's not very helpful. I'll try to git-bisect the compiler, unless someone has a better idea.

pb-cdunn commented 3 years ago

Still works at

commit 33d79b9e64f8f67adcf8415de61d1568630e36cb (HEAD)
Author: Timothee Cour <timothee.cour2@gmail.com>
Date:   Wed Nov 18 05:01:43 2020

Fails at

commit 87d3e5331a7838aa255deca8a840c2080b5424ce (HEAD)
Author: cooldome <ariabushenko@gmail.com>
Date:   Wed Nov 18 11:19:57 2020

    Semfold for nil cast (#16030)
    * bring back the semfold of nil
    * remove space
    * fix test
    * proc type can't be dereferenced

That's repeatable, so it's definitely that commit.

pb-cdunn commented 3 years ago

And it fails at several later commits, every one that I tried. It seems to be that particular change, which is fairly small.

pb-cdunn commented 3 years ago

If you want to reproduce this, here is my source code: https://github.com/bio-nim/pb-falconc (develop branch)

You need to install htslib and zlib. (Via macports or homebrew is fine.) Otherwise, it has all its own dependencies, in the vendor subdirs.

make rsync
make build

Since most of our macros come from cligen, I updated to the latest cligen on the cligen-update branch. No difference.

pb-cdunn commented 3 years ago

@c-blake , any ideas?

cooldome commented 3 years ago

@pb-cdunn, I can't install pb-falconc I am afraid.

Let's try this trick instead. Could you please add one line at ccgexprs.nim(77) in proc genLiteral:

echo toFileLineCol(p.module.g.graph.config, n.info), ": ", n

and compile nim_temp with koch temp. Recompile your project with koch temp.

Added echo should give lineinfo of offending line just before the crash. This should give you indication of what function actually causing problem and help preparing a test case.

c-blake commented 3 years ago

Sorry to be of no help, but holiday here makes it hard to contribute, but good luck. I have not seen this arise before, though.

pb-cdunn commented 3 years ago

I'm adding that now. But could you explain a bit more on nim_temp? I saw info on that, but I did not understand. koch is not in the bin, so how can I use koch temp. I tried using nim_temp ... (after koch temp in Nim repo), and that worked.

Anyway,

falconc/src/falconcpkg/falcon/sys.nim(76, 26) Error: compiler was built without 'spawn' support

Is that the problem?

pb-cdunn commented 3 years ago

I did a full ./koch boot, rebuilt my codebase, and got this:

...
/Users/cdunn/repo/gh/Nim/lib/system.nim(2011, 57): nil
/Users/cdunn/repo/bb/falconc/src/falconcpkg/raptor_db.nim(266, 8): nil
Error: internal error: getTypeDescAux(tyGenericParam)

https://github.com/bio-nim/pb-falconc/blob/develop/src/falconcpkg/raptor_db.nim#L266

proc alarm(e: ref Exception, fn: string) =
    ## Write a special JSON object expected by pbcommand.models.common.
    var fout = open(fn, fmWrite)
    if nil == fout:   # <<< line 266
pb-cdunn commented 3 years ago

File is ptr CFile, should that should be comparable to nil, right?

cooldome commented 3 years ago

hmm, I expected to see some generic functions because of tyGenericParam. Something didn't go well during experiment.

cooldome commented 3 years ago

Just checking, did you put echo above this line right?

 result = "(($1) NIM_NIL)" % [getTypeDesc(p.module, ty)]
pb-cdunn commented 3 years ago
 git diff
diff --git compiler/ccgexprs.nim compiler/ccgexprs.nim
index ec28eb1ec..2947dabc0 100644
--- compiler/ccgexprs.nim
+++ compiler/ccgexprs.nim
@@ -74,6 +74,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
     elif k in {tyPointer, tyNil, tyProc}:
       result = rope("NIM_NIL")
     else:
+      echo toFileLineCol(p.module.g.graph.config, n.info), ": ", n
       result = "(($1) NIM_NIL)" % [getTypeDesc(p.module, ty)]
   of nkStrLit..nkTripleStrLit:
     let k = if ty == nil: tyString
cooldome commented 3 years ago

looks good, not sure why it doesn't help then

jrfondren commented 3 years ago
when defined(good):
  var s: cstring
when defined(bad):
  var s: ptr char

when defined(op1):
  discard s.isNil
when defined(op2):
  discard s != nil
when defined(op3):
  discard nil != s
when defined(op4):
  discard isNil s

1.4.0 can compile all variants. 1.4.2 can compile all variants except for -d:bad -d:op3

var s: ptr char
discard nil != s
Error: internal error: getTypeDescAux(tyGenericParam)
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details
Nim Compiler Version 1.4.2 [Linux: amd64]
Compiled at 2020-11-30
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 3fb5157ab1b666a5a5c34efde0f357a82d433d04
active boot switches: -d:release
pb-cdunn commented 3 years ago

@jrfondren , you've found the problem! When I switch

if nil == fout:   # <<< line 266

to

if fout == nil:

it works. So this is the bug.

brentp commented 3 years ago

bump. I am hitting this as well.