Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] over-optimization of not-really constant locals #8959

Closed
nadako opened this issue Nov 11, 2019 · 4 comments
Closed

[analyzer] over-optimization of not-really constant locals #8959

nadako opened this issue Nov 11, 2019 · 4 comments
Assignees

Comments

@nadako
Copy link
Member

@nadako nadako commented Nov 11, 2019

enum List<T> {
	Cons(element:T, next:List<T>);
	Nil;
}
class Main {
	static function main() {
		var list = Cons(1, Cons(2, Cons(3, Nil)));
		var acc = 0;

		while (true) {
			switch list {
				case Cons(element, next):
					list = next;
					acc = acc + element;
				case Nil:
					break;
			}
		}

		trace(acc);
	}
}

with -D analyzer-optimize will generate:

var list = List.Cons(1,List.Cons(2,List.Cons(3,List.Nil)));
var acc = 0;
while(true) {
	list = list.next;
	++acc;
}
@nadako

This comment has been minimized.

Copy link
Member Author

@nadako nadako commented Nov 11, 2019

Also if we change the while condition to something like a < 10, we'll get even more optimized version (now with a trace \o/):

var acc = 0;
while(acc < 10) ++acc;
console.log("src/Main.hx:43:",acc);
@nadako

This comment has been minimized.

Copy link
Member Author

@nadako nadako commented Nov 11, 2019

@Simn Simn self-assigned this Nov 11, 2019
@skial skial mentioned this issue Nov 12, 2019
1 of 1 task complete
@Simn Simn closed this in 7cd8ed9 Nov 12, 2019
@Simn

This comment has been minimized.

Copy link
Member

@Simn Simn commented Nov 12, 2019

I'm very surprised that this hasn't come up before. I suppose nobody is actually using -D analyzer-optimize. Normal people would conclude that bugs like this suggest that we shouldn't make it the default yet, but let's not be normal.

@nadako

This comment has been minimized.

Copy link
Member Author

@nadako nadako commented Nov 12, 2019

I mean, this is quite an artificial example with constant enums. But yeah I guess people who use enums extensively and people who use the optimizer are different sets of users :)

Simn added a commit that referenced this issue Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.