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

Orc compiler crash when not making object from lineInfoObj into a literal #21326

Closed
HugoGranstrom opened this issue Feb 3, 2023 · 1 comment · Fixed by #21433
Closed

Orc compiler crash when not making object from lineInfoObj into a literal #21326

HugoGranstrom opened this issue Feb 3, 2023 · 1 comment · Fixed by #21433

Comments

@HugoGranstrom
Copy link
Contributor

Description

import macros

macro foo(body: untyped): untyped =
  let a = body.lineInfoObj()
  let aLit = a.newLit
  result = quote do:
    echo `a` # `aLit` works though

foo:
  let c = 1

This bug was discovered when testing latest nimib against devel (see @ringabout's stacktrace here). The problem is that for some reason beyond me, the compiler crashes with a SIGSEGV: Illegal storage access. (Attempt to read from nil?) when running this code on orc/arc but not on refc. And I have only been able to reproduce it using the object returned by lineInfoObj. Creating a LineInfo object directly does not trigger this bug:

let a = LineInfo()

I have also tried creating my own objects and returning them from functions but without any success in reproducing this.

The way to make the example code work is to convert a to a literal with a.newLit and then it compiles.

Nim Version

Nim Compiler Version 1.9.1 [Linux: amd64]
Compiled at 2023-02-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 8e53fba
active boot switches: -d:release

Current Output

C:\Users\blue\Desktop\Nim\compiler\nim.nim(167) nim
C:\Users\blue\Desktop\Nim\compiler\nim.nim(122) handleCmdLine
C:\Users\blue\Desktop\Nim\compiler\main.nim(307) mainCommand
C:\Users\blue\Desktop\Nim\compiler\main.nim(276) compileToBackend
C:\Users\blue\Desktop\Nim\compiler\main.nim(130) commandCompileToC
C:\Users\blue\Desktop\Nim\compiler\modules.nim(136) compileProject
C:\Users\blue\Desktop\Nim\compiler\modules.nim(56) compileModule
C:\Users\blue\Desktop\Nim\compiler\passes.nim(186) processModule
C:\Users\blue\Desktop\Nim\compiler\passes.nim(79) processTopLevelStmt
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(2021) myProcess
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(2015) genTopLevelStmt
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(1064) genProcBody
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1636) genStmts
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3071) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(2765) genStmtList
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1636) genStmts
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3121) expr
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1271) genTryGoto
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3071) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(2765) genStmtList
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1636) genStmts
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3071) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(2754) genStmtList
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1636) genStmts
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3024) expr
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(830) genCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(828) genAsgnCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(429) genPrefixCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(407) genParams
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(312) genArg
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(687) initLocExprSingleUse
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3030) expr
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(830) genCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(828) genAsgnCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(429) genPrefixCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(407) genParams
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(312) genArg
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(687) initLocExprSingleUse
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3070) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(2761) genStmtListExpr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3070) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(2754) genStmtListExpr
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1636) genStmts
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3109) expr
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(1629) genAsgn
C:\Users\blue\Desktop\Nim\compiler\ccgstmts.nim(136) loadInto
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(828) genAsgnCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(429) genPrefixCall
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(407) genParams
C:\Users\blue\Desktop\Nim\compiler\ccgcalls.nim(294) genArg
C:\Users\blue\Desktop\Nim\compiler\cgen.nim(674) initLocExpr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3052) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(1579) genObjConstr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(3009) expr
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(482) putDataIntoDest
C:\Users\blue\Desktop\Nim\compiler\ccgexprs.nim(323) genAssignment
C:\Users\blue\Desktop\Nim\compiler\ast.nim(1454) skipTypes
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

No crash

Possible Solution

No response

Additional Information

No response

@ringabout
Copy link
Member

It seems to be a common problem of VM, whose types disappear after evaluation. I might check semmacrosanity.

@ringabout ringabout self-assigned this Feb 22, 2023
Araq pushed a commit that referenced this issue Mar 2, 2023
…; `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (#21433)

* fixes #21326; getAst uses type info to annotateType quoted variables

* simplify logics; sem types first

* fixes important packages

* add testcases

* tiny
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…nim-lang#9607; rework quote do; `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (nim-lang#21433)

* fixes nim-lang#21326; getAst uses type info to annotateType quoted variables

* simplify logics; sem types first

* fixes important packages

* add testcases

* tiny
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…nim-lang#9607; rework quote do; `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (nim-lang#21433)

* fixes nim-lang#21326; getAst uses type info to annotateType quoted variables

* simplify logics; sem types first

* fixes important packages

* add testcases

* tiny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment