Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions JuliaLowering/src/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
id_inner = _insert_tree_node(graph, K"String", src; value=e)
setchildren!(graph, st_id, [id_inner])
return st_id, src
elseif e isa VersionNumber
st_id = _insert_tree_node(graph, K"VERSION", src, JS.set_numeric_flags(e.minor*10); value=e)
return st_id, src
elseif !(e isa Expr)
# There are other kinds we could potentially back-convert (e.g. Float),
# but Value should work fine.
Expand Down Expand Up @@ -407,7 +404,7 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
st_flags |= JS.BARE_MODULE_FLAG
end
child_exprs = has_version ?
Any[e.args[1], e.args[2+has_version], e.args[3+has_version]] :
Any[Expr(:mod_version, e.args[1]), e.args[2+has_version], e.args[3+has_version]] :
Any[e.args[2+has_version], e.args[3+has_version]]
elseif e.head === :do
# Expr:
Expand Down Expand Up @@ -565,6 +562,13 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
child_exprs = nothing
elseif e.head === :do_lambda
st_k = K"do"
elseif e.head === :mod_version
v = e.args[1]
@assert v isa VersionNumber
st_k = K"VERSION"
st_flags = JS.set_numeric_flags(v.minor*10)
st_attrs[:value] = v
child_exprs = nothing
end

#---------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion JuliaLowering/src/macro_expansion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ function expand_macro(ctx, ex)
# Compat: attempt to invoke an old-style macro if there's no applicable
# method for new-style macro arguments.
macro_args = Any[macro_loc, ctx.scope_layers[1].mod]

if length(raw_args) >= 1 && kind(raw_args[1]) === K"VERSION"
# Hack: see jl_invoke_julia_macro. We may see an extra argument
# depending on who parsed this macrocall.
macro_args[1] = Core.MacroSource(macro_loc, raw_args[1].value)
end

for arg in raw_args
# For hygiene in old-style macros, we omit any additional scope
# layer information from macro arguments. Old-style macros will
Expand All @@ -335,7 +342,7 @@ function expand_macro(ctx, ex)
# new-style macros which call old-style macros. Instead of seeing
# `Expr(:escape)` in such situations, old-style macros will now see
# `Expr(:scope_layer)` inside `macro_args`.
push!(macro_args, Expr(arg))
kind(arg) !== K"VERSION" && push!(macro_args, Expr(arg))
end
expanded = try
Base.invoke_in_world(ctx.macro_world, macfunc, macro_args...)
Expand Down
13 changes: 13 additions & 0 deletions JuliaLowering/test/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ ctx, expanded = JuliaLowering.expand_forms_1(test_mod, ex, false, Base.get_world
"y"
]

@test JuliaLowering.include_string(test_mod, raw"""
v"1.14"
""") isa VersionNumber
@test JuliaLowering.include_string(test_mod, raw"""
v"1.14"
""";expr_compat_mode=true) isa VersionNumber
@test JuliaLowering.include_string(test_mod, raw"""
Base.Experimental.@VERSION
""") isa NamedTuple
@test JuliaLowering.include_string(test_mod, raw"""
Base.Experimental.@VERSION
""";expr_compat_mode=true) isa NamedTuple

# World age support for macro expansion
JuliaLowering.include_string(test_mod, raw"""
macro world_age_test()
Expand Down