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

Fix type instability of closures capturing types #35970

Closed
wants to merge 1 commit into from

Conversation

tkf
Copy link
Member

@tkf tkf commented May 21, 2020

(trying to) fix #23618

This patch "works" in the sense that closures behave as expected in the "bare" julia:

$ usr/bin/julia --sysimage usr/lib/julia/corecompiler.ji
WARNING: Base._start not defined, falling back to economy mode repl.

julia> f = x -> g -> g(x)
getfield(Main, Symbol("#1#3"))()

julia> typeof(f(Int))  # this takes ~10 seconds
getfield(Main, Symbol("#2#4")){Type{Int64}}

julia> f(Int)(f(1))
1

Note that the output of the second statement would be getfield(Main, Symbol("#2#4")){DataType} in current master. In this branch, it captures a Type{Int64} instead of a DataType.

However, make never finishes:

...
Sysimage built. Summary:
Total ─────── 352.542854 seconds
Base: ─────── 147.912140 seconds 41.9558%
Stdlibs: ──── 204.630686 seconds 58.0442%
    JULIA usr/lib/julia/sys-o.a
Generating precompile statements... 34405 generated in 6878.302163 seconds (overhead 5869.884857 seconds)
^C
signal (2): Interrupt

It ran for hours and consumed more than 12 GiB RAM so I just interrupted the compile.

@JeffBezanson @vtjnash Is there any way to make this work (or fix #23618 in any way)?

@KristofferC
Copy link
Sponsor Member

34405 generated in 6878.302163 seconds (overhead 5869.884857 seconds

Oh my...

@JeffBezanson
Copy link
Sponsor Member

Ah, well, there you go --- sometimes we do these awful things with types for a reason :) This looks like a tough problem.

@tkf
Copy link
Member Author

tkf commented May 21, 2020

Oh well, that's too bad. I thought it was such an "easy" fix. But it turned out that it completely destroyed the balance that current Julia compiler achieved...

Can we still make it opt-in somehow? Maybe with closures with @inline?

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 31, 2021

replaced by #40985

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

Successfully merging this pull request may close these issues.

type inference problem with captured type in closures
4 participants