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

Improve type inference #308

Merged
merged 1 commit into from
Oct 12, 2024
Merged

Conversation

topolarity
Copy link
Contributor

This makes the following example compile with --trim:

using FFTW

Base.@ccallable function main() :: Cint
    v = fft([0; 1; 2; 1])
    for elem in v
        println(Core.stdout, elem)
    end
    return 0
end
$ ./fftw
4.0 + 0.0im
-2.0 + 0.0im
0.0 + 0.0im
-2.0 + 0.0im

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.99%. Comparing base (f888022) to head (55b8143).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/fft.jl 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #308      +/-   ##
==========================================
- Coverage   73.45%   70.99%   -2.46%     
==========================================
  Files           5        5              
  Lines         535      531       -4     
==========================================
- Hits          393      377      -16     
- Misses        142      154      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@topolarity topolarity changed the title Improve inferrability + sysimage build compatibility Improve inferrability Oct 9, 2024
Co-authored-by: Gabriel Baraldi <[email protected]>
@topolarity topolarity changed the title Improve inferrability Improve inference Oct 9, 2024
@topolarity topolarity changed the title Improve inference Improve type inference Oct 9, 2024
@@ -335,7 +335,12 @@ function destroy_deferred()
# we'll do nothing (the other function will eventually run destroy_deferred).
if !isempty(deferred_destroy_plans) && trylock(fftwlock)
try
foreach(unsafe_destroy_plan, deferred_destroy_plans)
@static if Base.VERSION >= v"1.9"
@inline foreach(unsafe_destroy_plan, deferred_destroy_plans)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is inlining needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core issue is that foreach in Base does not specialize on its function argument: https://github.com/JuliaLang/julia/blob/a007e807623f0bbb820315b8ce3340bd3d41262b/base/abstractarray.jl#L3213-L3214

This is missing something like foreach(f::F, ...) where F which would cause this to specialize better - otherwise as-is it contains a dynamic dispatch. Arguably that should be fixed upstream, but this improves things for released versions of Julia too

src/fft.jl Show resolved Hide resolved
@stevengj stevengj merged commit b6f41d8 into JuliaMath:master Oct 12, 2024
46 of 51 checks passed
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.

2 participants