Skip to content

Add missing consts #238

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
Jul 2, 2024
Merged

Conversation

DanielVandH
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.47%. Comparing base (f9fd686) to head (846a907).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #238      +/-   ##
==========================================
+ Coverage   90.00%   90.47%   +0.47%     
==========================================
  Files          11       11              
  Lines        1900     1901       +1     
==========================================
+ Hits         1710     1720      +10     
+ Misses        190      181       -9     

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

@jishnub
Copy link
Member

jishnub commented Jul 1, 2024

My understanding was that parametric types are assumed to be consts by default, and don't need to be annotated.

@DanielVandH
Copy link
Contributor Author

DanielVandH commented Jul 1, 2024

I think there there's a difference, e.g.

julia> module Test
       T = Union{Int, Real}
       f(x) = x isa T ? 2.0 : 1
       end
Main.Test

julia> module Test2
       const T = Union{Int, Real}
       f(x) = x isa T ? 2.0 : 1
       end
Main.Test2

julia> @code_warntype Test.f(2.0)
MethodInstance for Main.Test.f(::Float64)
  from f(x) @ Main.Test REPL[1]:3
Arguments
  #self#::Core.Const(Main.Test.f)
  x::Float64
Body::Union{Float64, Int64}
1%1 = (x isa Main.Test.T)::Bool
└──      goto #3 if not %1
2return 2.0
3return 1


julia> @code_warntype Test2.f(2.0)
MethodInstance for Main.Test2.f(::Float64)
  from f(x) @ Main.Test2 REPL[2]:3
Arguments
  #self#::Core.Const(Main.Test2.f)
  x::Float64
Body::Float64
1%1 = (x isa Main.Test2.T)::Core.Const(true)
└──      goto #3 if not %1
2return 2.0
3 ─      Core.Const(:(return 1))

@jishnub
Copy link
Member

jishnub commented Jul 2, 2024

I meant the const annotation is unnecessary in case the global variable is a parametric type alias (as in the change in this PR):

julia> module Test
       struct A{T} x::T end
       C{T} = A{T}
       f(x) = x isa C{Int} ? 1 : 2.0
       end
Main.Test

julia> module Test2
       struct A{T} x::T end
       const C{T} = A{T}
       f(x) = x isa C{Int} ? 1 : 2.0
       end
Main.Test2

julia> @code_typed Test.f(Test.A(2.0))
CodeInfo(
1nothing::Nothing
└──     return 2.0
) => Float64

julia> @code_typed Test2.f(Test2.A(2.0))
CodeInfo(
1nothing::Nothing
└──     return 2.0
) => Float64

This used to be necessary at one point, but not anymore on recent versions.

I am ok with the change either way, but I'm unsure if this helps with performance.

@DanielVandH
Copy link
Contributor Author

Interesting, I didn't know about that. It's up to you then, I don't mind if this gets closed. It does have the nice benefit that it at least makes the types consistent with the rest of the types which have a const.

@dlfivefifty
Copy link
Member

I think making it explicit is better

@dlfivefifty dlfivefifty merged commit 318d0d8 into JuliaLinearAlgebra:master Jul 2, 2024
18 checks passed
@DanielVandH DanielVandH deleted the consts branch July 24, 2024 01:52
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.

3 participants