Skip to content

Commit

Permalink
Deprecate expand(module, ex) to Meta.lower(module, ex).
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 22, 2017
1 parent 175f7a1 commit a885ba7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ Deprecated or removed
which now require a module argument.
And it caused the bugfix of other default arguments to use the Main module (including `whos`, `which`).

* `expand(ex)` and `expand(module, ex)` have been deprecated in favor of
`Meta.lower(ex)` ([#24278]).

* The `Operators` module is deprecated. Instead, import required operators explicitly
from `Base`, e.g. `import Base: +, -, *, /` ([#22251]).

Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function eval_user_input(@nospecialize(ast), show_value)
display_error(lasterr,bt)
errcount, lasterr = 0, ()
else
ast = expand(Main, ast)
ast = Meta.lower(Main, ast)
value = eval(Main, ast)
eval(Main, Expr(:body, Expr(:(=), :ans, QuoteNode(value)), Expr(:return, nothing)))
if !(value === nothing) && show_value
Expand Down Expand Up @@ -210,7 +210,7 @@ function parse_input_line(s::String; filename::String="none")
s, sizeof(s), filename, sizeof(filename))
if ex isa Symbol && all(equalto('_'), string(ex))
# remove with 0.7 deprecation
expand(Main, ex) # to get possible warning about using _ as an rvalue
Meta.lower(Main, ex) # to get possible warning about using _ as an rvalue
end
return ex
end
Expand Down
5 changes: 3 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,10 @@ _current_module() = ccall(:jl_get_current_module, Ref{Module}, ())
depwarn("binding_module(symbol) is deprecated, use `binding_module(module, symbol)` instead.", :binding_module)
return binding_module(_current_module(), s)
end
export expand
@noinline function expand(@nospecialize(x))
depwarn("expand(x) is deprecated, use `expand(module, x)` instead.", :expand)
return expand(_current_module(), x)
depwarn("expand(x) is deprecated, use `Meta.lower(module, x)` instead.", :expand)
return Meta.lower(_current_module(), x)
end
@noinline function macroexpand(@nospecialize(x))
depwarn("macroexpand(x) is deprecated, use `macroexpand(module, x)` instead.", :macroexpand)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ export

# syntax
esc,
expand,
gensym,
macroexpand,
@macroexpand1,
Expand Down
9 changes: 0 additions & 9 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ copy_exprargs(x::Array{Any,1}) = Any[copy_exprs(a) for a in x]
==(x::Expr, y::Expr) = x.head === y.head && isequal(x.args, y.args)
==(x::QuoteNode, y::QuoteNode) = isequal(x.value, y.value)

"""
expand(m, x)
Takes the expression `x` and returns an equivalent expression in lowered form
for executing in module `m`.
See also [`code_lowered`](@ref).
"""
expand(m::Module, @nospecialize(x)) = ccall(:jl_expand, Any, (Any, Any), x, m)

"""
macroexpand(m::Module, x; recursive=true)
Expand Down
2 changes: 1 addition & 1 deletion base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function gen_call_with_extracted_types(__module__, fcn, ex0)
if isa(ex0, Expr) && ex0.head == :macrocall # Make @edit @time 1+2 edit the macro by using the types of the *expressions*
return Expr(:call, fcn, esc(ex0.args[1]), Tuple{#=__source__=#LineNumberNode, #=__module__=#Module, Any[ Core.Typeof(a) for a in ex0.args[3:end] ]...})
end
ex = expand(__module__, ex0)
ex = Meta.lower(__module__, ex0)
exret = Expr(:none)
if !isa(ex, Expr)
exret = Expr(:call, :error, "expression is not a function call or symbol")
Expand Down
9 changes: 9 additions & 0 deletions base/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ macro dump(expr)
dump(expr)
end

"""
lower(m, x)
Takes the expression `x` and returns an equivalent expression in lowered form
for executing in module `m`.
See also [`code_lowered`](@ref).
"""
lower(m::Module, @nospecialize(x)) = ccall(:jl_expand, Any, (Any, Any), x, m)

end # module

0 comments on commit a885ba7

Please sign in to comment.