Closed
Description
openedon Mar 14, 2017
Cross-posting from discourse: https://discourse.julialang.org/t/incorrect-results-from-which-and-code-warntype-for-literal-powers/2630
I'm trying to use the new literal exponent behavior introduced in #20530 and #20889. I think I'm correctly overloading literal_pow
, but various macros like @which
, @code_warntype
and others all seem to be showing me the wrong behavior.
julia> versioninfo()
Julia Version 0.6.0-pre.alpha.136
Commit 6eeabd8 (2017-03-13 00:18 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin13.4.0)
CPU: Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, sandybridge)
julia> immutable MyType
x::Int
end
julia> import Base: literal_pow
julia> literal_pow(^, m::MyType, ::Type{Val{p}}) where p = m.x + p
literal_pow (generic function with 6 methods)
julia> m = MyType(1)
MyType(1)
julia> m^2
3
That's all good so far. But none of the introspection macros seem to work for m^2
:
julia> @which m^2
^(x, p::Integer) in Base at intfuncs.jl:196
julia> @code_warntype m^2
Variables:
#self#::Base.#^
x::MyType
p::Int64
Body:
begin
return $(Expr(:invoke, MethodInstance for power_by_squaring(::MyType, ::Int64), :(Base.power_by_squaring), :(x), :(p)))
end::Any
julia> @code_lowered m^2
CodeInfo(:(begin
nothing
return (Base.power_by_squaring)(x, p)
end))
julia> using Base.Test
julia> @inferred m^2
ERROR: MethodError: no method matching *(::MyType, ::MyType)
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
Stacktrace:
[1] power_by_squaring(::MyType, ::Int64) at ./intfuncs.jl:166
[2] ^(::MyType, ::Int64) at ./intfuncs.jl:196
are the special lowering rules not being applied inside these macros?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment