Revision 4faf28a83e9fd6c02fd03abc23daf9ea4dcf3a43 authored by Keno Fischer on 15 September 2022, 02:57:54 UTC, committed by Keno Fischer on 15 September 2022, 03:14:28 UTC
Currently we represent an unknown :static_parameter, as `Any`. However, we actually have a fair bit of additional information about it. In particular, a value that came from a static parameter must have been a `valid_tparam` and thus if it's used in `apply_type` again, we're guaranteed that such a use will be nothrow. This adds a special lattice element to encode this set of values. The primary benefit is to be able to prove the nothrow fact about many more apply_type calls and thus cut down the size of the IR. That said, at the moment, we cannot prove nothrow for unknown `:static_parameter` either, but that's a separate bit of work (and we need to do both to really be able to eliminate common patterns).
1 parent f7dea04
osutils.jl
# This file is a part of Julia. License is MIT: https://julialang.org/license
"""
@static
Partially evaluate an expression at parse time.
For example, `@static Sys.iswindows() ? foo : bar` will evaluate `Sys.iswindows()` and insert
either `foo` or `bar` into the expression.
This is useful in cases where a construct would be invalid on other platforms,
such as a `ccall` to a non-existent function.
`@static if Sys.isapple() foo end` and `@static foo <&&,||> bar` are also valid syntax.
"""
macro static(ex)
if isa(ex, Expr)
@label loop
hd = ex.head
if hd ∈ (:if, :elseif, :&&, :||)
cond = Core.eval(__module__, ex.args[1])
if xor(cond, hd === :||)
return esc(ex.args[2])
elseif length(ex.args) == 3
br = ex.args[3]
if br isa Expr && br.head === :elseif
ex = br
@goto loop
else
return esc(ex.args[3])
end
elseif hd ∈ (:if, :elseif)
return nothing
else
return cond
end
end
end
throw(ArgumentError("invalid @static macro"))
end
Computing file changes ...