HaxeFoundation / HaxeFoundation/haxe

Manually specify dependencies for DCE

Open
#8,112 12 comments 0 reactions 1 assignee Claimed by @RealyUniqueName View on GitHub
discussion
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

When I call an extern method which accepts a type such as `IMap`, DCE deletes methods on my type that are required by the type.

If an extern library’s method accepts a type, Haxe should assume that the extern method may access any of the members of that type. This should result in passing such types to extern methods causing all of their members to be marked keep. Otherwise, the compilation will succeed but will fail at runtime due to the extern referencing a member which was excluded by DCE.

For example, consider the following Haxe+JS code:

```haxe
import haxe.Constraints;

@:native('({x(v) {const i = v.keys(); while (i.hasNext()) {console.log(i.next());}}})')
extern class X {
static function x(v:IMap):Void;
}

class Test {
static function main() {
var map = [
'a'=>'b',
'c'=>'d',
];
// Only works if this following line is uncommented:
//map.keys();
X.x(map);
}
}
```

With the standard options on https://try.haxe.org/ , it fails. But if I force the member used by the extern library to exist by calling it from within my haxe code by uncommenting the line which calls `map.keys()`, it succeeds.

However, this shouldn’t be necessary. An extern library provides an interface/abstraction. If I have to manually reference members of types passed to the extern method as “used” so that they aren’t deleted by DCE, that means that I have to know the internals of the extern library, breaking encapsulation/abstraction. I shouldn’t have to look at the implementation of the extern library to successfully call it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.