reflaxe.CPP icon indicating copy to clipboard operation
reflaxe.CPP copied to clipboard

Haxe inline functions still generate as C++ functions

Open fourst4r opened this issue 2 years ago • 3 comments

For example 😅

inline function foo() {}

function main() {
    foo();
}

Will still generate a

void _Main::Main_Fields_::foo() {

}

I only noticed this because I am generating a wrapper for which I don't know the header for, but it is guaranteed that the header is included at the call site. So, I was trying to use inline to get around that.

fourst4r avatar Jun 22 '23 08:06 fourst4r

Sorry for the delay, I think this might be a thing with Haxe. While I could fix, that would make it less consistent with the Haxe static targets. For example, I tested this code on Haxe/C# and it doesn't inline. Let me check out how the other targets handle inline and I'll get back to this when I can, but there is a fix you can use right now!

The good news is you can force inlining by adding "extern". (inline extern function foo() { ... }), and this should work!

class Test {
  static function main() {
    bla();
  }
  
  inline static function bla() {
		trace("bla");
  }
}
public static void main() {
		unchecked {
			global::haxe.Log.trace.__hx_invoke2_o(default(double), ((global::haxe.lang.Function) (new global::haxe.lang.Closure(typeof(global::Test), "bla", 4897623)) ), default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"bla", "Test", "src/Test.hx"}, new int[]{1981972957}, new double[]{((double) (7) )}));
		}
	}
	
	
	public static void bla() {
		unchecked {
			global::haxe.Log.trace.__hx_invoke2_o(default(double), ((global::haxe.lang.Function) (new global::haxe.lang.Closure(typeof(global::Test), "bla", 4897623)) ), default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"bla", "Test", "src/Test.hx"}, new int[]{1981972957}, new double[]{((double) (7) )}));
		}
	}

SomeRanDev avatar Jun 27 '23 08:06 SomeRanDev

Sorry for the delay

Not at all, I appreciate all the time and effort you've already put into this project.

For example, I tested this code on Haxe/C# and it doesn't inline.

Curious.

The good news is you can force inlining by adding "extern".

Thank you! That's exactly what I needed. 😁

fourst4r avatar Jun 27 '23 19:06 fourst4r

Reflecting back on this now, it may have something to do with reflection.

fourst4r avatar Aug 15 '23 08:08 fourst4r