HaxeFoundation / HaxeFoundation/haxe

Possibility to get DCE's good ol' maybeUsed in Haxe 5

Open
#12,461 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Spacebar heating request:

We're doing some field minification via `@:native` and since that doesn't work for structures, we need to make sure that classes that are upcast to structures don't have those fields minified. In Haxe 4 this was possible thanks to `@:maybeUsed` left behind when a class was unified with a structure, but now this seems to have become a flag on the class field itself: https://github.com/HaxeFoundation/haxe/blob/6cd1f655007ccdf54123ad6a87d5a98ad84e9aa7/src/core/tType.ml#L530

I guess one option would be to [encode it into `ClassField`](https://github.com/HaxeFoundation/haxe/blob/6cd1f655007ccdf54123ad6a87d5a98ad84e9aa7/src/macro/macroApi.ml#L1105). This would make the object a bit heavier, but compared to the meta data based solution, I think it shouldn't be *that* bad.

I realize that misusing DCE like this is a questionable approach to start with, but it does give us a ~25% size decrease. We can get relatively close to that by simply skipping any fields found in typedefs, but the problem then is that we fail to catch cases like these (unless we scan the whole typed AST for structures):

```haxe
function callFoo(o) {
o.foo();
}
call(new HasFoo());
```

So yeah, would be great to have some API to get the information, since it's already there, just out of reach.

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.