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

nim e crashes when user-defined hooks are used #1401

Open
alaviss opened this issue Aug 7, 2024 · 1 comment
Open

nim e crashes when user-defined hooks are used #1401

alaviss opened this issue Aug 7, 2024 · 1 comment
Labels
bug Something isn't working compiler General compiler tag

Comments

@alaviss
Copy link
Contributor

alaviss commented Aug 7, 2024

Example

type
  C = object
    heaped: ref array[1, uint8]

proc `=copy`(dst: var C, src: C) =
  if dst.heaped != src.heaped:
    new(dst.heaped)
    dst.heaped[] = src.heaped[]

proc newC(): C =
  C(heaped: new(array[1, uint8]))

var c = newC()

Actual Output

$ ./koch.py temp e test.nim

bin/nim_temp  e test.nim
compiler/nim.nim(154) nim
compiler/nim.nim(89) handleCmdLine
compiler/front/main.nim(695) mainCommand
compiler/front/scripting.nim(231) runNimScript
compiler/sem/passes.nim(275) processModule
compiler/sem/passes.nim(102) processTopLevelStmt
compiler/vm/compilerbridge.nim(724) myProcess
compiler/vm/compilerbridge.nim(413) evalStmt
compiler/vm/compilerbridge.nim(353) execute
compiler/vm/compilerbridge.nim(329) execute
compiler/vm/vmjit.nim(314) compile
compiler/vm/vmjit.nim(269) genProc
compiler/backend/backends.nim(403) generateIR
compiler/backend/cgirgen.nim(812) generateIR
compiler/backend/cgirgen.nim(796) tb
compiler/backend/cgirgen.nim(776) scopeToIr
compiler/backend/cgirgen.nim(643) stmtToIr
compiler/utils/idioms.nim(36) unreachableImpl
lib/system/assertions.nim(28) raiseAssert
lib/system/fatal.nim(50) sysFatal
Error: unhandled exception: cgirgen.nim(643, 16) unreachable: a 'destroy' that wasn't lowered [AssertionDefect]

Additional Information

  • Runs fine with JS and native backends
@alaviss alaviss added bug Something isn't working compiler/backend Related to backend system of the compiler labels Aug 7, 2024
@zerbina zerbina changed the title VM backend crash when =copy is defined for an object with ref field nim e crashes when user-defined hooks are used Aug 7, 2024
@zerbina
Copy link
Collaborator

zerbina commented Aug 7, 2024

I've tried building and running the provided example with the VM backend, and it works as it should.

Going by the actual output you showed, you using NimScript rather than the VM backend, which are two different things. In NimScript, hooks don't work at all, unrelated to ref fields. Here's a reduced reproducer:

type
  C = object

proc `=destroy`(dst: var C) =
  discard

block:
  var c = newC()

running the above results in the same crash.

I've changed the title of the issue, in order to make it clearer what's going on.

@zerbina zerbina added compiler General compiler tag and removed compiler/backend Related to backend system of the compiler labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler General compiler tag
Projects
None yet
Development

No branches or pull requests

2 participants