HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.17k stars 655 forks source link

Compilation Error - Invalid_argument("index out of bounds") | DCE full only #10450

Open onehundredfeet opened 3 years ago

onehundredfeet commented 3 years ago

When I compile my project it runs through most of it and then outputs this:

Invalid_argument("index out of bounds")

UPDATE: I believe it's something due to dead code elimination. I believe the DCE is eliminating the type somehow and then the macro is bringing it back in. On DCE std or off it runs fine.

I get this when I am targeting HL/C. When I target hashlink, I don't get a compile error, but I get a JIT error where it can't find a function.

After cutting out portions of the project I can get the error to appear/re-appear with the addition and removal of a single function with no body. I have no idea why its happening.

I'm guessing that something is stopping the compiler from emitting the correct number of functions in some way but I don't know how the compiler works internally.

Some more error information would be helpful.

Below is the macro output that when generated makes the error code appear:

if (!activated) {
    activated = true;
    __clientAdd_listener__ = function(__entity__:hcqe.Entity, a:heaps.yojimbo.RemoteClient):Void clientAdd(a);
    viewof_ffffffff_heapsyojimboremoteclient.activate();
    viewof_ffffffff_heapsyojimboremoteclient.onAdded.add(__clientAdd_listener__);
    viewof_ffffffff_heapsyojimboremoteclient.iter(__clientAdd_listener__);
    onactivate();
}

Below is the same output with the function generation disabled. The error code no longer appears.

if (!activated) {
    activated = true;
    viewof_ffffffff_heapsyojimboremoteclient.activate();
    viewof_ffffffff_heapsyojimboremoteclient.onAdded.add(__clientAdd_listener__);
    viewof_ffffffff_heapsyojimboremoteclient.iter(__clientAdd_listener__);
    onactivate();
}

The above was printed with the Haxe macro printer.

Simply assigning the anonymous function in the macro makes the error code appear. __clientAdd_listener = function(entity__:hcqe.Entity, a:heaps.yojimbo.RemoteClient):Void clientAdd(a);

If I change the type the error code also goes away.

Here is the Haxe -v output tail:

....
Typing haxe.ds._Vector.Vector_Impl_.copy
Typing haxe.ds._Vector.Vector_Impl_.join
Typing haxe.ds._Vector.Vector_Impl_.map
Typing haxe.ds._Vector.Vector_Impl_.sort
Generating hl: bin/server.c
Invalid_argument("index out of bounds")
onehundredfeet commented 3 years ago

-DCE off or std is fine

-DCE full causes the error to appear.

I will try to make a minimal case asap.

Simn commented 3 years ago

That's interesting. I'm not sure how DCE can affect a generator like that. You can try setting the environment variable OCAMLRUNPARAM=b and see if that gives you a full stack trace, which should at least point us to the operation that is failing.

onehundredfeet commented 2 years ago

This is caused by pointing to the wrong STD when building. I wish there was a warning letting me know.

When I use

export HAXE_STD_PATH=source_dir/std

everything works.

User error, but a warning would be helpful.

Simn commented 2 years ago

This comes up every once in a while. Maybe we could add a #if (haxe_ver < current) check to Std.hx.

onehundredfeet commented 2 years ago

I spoke too soon. I had the above error when compiling Haxe itself. Pointing to the right STD fixed that. My original error I should re-verify.