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

Closures are not inlined when used through another inline closure #11626

Open
Speedphoenix opened this issue Apr 4, 2024 · 0 comments
Open

Comments

@Speedphoenix
Copy link

In this situation

class Extensions {
	inline static public function findMin<T>(a:Array<T>, f:T->Float) {
		var minVal = Math.POSITIVE_INFINITY;
		var minItem = null;
		for (item in a) {
			var v = f(item);
			if (v < minVal) {
				minVal = v;
				minItem = item;
			}
		}
		return {item: minItem, val: minVal};
	}

	inline static public function findMaxValue<T>(a:Array<T>, f:T->Float):Float {
		return -findMin(a, i -> -f(i)).val;
	}
}

class Test {
	static function main() {
		var arr = [5, 4, 65, 8];
		trace(Extensions.findMaxValue(arr, e -> e * 2));
	}
}

The e -> e * 2 closure is not inlined, even though it's only used in inline functions

On Try Haxe, the JS Source still shows

let arr = [5,4,65,8];
let f = function(e) {
	return e * 2;
};
let minVal = Infinity;
let _g = 0;
while(_g < arr.length) {
	let v = -f(arr[_g++]);
	if(v < minVal) {
		minVal = v;
	}
}
console.log("Test.hx:23:",-minVal);
@Speedphoenix Speedphoenix changed the title Clojures are not inlined when used through another inline clojure Closures are not inlined when used through another inline closure Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant