HaxeFoundation / HaxeFoundation/haxe
[cpp] functions get wrapped in Dynamic
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
One of the intermediate issues that lead to the discovery of https://github.com/HaxeFoundation/hxcpp/issues/575 is the following:
Source:
```haxe
class C {
static var _f:cpp.FunctionVoid,cpp.abi.StdCall>;
static function f(n) {
_f.call(n + 1);
}
}
```
Generated C++
```cpp
void C_obj::f(int n){
HX_STACKFRAME(&_hx_pos_3831bbadf076dfac_5_f)
HXLINE( 5) ::Dynamic _hx_tmp = ::C_obj::_f;
HXDLIN( 5) _hx_tmp((n + (int)1));
}
```
The function is wrapped in hxcpp's `Dynamic` which I believe quite costly performance-wise because of all the wrapping and even array allocation for arguments, so this is something we might care about.
The cause is probably that the `cpp.Function` ends up being typed as a simple function in the end, as we can see in the AST. I'm not sure why though.
AST:
```
static function f[Function:n : Int -> Void]
[Arg:Int] [Local n(176):Int]
[Block:Void]
[Var _hx_tmp(194):Int -> Void]
[Cast:cpp.FunctionData Void, cpp.abi.StdCall>]
[Cast:cpp.FunctionData Void, cpp.abi.StdCall>]
[Field:cpp.Function Void, cpp.abi.StdCall>]
[TypeExpr C:Class]
[FStatic:cpp.Function Void, cpp.abi.StdCall>]
C
_f
[Call:Void]
[Local _hx_tmp(194):Int -> Void]
[Binop:Int]
[Local n(176):Int]
+
[Const:Int] 1
```
Contributor guide
Assessment
This issue has not been assessed yet.