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

Simple type definition crash #12897

Closed
Clyybber opened this issue Dec 14, 2019 · 2 comments
Closed

Simple type definition crash #12897

Clyybber opened this issue Dec 14, 2019 · 2 comments

Comments

@Clyybber
Copy link
Contributor

The following crashes the compiler (assertion fails in int128)

Example

type
  TileCT[n: static int] = object
    a: array[n, int]
  Tile = TileCT #Commenting this out to make it work

Current Output

/home/clyybber/builds/nim/compiler/nim.nim(106) nim
/home/clyybber/builds/nim/compiler/nim.nim(83) handleCmdLine
/home/clyybber/builds/nim/compiler/cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
/home/clyybber/builds/nim/compiler/main.nim(188) mainCommand
/home/clyybber/builds/nim/compiler/main.nim(92) commandCompileToC
/home/clyybber/builds/nim/compiler/modules.nim(144) compileProject
/home/clyybber/builds/nim/compiler/modules.nim(85) compileModule
/home/clyybber/builds/nim/compiler/passes.nim(210) processModule
/home/clyybber/builds/nim/compiler/passes.nim(86) processTopLevelStmt
/home/clyybber/builds/nim/compiler/sem.nim(600) myProcess
/home/clyybber/builds/nim/compiler/sem.nim(568) semStmtAndGenerateGenerics
/home/clyybber/builds/nim/compiler/semstmts.nim(2218) semStmt
/home/clyybber/builds/nim/compiler/semexprs.nim(986) semExprNoType
/home/clyybber/builds/nim/compiler/semexprs.nim(2740) semExpr
/home/clyybber/builds/nim/compiler/semstmts.nim(2158) semStmtList
/home/clyybber/builds/nim/compiler/semexprs.nim(2745) semExpr
/home/clyybber/builds/nim/compiler/semstmts.nim(1359) semTypeSection
/home/clyybber/builds/nim/compiler/semstmts.nim(1297) typeSectionFinalPass
/home/clyybber/builds/nim/compiler/semtypinst.nim(27) checkConstructedType
/home/clyybber/builds/nim/compiler/types.nim(1390) computeSize
/home/clyybber/builds/nim/compiler/sizealignoffsetimpl.nim(405) computeSizeAlign
/home/clyybber/builds/nim/compiler/sizealignoffsetimpl.nim(382) computeSizeAlign
/home/clyybber/builds/nim/compiler/sizealignoffsetimpl.nim(150) computeObjectOffsetsFoldFunction
/home/clyybber/builds/nim/compiler/sizealignoffsetimpl.nim(155) computeObjectOffsetsFoldFunction
/home/clyybber/builds/nim/compiler/sizealignoffsetimpl.nim(264) computeSizeAlign
/home/clyybber/builds/nim/compiler/int128.nim(338) *
/home/clyybber/builds/nim/compiler/int128.nim(330) *
/home/clyybber/builds/nim/lib/system/assertions.nim(27) failedAssertImpl
/home/clyybber/builds/nim/lib/system/assertions.nim(20) raiseAssert
/home/clyybber/builds/nim/lib/system/fatal.nim(39) sysFatal
Error: unhandled exception: /home/clyybber/builds/nim/compiler/int128.nim(330, 11) `false` overflow [AssertionError]
$ nim -v
Nim Compiler Version 1.1.1 (#devel)
@Clyybber
Copy link
Contributor Author

Using Tile[n: static int] = TileCT[n] works as a workaround for now, but shouldn't be needed.

@krux02
Copy link
Contributor

krux02 commented Dec 16, 2019

The following condition tests if a type has generic parameters in typeSectionFinalPass.

if a[1].kind == nkEmpty:

Generic types should be skipped in this pass. Since the expression Tile = TileCT has no explicit generic parameters, it isn't skipped here even though it should. The incomplete type gets size computation and that causes an int128 undorflow (crash in debug mode). This also explains why Tile[n: static int] = TileCT[n] does prevent the crash, because here the generic parameters are explicitly listed.

My recommended solution to this problem is that the type alias infers the generic parameters in the way that Tile = TileCT is internally converted into Tile[n: static int] = TileCT[n]. size computation and the listed condition doesn't need to be touched.

Clyybber added a commit to Clyybber/Nim that referenced this issue Nov 6, 2020
narimiran pushed a commit that referenced this issue Nov 9, 2020
(cherry picked from commit 60c364f)
PMunch pushed a commit to PMunch/Nim that referenced this issue Jan 6, 2021
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
irdassis pushed a commit to irdassis/Nim that referenced this issue Mar 16, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants