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

Error: unhandled exception: sym is not accessible [FieldError] #10058

Closed
zevv opened this issue Dec 20, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@zevv
Copy link
Contributor

commented Dec 20, 2018

Nim 0.19.0, the snippet below causes a compiler SIGSEGV about 50% of the time when compiled.


import macros
import strformat


proc transpile(ipreg: string, ss: NimNode): NimNode =

  var caseStmt = nnkCaseStmt.newTree()
  caseStmt.add newIdentNode(ipreg)

  var n = 0
  for s in ss:
    let (op, a, b, c) = (s[0].strVal, intval s[1][0], intval s[1][1][0], intval s[1][1][1])

    proc gen(): string =
      &"r{a} + {b}"

    caseStmt.add nnkOfBranch.newTree(newLit(n), parseExpr &"r{c} = " & gen())
    inc n

  caseStmt.add nnkElse.newTree(
    nnkStmtList.newTree(
      nnkBreakStmt.newTree(newEmptyNode())
    )
  )
  
  result = nnkStmtList.newTree(
    nnkWhileStmt.newTree(
      newIdentNode("true"),
      nnkStmtList.newTree(
        caseStmt,
      )
    )
  )
  
macro elvenCode(ipreg: int, code: untyped): untyped =
  result = transpile("r" & $intVal(ipreg), code)
  echo toStrLit result
  
var r0, r1, r2, r3, r4, r5: int
  
elvenCode(5):
  addi 5 16 5

echo r0

I wasn't able to reduce much further without changing the compiler behaviour.

Interestingly enough, running under strace, moving the file to another directory or adding different compiler flags completely changes the behaviour (often for the good, resulting in a good compile)

Compiling with a debug compiler:

$./koch temp c  ~/sandbox/prjs/advent/bug.nim
[stuff happening]
Hint: algorithm [Processing]
nim.nim(108)             nim
nim.nim(72)              handleCmdLine
cmdlinehelper.nim(91)    loadConfigsAndRunMainCommand
main.nim(163)            mainCommand
main.nim(74)             commandCompileToC
modules.nim(126)         compileProject
modules.nim(71)          compileModule
passes.nim(211)          processModule
passes.nim(103)          processTopLevelStmt
sem.nim(600)             myProcess
sem.nim(568)             semStmtAndGenerateGenerics
semstmts.nim(1940)       semStmt
semexprs.nim(920)        semExprNoType
semexprs.nim(2526)       semExpr
semstmts.nim(1881)       semStmtList
semexprs.nim(2414)       semExpr
semexprs.nim(902)        semDirectOp
semexprs.nim(795)        afterCallActions
sem.nim(463)             semMacroExpr
vm.nim(1961)             evalMacroCall
vm.nim(1007)             rawExecute
vm.nim(396)              compile
vmgen.nim(2089)          genProc
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1886)          gen
vmgen.nim(314)           genBlock
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1886)          gen
vmgen.nim(314)           genBlock
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1886)          gen
vmgen.nim(314)           genBlock
vmgen.nim(1885)          gen
vmgen.nim(308)           genWhile
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1899)          gen
vmgen.nim(260)           gen
vmgen.nim(1915)          gen
vmgen.nim(538)           genVarSection
system.nim(2836)         sysFatal
Error: unhandled exception: sym is not accessible [FieldError]
FAILURE

@Araq Araq closed this in 23448a9 Dec 21, 2018

@zevv

This comment has been minimized.

Copy link
Contributor Author

commented Dec 21, 2018

solves the above, thanks for the quick fix

narimiran added a commit to narimiran/Nim that referenced this issue Dec 29, 2018

fixes nim-lang#10058 [backport]
(cherry picked from commit 23448a9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.