Closed ncannasse closed 4 years ago
I think we should just throw out @:multiType
and think of something else. It has major AST-issues with inlining anyway because the abstract disappears and the compiler doesn't know which specialization to select anymore.
@Simn any suggestion for a replacement? If it's only used by Map, we could hardcode the type selection in the compiler for now.
It's used by libraries: OpenFL's Dictionary, Flixel's FlxSignal, hxsignal, etc...
Maybe we could lose IMap itself by making Map into a @:coreType
and take it from there. I'll have to investigate that...
Just so you know, this also generates the following on C#:
public virtual global::Main foo(int key) {
return ((global::Main) ((((global::haxe.ds.IntMap<object>) (global::haxe.ds.IntMap<object>.__hx_cast<object>(((global::haxe.ds.IntMap) (((global::haxe.IMap<int, object>) (this.a) )) ))) ).@get(key)).@value) );
}
while direct IntMap usage generates much nicer code:
public virtual global::Main foo(int key) {
return ((global::Main) ((this.a.@get(key)).@value) );
}
HL compilation does take care of removing these unnecessary casts, but still the compiler could output nicer code. Keeping open so it's linked to Map redesign (one day)
This is a duplicate of another issue that I'm too lazy to scroll back to right now.
Trying to pinpoint why HL allocate that much memory, I found the following:
Produces the following AST:
What it does is first cast the
Map<Int,Main>
toIMap
which is an interface, then cast it back (unsafely) toIntMap
. If we could avoid these cast forth and back to interfaces, I'm sure all static type systems will be happy since it has some cost because the object value and interface value are two different things.