haxe icon indicating copy to clipboard operation
haxe copied to clipboard

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

Open onehundredfeet opened this issue 4 years ago • 5 comments

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 avatar Oct 23 '21 21:10 onehundredfeet

-DCE off or std is fine

-DCE full causes the error to appear.

I will try to make a minimal case asap.

onehundredfeet avatar Oct 23 '21 22:10 onehundredfeet

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.

Simn avatar Oct 24 '21 06:10 Simn

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.

onehundredfeet avatar Apr 05 '22 15:04 onehundredfeet

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

Simn avatar Apr 05 '22 15:04 Simn

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.

onehundredfeet avatar Apr 05 '22 16:04 onehundredfeet