-
-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cs] Wrong generic type definition #5434
Comments
The second one is a real issue. As for the |
? Would love to see those tests. While what you say is true for some cases, it's not for all of them. Think for example of a generic that in the end is creating an array for ints, with the code used for c# you'll end creating an array of objects, in that case the memory layout is not the same and haxe code will be much slower for some uses. Also, what if you use constraints for the generic type? I didn't check this use case, but do you rely on reflection to access known methods and properties? in that case it's clear it will also be slower. There are other cases too, but I'd say that in a lot of cases the produced code will be slower (admittedly in a lot of them the difference will be minimal), maybe those tests were not taking into account GC garbage, starting up overload and other things that can take an effect into the final results? EDIT: Tested it, I see that constraints are not converted over to C# code, and that in fact reflection is used unless we define the exact type to be used in the interface or class declaration. |
Well, for basic types (int,double,bool) it generates proper type, it's just all others that are pointers anyway, but yeah, we should look into it at some point in future. |
I see, I thought the object replacement was used everywhere, my bad. There may be some cases where it can still be a problem, like arrays of primitive types, but I think this one would be very uncommon. At any rate, that bug when using Dynamic is way more important, it's for example making hexMachina not usable when targetting C#, a real shame as it's already working for a few targets. |
Is there any way to avoid this issue? Haxe falls back to reflection when iterating through Map values like this. |
I'm not sure why losing generic parameter makes program faster either. That will cause lots of casts, and makes code size bigger. Compilers cannot generate optimized code from such big code. |
Even when reflection is not used it could be bad for performance because of lots of casts. Also, losing type information is bad if you want to make a library for existing .NET application, or if you want to use that library from Haxe with |
That's a good point... I didn't try it, but what if you have a library that requires to get for example some |
You mean we should support casting to Could that be the other way around? Should a List be able to contain any kind of object? Then it's not possible to support variance in this way. |
|
Not so nice, but it seems impossible to |
But it's not possible to cast I've tried writing a function that returns |
I'm not sure to follow you :/. Having some fictitious 3rdparty.dll that you reference in your HxCS project, and 3rdparty.dll has a class When you do
Which AFAIK, should fail. |
Just tested it. Indeed it fails. Note that my sample is not 100% valid tho, because I was using IComparable, and from .NET 4 onward it's using variance (it's defined as |
I've found the place where this conversion is done. Line 955 in 9ab880c
Changing @Neverbirth your test class is just a haxe-generated class that implements builtin .NET interface, so haxe still converts type parameters to Should we be able to convert |
Could this be fixed without converting all type parameters to |
Oh, I didn't consider how EDIT: I guess typedefs can also become a bit tricky... didn't check the generated code for a case like this. Anyway, all this topic is not a showstopper like the second bug I mentioned in my original report. |
* Add failing tests * [cs] Consider String as basic type too * HxObject.getParams() returns an Array<{}> * Add tests for #5434
Seems to be fixed by #8387 (or is there something else to do here?) |
Having for example the following piece of code:
Generates the following C# code for ISubTest:
As you can see it completely loses the types we want to use. I tried different types, and I was always getting object for the generic type. Furthermore, this one:
Doesn't compile at all, because it generates some invalid implementation of the interface in
TestClass
:I would say this is a rather important issue.
The text was updated successfully, but these errors were encountered: