HaxeFoundation / HaxeFoundation/haxe

Analyzer Fusion order of operations

Open
#10,842 2 comments 1 reaction 1 assignee Claimed by @Simn View on GitHub
feature-analyzer
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I noticed that the analyzer's fusion module struggles with a particular pattern:

```haxe
@:analyzer(fusion_debug)
function main() {
var a = getValue();
var b = getValue();
var c = [a, b];
trace(c);
}

@:pure(false)
function getValue() {
return 1;
}
```

Here's what happens:

1. It attempts to fuse `a`, but fails due to the side effect on `var b = getValue()`.
2. It then attempts to fuses `b`, and succeeds.
3. Because something has changed, the algorithm re-enters and then successfully fuses `a`.

While this doesn't look particularly bad at first glance, it scales really poorly. The problem is that every additional variable causes an additional pass to be run over the entire expression. This is facilitated by the transformer generating lots of temporary variables which are then fused together.

I'm thinking that forward searching is _generally_ the right approach for this algorithm, but subsequent variables should first be "collected" and then processed in reverse order.

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.