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

Hang when dealing with some pieces of code #738

Open
linkpy opened this issue May 2, 2020 · 4 comments
Open

Hang when dealing with some pieces of code #738

linkpy opened this issue May 2, 2020 · 4 comments

Comments

@linkpy
Copy link
Contributor

linkpy commented May 2, 2020

(register-type MyType)

(defmodule MyType
  (register init (Fn [] MyType))
  (register delete (Fn [&MyType] ()))
  (register copy (Fn [&MyType] MyType))
)

(deftype MyWrapper [inner MyType])

(defmodule MyWrapper
  (defn delete [w]
    (MyType.delete (MyWrapper.inner &w))))

(defn main []
  (let [v (MyWrapper.init (MyType.init))]
    (IO.println "in let")))

This code, when doing (load "test.carp") hangs and consume all of my memory (16Gb). But, if i do (MyType.delete (MyWrapper.inner w)) (removing the &) then it loads correctly.

I have no idea how i can debug this (i have no knowledge of Haskell) so don't hesitate to ask for more info.

@hellerve
Copy link
Member

hellerve commented May 2, 2020

Hey! Thanks for reporting this!

I’m assuming that Carp chokes on the redefinition of an autogenerated delete function (which, in my opinion, should be possible). Maybe @eriksvedang can provide more insight into this!

@linkpy
Copy link
Contributor Author

linkpy commented May 2, 2020

I'm renaming that issue because I encountered it with a piece of code not using references at all :

(deftype MyType [v Int])

(defmodule MyType
  (sig delete (Fn [MyType] ()))
  (defn delete [o]
    (do
      (IO.println "in delete")
      ())))

(defn main []
  (let [v (MyType.init 0)]
    (IO.println "in let")))

Doing (load "test.lisp") hangs. I tried to input each line into the REPL, and it hangs for the main function declaration.

When I try reordering the statements : deftype, then defn main then defmodule, the REPL doesn't hang anymore, but the compile fails :

out/main.c:8813:9: warning: implicit declaration of function 'MyType_delete' is invalid in C99 [-Wimplicit-function-declaration]
        MyType_delete(v);
        ^
1 warning generated.
/usr/bin/ld: /tmp/main-f81b52.o: in function `main':
/home/linkie-pi/Documents/devel/carp/gdnative-carp/out/main.c:8813: undefined reference to `MyType_delete'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
carp: callCommand: clang -fPIC -lm -g out/main.c -o "out/Untitled"  -I/home/linkie-pi/Documents/Carp/core/   (exit 1): failed

I obtain the same error when using a file with the reordered code. When i tried with defn main as the first definition in the file, the parse fails due to MyType.init not declared and I guess it's to be expected.

Some more info that could be useful (based on the example given in that comment) :

  • When the main doesn't use MyType, the hang does not happen (for example, (IO.println "test") as the main's body.
  • I wanted to check if let wasn't causing the issue, so i tried (MyType.delete (MyType.init 0)) as the main's body code. Carp hangs with that code.
  • Renaming delete to my-delete doesn't make main to hang.

@linkpy linkpy changed the title Hang when dealing with references Hang when dealing with some pieces of code May 2, 2020
@scolsen
Copy link
Contributor

scolsen commented May 4, 2020

I've encountered this before. I could be wrong, but I think the same hang happens for sumtypes + modules too.

@eriksvedang eriksvedang added the bug label May 4, 2020
@eriksvedang eriksvedang modified the milestone: Version 0.4.0 May 5, 2020
@scolsen
Copy link
Contributor

scolsen commented May 21, 2020

I suspect this might have to do with some of the eval or constraint generation loops or solving loops since it seems to have some kind of relationship with struct/sumtypes.

Or it has to do with lookups happening somewhere that enter in a loop somehow 🤔

@eriksvedang eriksvedang added this to the 0.7.0 – No major bugs milestone Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants