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

inlining with @:generic #3663

Closed
mandel59 opened this issue Dec 10, 2014 · 2 comments
Closed

inlining with @:generic #3663

mandel59 opened this issue Dec 10, 2014 · 2 comments
Assignees

Comments

@mandel59
Copy link
Contributor

The code (the same as #3639)

class Test {
    public static function main() {
        each(0 ... 5, function(x) trace(x));
    }

    @:generic
    static function each<T,I:Iterator<T>>(itr : I, f : T -> Void) {
        for (x in itr) f(x);
    }
}

This code generates specialized method Test.each_Int_IntIterator, but method calls in it have not been inlined:

Test.each_Int_IntIterator = function(itr,f) {
        while( itr.hasNext() ) {
                var x = itr.next();
                f(x);
        }
};

Is it able to apply inlining to these method calls?

@Simn Simn added this to the 3.3 milestone Dec 10, 2014
@Simn
Copy link
Member

Simn commented Dec 10, 2014

The problem is that we do iterator inlining at the time of typing it. Generic expansion on the other hand works by "copying" the typed expressions, so there is no re-typing involved.

It might be possible to move the iterator inlining to a later optimization stage, but that is going to require some work.

@Simn Simn self-assigned this Jan 16, 2015
Simn added a commit that referenced this issue Jan 19, 2015
@Simn Simn modified the milestones: 3.3.0-rc1, 3.4 Feb 23, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Backlog Apr 17, 2018
@Simn
Copy link
Member

Simn commented Feb 19, 2020

This now generates good code:

Main.each_Int_IntIterator = function(itr,f) {
	var _g = itr;
	while(_g.min < _g.max) {
		var x = _g.min++;
		f(x);
	}
};

@Simn Simn closed this as completed Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants