elsassph / hxtsdgen

TypeScript declaration file generator for Haxe JavaScript output target
65 stars 12 forks source link

Some tests fail with a StackOverflow #5

Closed fullofcaffeine closed 5 years ago

fullofcaffeine commented 5 years ago

Just started looking at this lib as I'd like to integrate it with hxgenjs. Checked it out locally and trying to run tests after compiling with Haxe 4RC2:

make                                                                                                                                                   [2.5.0]
haxe test.hxml
node test
Running test case `basic-types.txt`...
Running test case `callback.txt`...
Running test case `ctors.txt`...
Running test case `doc.txt`...
Running test case `eithertype.txt`...
Running test case `empty.txt`...
Running test case `expose.txt`...
Running test case `function.txt`...
Stack overflow
Haxe compilation failed!
Running test case `generic.txt`...
Running test case `readonly.txt`...
Running test case `structs.txt`...
Stack overflow
Haxe compilation failed!
Result: 11. Failed: 2.
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

Not sure if this affects the actual usage of the lib, will report if so.

fullofcaffeine commented 5 years ago

Retried the test suite after pulling the latest updates, the function.txt test case still fails with a StackOverflow error:

Running test case `function.txt`...
Stack overflow
nadako commented 5 years ago

wow, I even added tests for this

nadako commented 5 years ago

The Stack overflow comes from OCaml code, could you try setting env var OCAMLRUNPARAM=b and see if that gives a stacktrace?

fullofcaffeine commented 5 years ago

@nadako An excerpt of the stacktrace follows. The Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17 line just repeats until it ends in the stack overflow ~3000 iterations afterwards (found out by counting the lines of the stacktrace):

Fatal error: exception Stack overflow
Raised by primitive operation at file "hashtbl.ml", line 163, characters 11-24
Called from file "hashtbl.ml", line 169, characters 18-34
Called from file "_build/src/macro/eval/evalHash.ml", line 26, characters 1-32
Called from file "_build/src/macro/eval/evalEncode.ml", line 125, characters 36-44
Called from file "list.ml", line 55, characters 20-23
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "list.ml", line 55, characters 32-39
Called from file "_build/src/macro/eval/evalEncode.ml", line 125, characters 12-50
Called from file "_build/src/macro/eval/evalEmitter.ml", line 441, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 79, characters 23-31
Called from file "_build/src/macro/eval/evalEmitter.ml", line 245, characters 7-18
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
Called from file "_build/src/macro/eval/evalEmitter.ml", line 744, characters 9-17
...

Using Haxe 4.0.0-rc.2+77068e1 on Linux Mint.

If you need any additional info, let me know.

nadako commented 5 years ago

Hmm, this looks to me like some self-referencing object is tried to get encoded from/to macro, or something...

In theory, OCaml errors should not surface to the user, but I'm not sure about cases like this. cc @Simn

fullofcaffeine commented 5 years ago

@nadako Reported this issue @ the Haxe repo as well seems it seems it's an issue in the eval target.

fullofcaffeine commented 5 years ago

@RealyUniqueName found the root of the issue, it's not really a Haxe bug, but happened due to a change in the way Null<> is represented by Haxe 4:

This is indeed self-recursive function.
This line: https://github.com/nadako/hxtsdgen/blob/8244c17/src/hxtsdgen/TypeRenderer.hx#L51
It recurses infinitely on Null<Int>.
In Haxe 3.4 Null was a typedef and avoided that branch of renderType function. Now Null is an abstract and goes to that branch.

Source: https://github.com/HaxeFoundation/haxe/issues/8303#issuecomment-494012128.

Look like we need to fix the issue in hxtsdgen.