Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array type alias indexed via a type class can cause infinite recursion in the compiler #13184

Closed
refi64 opened this issue Jan 17, 2020 · 1 comment · Fixed by #24525
Closed

Comments

@refi64
Copy link
Contributor

refi64 commented Jan 17, 2020

I don't even know how to describe this, it's pretty weird:

Example

type
  TypeClass = uint | enum | int
  ArrayAlias[I: TypeClass] = array[I, int]

proc test[I: TypeClass](points: ArrayAlias[I]) =
  discard

Current Output

Hint: used config file '/var/home/ryan/code/Nim/config/nim.cfg' [Conf]
Hint: used config file '/var/home/ryan/code/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: tst [Processing]
Traceback (most recent call last)
/var/home/ryan/code/Nim/compiler/nim.nim(118) nim
/var/home/ryan/code/Nim/compiler/nim.nim(95) handleCmdLine
/var/home/ryan/code/Nim/compiler/cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
/var/home/ryan/code/Nim/compiler/main.nim(189) mainCommand
/var/home/ryan/code/Nim/compiler/main.nim(92) commandCompileToC
/var/home/ryan/code/Nim/compiler/modules.nim(142) compileProject
/var/home/ryan/code/Nim/compiler/modules.nim(83) compileModule
/var/home/ryan/code/Nim/compiler/passes.nim(213) processModule
/var/home/ryan/code/Nim/compiler/passes.nim(86) processTopLevelStmt
/var/home/ryan/code/Nim/compiler/sem.nim(600) myProcess
/var/home/ryan/code/Nim/compiler/sem.nim(568) semStmtAndGenerateGenerics
/var/home/ryan/code/Nim/compiler/semstmts.nim(2240) semStmt
/var/home/ryan/code/Nim/compiler/semexprs.nim(986) semExprNoType
/var/home/ryan/code/Nim/compiler/semexprs.nim(2758) semExpr
/var/home/ryan/code/Nim/compiler/semstmts.nim(2016) semProc
/var/home/ryan/code/Nim/compiler/semstmts.nim(1830) semProcAux
/var/home/ryan/code/Nim/compiler/semstmts.nim(1365) semParamList
/var/home/ryan/code/Nim/compiler/semtypes.nim(1188) semProcTypeNode
/var/home/ryan/code/Nim/compiler/semtypes.nim(1144) semParamType
/var/home/ryan/code/Nim/compiler/semtypes.nim(1743) semTypeNode
/var/home/ryan/code/Nim/compiler/semtypes.nim(1410) semGeneric
/var/home/ryan/code/Nim/compiler/sigmatch.nim(2520) matches
/var/home/ryan/code/Nim/compiler/sigmatch.nim(2458) matchesAux
/var/home/ryan/code/Nim/compiler/sigmatch.nim(2169) paramTypesMatch
/var/home/ryan/code/Nim/compiler/sigmatch.nim(2013) paramTypesMatchAux
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1680) typeRel
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1086) typeRel
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1586) typeRel
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1075) typeRel
(clipped stack trace so it doesn't take up the whole issue)
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1075) typeRel
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1075) typeRel
/var/home/ryan/code/Nim/compiler/sigmatch.nim(1073) typeRel
/var/home/ryan/code/Nim/compiler/astalgo.nim(899) idTableGet
/var/home/ryan/code/Nim/compiler/astalgo.nim idTableRawGet
Error: call depth limit reached in a debug build (2000 function calls). You can change it with -d:nimCallDepthLimit=<int> but really try to avoid deep recursions instead.

Additional Information

When I originally stumbled upon this, the type class was SomeOrdinal.

I've reduced it to the type class needing to contain those three types. The two integral types can be swapped out with others and the issue will still appear, but the enum must remain in the middle to reproduce the error. Moving it to the beginning or end will result in successful compilation.

If you remove the I: TypeClass from the proc, the compilation will succeed.

If a constrained alias is not used (e.g. the proc contains the array directly in its signature), the compilation will succeed.

Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-12-11
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release -d:useLinenoise

This is also reproducible on git master.

@metagn
Copy link
Collaborator

metagn commented Jun 24, 2023

This now works? Maybe a more complex test case is needed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants