-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve exception type inference for core math functions
- Loading branch information
Showing
5 changed files
with
47 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,9 +130,9 @@ to tell the compiler that indexing operations within the applied expression are | |
inbounds and do not need to taint `:consistent` and `:nothrow`. | ||
""" | ||
macro _safeindex(ex) | ||
return esc(_safeindex(__module__, ex)) | ||
return esc(_safeindex(@__MODULE__, ex)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
aviatesk
Author
Member
|
||
end | ||
function _safeindex(__module__, ex) | ||
function _safeindex(mod, ex) | ||
isa(ex, Expr) || return ex | ||
if ex.head === :(=) | ||
lhs = ex.args[1] | ||
|
@@ -141,16 +141,16 @@ function _safeindex(__module__, ex) | |
xs = lhs.args[1] | ||
args = Vector{Any}(undef, length(lhs.args)-1) | ||
for i = 2:length(lhs.args) | ||
args[i-1] = _safeindex(__module__, lhs.args[i]) | ||
args[i-1] = _safeindex(mod, lhs.args[i]) | ||
end | ||
return Expr(:call, GlobalRef(__module__, :__safe_setindex!), xs, _safeindex(__module__, rhs), args...) | ||
return Expr(:call, GlobalRef(mod, :__safe_setindex!), xs, _safeindex(mod, rhs), args...) | ||
end | ||
elseif ex.head === :ref # xs[i] | ||
return Expr(:call, GlobalRef(__module__, :__safe_getindex), ex.args...) | ||
return Expr(:call, GlobalRef(mod, :__safe_getindex), ex.args...) | ||
end | ||
args = Vector{Any}(undef, length(ex.args)) | ||
for i = 1:length(ex.args) | ||
args[i] = _safeindex(__module__, ex.args[i]) | ||
args[i] = _safeindex(mod, ex.args[i]) | ||
end | ||
return Expr(ex.head, args...) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,14 +155,11 @@ logbU(::Type{Float64},::Val{10}) = 0.4342944819032518 | |
logbL(::Type{Float64},::Val{10}) = 1.098319650216765e-17 | ||
|
||
# Procedure 1 | ||
# XXX we want to mark :noub here so that this function can be concrete-folded, | ||
# because the effect analysis currently can't prove it in the presence of `@inbounds` or | ||
# `:boundscheck`, but still the access to `t_log_Float64` is really safe here | ||
Base.@assume_effects :consistent :noub @inline function log_proc1(y::Float64,mf::Float64,F::Float64,f::Float64,base=Val(:ℯ)) | ||
@inline function log_proc1(y::Float64,mf::Float64,F::Float64,f::Float64,base=Val(:ℯ)) | ||
jp = unsafe_trunc(Int,128.0*F)-127 | ||
|
||
## Steps 1 and 2 | ||
@inbounds hi,lo = t_log_Float64[jp] | ||
Base.@_safeindex hi,lo = t_log_Float64[jp] | ||
This comment has been minimized.
Sorry, something went wrong.
Keno
Member
|
||
l_hi = mf* 0.6931471805601177 + hi | ||
l_lo = mf*-1.7239444525614835e-13 + lo | ||
|
||
|
@@ -216,14 +213,11 @@ end | |
end | ||
|
||
# Procedure 1 | ||
# XXX we want to mark :noub here so that this function can be concrete-folded, | ||
# because the effect analysis currently can't prove it in the presence of `@inbounds` or | ||
# `:boundscheck`, but still the access to `t_log_Float32` is really safe here | ||
Base.@assume_effects :consistent :noub @inline function log_proc1(y::Float32,mf::Float32,F::Float32,f::Float32,base=Val(:ℯ)) | ||
@inline function log_proc1(y::Float32,mf::Float32,F::Float32,f::Float32,base=Val(:ℯ)) | ||
jp = unsafe_trunc(Int,128.0f0*F)-127 | ||
|
||
## Steps 1 and 2 | ||
@inbounds hi = t_log_Float32[jp] | ||
Base.@_safeindex hi = t_log_Float32[jp] | ||
l = mf*0.6931471805599453 + hi | ||
|
||
## Step 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Might be clearer to write
Base
here explicitly?