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

Finalizer not called for type ref object of RootObj when using ARC/ORC + Forward declaration #19402

Closed
arkanoid87 opened this issue Jan 17, 2022 · 12 comments · Fixed by #20295
Closed

Comments

@arkanoid87
Copy link
Contributor

Example

compile with --gc:arc

type Foo = ref object of RootObj
proc delete(self: Foo) 
proc newFoo: Foo = new(result, delete)
proc delete(self: Foo) = echo("delete Foo")

if isMainModule:
  proc test() = discard newFoo()
  test()

Current Output

none

Expected Output

delete foo

Additional Information

Tested nim version 1.4.2 up to devel (15e3813)

It works with --gc:refc, it gives a different problem if type Foo = ref object (see #19401)

@filcuc
Copy link

filcuc commented Jan 17, 2022

This impact NimQml. See
filcuc/nimqml#43
filcuc/nimqml#42

@filcuc

This comment has been minimized.

@arkanoid87

This comment has been minimized.

@ringabout
Copy link
Member

ringabout commented Jan 27, 2022

Workaround: use codeReordering

{.experimental: "codeReordering".}

type Foo = ref object of RootObj
proc delete(self: Foo)  # it can be omitted
proc newFoo: Foo = new(result, delete)
proc delete(self: Foo) = echo("delete Foo")

if isMainModule:
  proc test() = discard newFoo()
  test()

@filcuc
Copy link

filcuc commented Jan 27, 2022

@xflywind it seems code reordering is not enough for making NimQml work..probably code reordering is experiemental for a reason :D

@ringabout
Copy link
Member

Yeah, I agree. It needs a real fix.

@filcuc
Copy link

filcuc commented Apr 13, 2022

@Araq and @xflywind any tip for debugging this one. Maybe i can try to look and debug this one in the compiler but a couple of hints could increase my success chances. I quickly skimmed the output in the c files but didn't noticed anything interesting (or maybe failed to understand them).

@Araq
Copy link
Member

Araq commented May 9, 2022

Look at lifdestructors.nim and maybe at injectdestructors.nim

@ringabout
Copy link
Member

ringabout commented Sep 2, 2022

Hello, @filcuc Here is the progress => #20295, but I cannot try it out with nimQML

@filcuc
Copy link

filcuc commented Sep 5, 2022

@ringabout i'll try your fix asap

@filcuc
Copy link

filcuc commented Sep 11, 2022

@ringabout i've tested it and it works! nice!!!

@filcuc
Copy link

filcuc commented Sep 11, 2022

@ringabout the only thing i've notice is that even if i'm using orc/arc deletion of object is not called immediately. However if i make a call to GC.forceFullCollect i see the finalizers being called...seems like something is "deferring" the deletion

Araq pushed a commit that referenced this issue Sep 27, 2022
…for ORC (#20295)

* fixes #19401; fixes #19402; rework Forward declaration and finalizer for ORC

* add more tests

* give it a name

* make more tests

* fixes tests

* hidden addr for cpp

* move code to a function
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…n and finalizer for ORC (nim-lang#20295)

* fixes nim-lang#19401; fixes nim-lang#19402; rework Forward declaration and finalizer for ORC

* add more tests

* give it a name

* make more tests

* fixes tests

* hidden addr for cpp

* move code to a function
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.

4 participants