-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add missing consts #238
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
My understanding was that parametric types are assumed to be |
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
2 ─ return 2.0
3 ─ return 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
2 ─ return 2.0
3 ─ Core.Const(:(return 1)) |
I meant the 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(
1 ─ nothing::Nothing
└── return 2.0
) => Float64
julia> @code_typed Test2.f(Test2.A(2.0))
CodeInfo(
1 ─ nothing::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. |
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 |
I think making it explicit is better |
No description provided.