haxe-instrument icon indicating copy to clipboard operation
haxe-instrument copied to clipboard

replaceReturn causes issues in HaxeFlixel classes for some structure returns

Open 47rooks opened this issue 1 year ago • 1 comments

Following on from https://github.com/AlexHaxe/haxe-instrument/issues/18.

Using Haxe 4.3.3 Instrument git at https://github.com/AlexHaxe/haxe-instrument/commit/5ce5871be21549bb474f806bf169d01bf1914b04 flixel 5.6.2

In a number of classes in HaxeFlixel the return cast result statement causes compilation issues caused by type mismatches between the anonymous structure returned and the defined typedef it is supposed to match. Cases can be such as Null<Int> vs Int and so on.

lime build hl
Instrumenting..................................................................................................................  
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/tools/Eraser.hx:64: characters 12-16 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> has no field kill
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/tools/Eraser.hx:66: characters 23-29 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> should be flixel.FlxBasic
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/tools/Eraser.hx:66: characters 23-29 : ... For function argument 'item'
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/Interaction.hx:402: characters 25-26 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> has no field x
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/Interaction.hx:402: characters 58-59 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> has no field y
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/Interaction.hx:402: characters 91-96 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> has no field width
MY_PATH/haxe-perf-examples/.haxelib/flixel/5,6,2/flixel/system/debug/interaction/Interaction.hx:402: characters 111-117 : Null<{ scrollFactor : Null<Unknown<0>>, isOnScreen : () -> Bool }> has no field height

Removing the cast, as below, works for those cases but there are then other cases which must have casts added. I have gotten this working by manually adding casts in the specific classes to test that was indeed the problem.

	static function replaceReturn(expr:Expr):Expr {
...
...
		return relocateExpr(macro {
			var result = ${instrumentExpr(expr)};
			instrument.profiler.Profiler.exitFunction(__profiler__id__);
			// return cast result;
			return result;
		}, expr.pos);

None of these are particularly important classes to profile so I'll skip them for now.

47rooks avatar Apr 14 '24 03:04 47rooks

I've reverted to the base install of the haxelib for flixel 5.6.2 and it turns out that even with "flixel.system" in the exclude list I cannot get around these errors. @:ignoreInstrument doesn't work either. The only thing that does appears to be removing the cast which results in the need to patch up or ignore other classes.

That requires adding "flixel.graphics.frames". This is because FlxFramesCollection.hx needs to be excluded, though apart from that "flixel.graphics.frames.bmfont" would be enough. This is a little broad as it's not inconceivable that you would want to profile animation frame handling. So if that is the case you need to modify the FlxFramesCollection.hx and add the @:ignoreInstrument to the class. Then it will build.

47rooks avatar Apr 14 '24 04:04 47rooks

should be fixed in 1.2.0

AlexHaxe avatar Jun 02 '24 19:06 AlexHaxe