Skip to content

Add const declerations to type aliases #289

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

Merged
merged 1 commit into from
Aug 11, 2025

Conversation

kunzaatko
Copy link
Contributor

@kunzaatko kunzaatko commented Aug 11, 2025

  • feat(perf): Add const declarations to type aliases

@kunzaatko
Copy link
Contributor Author

It should in theory lead to type specialization and avoid runtime dispatch.
It should not change any functionality since the types are not changed elsewhere.

@kunzaatko kunzaatko changed the title Add const declerations to type aliases Add const declerations to type aliases [run benchmark] Aug 11, 2025
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@3cca7d0). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #289   +/-   ##
=========================================
  Coverage          ?   91.86%           
=========================================
  Files             ?       12           
  Lines             ?     1672           
  Branches          ?        0           
=========================================
  Hits              ?     1536           
  Misses            ?      136           
  Partials          ?        0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kunzaatko kunzaatko changed the title Add const declerations to type aliases [run benchmark] Add const declerations to type aliases Aug 11, 2025
@kunzaatko
Copy link
Contributor Author

Could you add the the run benchmark label so that we can see whether it truly makes a difference or the compiler is smart enough to infer the const?

@timholy
Copy link
Member

timholy commented Aug 11, 2025

This is only cosmetic, as

julia> using FixedPointNumbers, ColorTypes

julia> FixedColorant{T<:Normed} = Colorant{T}
ColorantNormed (alias for Colorant{T} where T<:Normed)

julia> isconst(Main, :FixedColorant)
true

The key point is that all of these have curly braces {T} in the left-hand side, so Julia knows they refer to types and marks them const.

That said, if you like the code better with the explicit declarations, we can merge this.

@kunzaatko
Copy link
Contributor Author

kunzaatko commented Aug 11, 2025

Thanks for the explanation!
I do like the code better since I see it often in other packages and consider it a standard that supports explicitness. As a newcomer, one knows that what is declared const is not modified within the rest of the package, however as you say, this would probably madden the compiler and it would not happen anyway.
However you should not feel pressured into merging this if you like the code the other way around.

@timholy timholy merged commit d3c2202 into JuliaImages:master Aug 11, 2025
9 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