JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.92k stars 5.49k forks source link

@fastmath rewrites syntactically #26828

Open maleadt opened 6 years ago

maleadt commented 6 years ago
julia> sin(x) = println("Hello, $x")
sin (generic function with 1 method)

julia> sin("World")
Hello, World

julia> @fastmath sin("World")
ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::BigFloat) at mpfr.jl:637
  sin(::Complex{Float16}) at math.jl:951
  sin(::Float16) at math.jl:950
  ...
Stacktrace:
 [1] sin_fast(::String) at ./fastmath.jl:332

Maybe the docstring should mention how @fastmath rewrites syntactically, as there's less nonsensical scenario's where this might trip up user code (only defining sin on custom number types, adding specialized methods, etc).

simonbyrne commented 5 years ago

It really should be implemented using Cassette.jl, and moved to a package.