HaxeFoundation / HaxeFoundation/haxe
Inlining issue because @:coreApi is annoying
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```haxe
class Main {
static public function main() {
var map = new StringMap();
map.set("foo", 12);
map.set("bar", 13);
for (value in map) { }
}
}
```
This generates:
```js
var value = new haxe_ds__$StringMap_StringMapIterator(map,map.arrayKeys());
while(value.hasNext()) value.next();
```
The reason for that is obvious in the dump file:
```
[Var value(4799):Iterator]
[Cast:Iterator]
[New:haxe.ds._StringMap.StringMapIterator]
haxe.ds._StringMap.StringMapIterator
[Local map(4563):haxe.ds.StringMap:haxe.ds.StringMap]
[Call:Array]
[Field:Void -> Array]
[Local map(4563):haxe.ds.StringMap:haxe.ds.StringMap]
[FInstance:Void -> Array]
haxe.ds.StringMap
arrayKeys
[While:Void]
[Parenthesis:Bool]
[Call:Bool]
[Field:Void -> Bool]
[Local value(4799):Iterator:Iterator]
[FAnon:Void -> Bool] hasNext
[Call:Int]
[Field:Void -> Int]
[Local value(4799):Iterator:Iterator]
[FAnon:Void -> Int] next
```
The underlying problem here is that `StringMap.iterator` is typed to be `Iterator`, which means the `next`/`hasNext` field accesses are made on the structure and are not inlined.
From the inliner's point of view, this is the correct behavior. We don't want to lose the return type of an inline function, so casting to `Iterator` is only consistent.
I think `@:coreApi` should allow covariance for return types so that `StringMap.iterator` can be typed to return `StringMapIterator` instead of `Iterator`.
Contributor guide
Assessment
This issue has not been assessed yet.