Skip to content

Commit 828e5fe

Browse files
authored
Merge branch 'master' into patch-2
2 parents a68df3e + 296cca2 commit 828e5fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+527
-157
lines changed

.github/workflows/Typos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
timeout-minutes: 5
1212
steps:
1313
- name: Checkout the JuliaLang/julia repository
14-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
1515
with:
1616
persist-credentials: false
1717
- name: Check spelling with typos

.github/workflows/Whitespace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
timeout-minutes: 2
1616
steps:
1717
- name: Checkout the JuliaLang/julia repository
18-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
1919
with:
2020
persist-credentials: false
2121
- uses: julia-actions/setup-julia@5c9647d97b78a5debe5164e9eec09d653d29bd71 # v2.6.1

.github/workflows/cffconvert.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- name: Check out a copy of the repository
26-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
2727
with:
2828
persist-credentials: false
2929

Compiler/src/effects.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function is_better_effects(new::Effects, old::Effects)
218218
end
219219
end
220220
if new.effect_free == ALWAYS_TRUE
221-
any_improved |= old.consistent != ALWAYS_TRUE
221+
any_improved |= old.effect_free != ALWAYS_TRUE
222222
elseif new.effect_free == EFFECT_FREE_IF_INACCESSIBLEMEMONLY
223223
old.effect_free == ALWAYS_TRUE && return false
224224
any_improved |= old.effect_free != EFFECT_FREE_IF_INACCESSIBLEMEMONLY

JuliaLowering/src/compat.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ end
3434
graph = syntax_graph(ctx)
3535
toplevel_src = if isnothing(lnn)
3636
# Provenance sinkhole for all nodes until we hit a linenode
37-
dummy_src = SourceRef(
38-
SourceFile("No source for expression"),
39-
1, JS.GreenNode(K"None", 0))
37+
dummy_src = SourceRef(SourceFile("No source for expression"), 1, 0)
4038
_insert_tree_node(graph, K"None", dummy_src)
4139
else
4240
lnn
@@ -46,15 +44,14 @@ end
4644
return out
4745
end
4846

49-
function _expr_replace!(@nospecialize(e), replace_pred::Function, replacer!::Function,
47+
function _expr_replace(@nospecialize(e), replace_pred::Function, replacer::Function,
5048
recurse_pred=(@nospecialize e)->true)
5149
if replace_pred(e)
52-
replacer!(e)
53-
end
54-
if e isa Expr && recurse_pred(e)
55-
for a in e.args
56-
_expr_replace!(a, replace_pred, replacer!, recurse_pred)
57-
end
50+
replacer(e)
51+
elseif e isa Expr && recurse_pred(e)
52+
Expr(e.head, Any[_expr_replace(a, replace_pred, replacer, recurse_pred) for a in e.args]...)
53+
else
54+
e
5855
end
5956
end
6057

@@ -211,9 +208,6 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
211208
id_inner = _insert_tree_node(graph, K"String", src; value=e)
212209
setchildren!(graph, st_id, [id_inner])
213210
return st_id, src
214-
elseif e isa VersionNumber
215-
st_id = _insert_tree_node(graph, K"VERSION", src, JS.set_numeric_flags(e.minor*10); value=e)
216-
return st_id, src
217211
elseif !(e isa Expr)
218212
# There are other kinds we could potentially back-convert (e.g. Float),
219213
# but Value should work fine.
@@ -369,7 +363,8 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
369363
lam_eqs = Any[]
370364
for a in a1.args
371365
a isa LineNumberNode && continue
372-
a isa Expr && a.head === :(=) ? push!(lam_eqs, a) : push!(lam_args, a)
366+
a isa Expr && a.head === :(=) ?
367+
push!(lam_eqs, Expr(:kw, a.args...)) : push!(lam_args, a)
373368
end
374369
!isempty(lam_eqs) && push!(lam_args, Expr(:parameters, lam_eqs...))
375370
child_exprs[1] = a1_esc(Expr(:tuple, lam_args...))
@@ -407,7 +402,7 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
407402
st_flags |= JS.BARE_MODULE_FLAG
408403
end
409404
child_exprs = has_version ?
410-
Any[e.args[1], e.args[2+has_version], e.args[3+has_version]] :
405+
Any[Expr(:mod_version, e.args[1]), e.args[2+has_version], e.args[3+has_version]] :
411406
Any[e.args[2+has_version], e.args[3+has_version]]
412407
elseif e.head === :do
413408
# Expr:
@@ -439,11 +434,9 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
439434
child_exprs = child_exprs[2:end]
440435
# TODO handle docstrings after refactor
441436
elseif (e.head === :using || e.head === :import)
442-
_expr_replace!(e,
443-
(e)->(e isa Expr && e.head === :.),
444-
(e)->(e.head = :importpath))
445-
elseif e.head === :kw
446-
st_k = K"="
437+
e2 = _expr_replace(e, (e)->(e isa Expr && e.head === :.),
438+
(e)->Expr(:importpath, e.args...))
439+
child_exprs = e2.args
447440
elseif e.head in (:local, :global) && nargs > 1
448441
# Possible normalization
449442
# child_exprs = Any[Expr(:tuple, child_exprs...)]
@@ -565,6 +558,13 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
565558
child_exprs = nothing
566559
elseif e.head === :do_lambda
567560
st_k = K"do"
561+
elseif e.head === :mod_version
562+
v = e.args[1]
563+
@assert v isa VersionNumber
564+
st_k = K"VERSION"
565+
st_flags = JS.set_numeric_flags(v.minor*10)
566+
st_attrs[:value] = v
567+
child_exprs = nothing
568568
end
569569

570570
#---------------------------------------------------------------------------

JuliaLowering/src/desugaring.jl

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function check_no_parameters(ex::SyntaxTree, msg)
8686
end
8787

8888
function check_no_assignment(exs, msg="misplaced assignment statement in `[ ... ]`")
89-
i = findfirst(kind(e) == K"=" for e in exs)
89+
i = findfirst(kind(e) == K"=" || kind(e) == K"kw" for e in exs)
9090
if !isnothing(i)
9191
throw(LoweringError(exs[i], msg))
9292
end
@@ -532,17 +532,17 @@ end
532532

533533
#-------------------------------------------------------------------------------
534534
# Expansion of array indexing
535-
function _arg_to_temp(ctx, stmts, ex, eq_is_kw=false)
535+
function _arg_to_temp(ctx, stmts, ex)
536536
k = kind(ex)
537537
if is_effect_free(ex)
538538
ex
539539
elseif k == K"..."
540540
@ast ctx ex [k _arg_to_temp(ctx, stmts, ex[1])]
541-
elseif k == K"=" && eq_is_kw
542-
@ast ctx ex [K"=" ex[1] _arg_to_temp(ctx, stmts, ex[2], false)]
541+
elseif k == K"kw"
542+
@ast ctx ex [K"kw" ex[1] _arg_to_temp(ctx, stmts, ex[2])]
543543
elseif k == K"parameters"
544544
mapchildren(ctx, ex) do e
545-
_arg_to_temp(ctx, stmts, e, true)
545+
_arg_to_temp(ctx, stmts, e)
546546
end
547547
else
548548
emit_assign_tmp(stmts, ctx, ex)
@@ -565,9 +565,8 @@ function remove_argument_side_effects(ctx, stmts, ex)
565565
emit_assign_tmp(stmts, ctx, ex)
566566
else
567567
args = SyntaxList(ctx)
568-
eq_is_kw = ((k == K"call" || k == K"dotcall") && is_prefix_call(ex)) || k == K"ref"
569568
for (i,e) in enumerate(children(ex))
570-
push!(args, _arg_to_temp(ctx, stmts, e, eq_is_kw && i > 1))
569+
push!(args, _arg_to_temp(ctx, stmts, e))
571570
end
572571
# TODO: Copy attributes?
573572
@ast ctx ex [k args...]
@@ -1613,7 +1612,7 @@ function _merge_named_tuple(ctx, srcref, old, new)
16131612
end
16141613
end
16151614

1616-
function expand_named_tuple(ctx, ex, kws;
1615+
function expand_named_tuple(ctx, ex, kws, eq_is_kw;
16171616
field_name="named tuple field",
16181617
element_name="named tuple element")
16191618
name_strs = Set{String}()
@@ -1628,7 +1627,8 @@ function expand_named_tuple(ctx, ex, kws;
16281627
# x ==> x = x
16291628
name = to_symbol(ctx, kw)
16301629
value = kw
1631-
elseif k == K"="
1630+
elseif k == K"kw" || (eq_is_kw && k == K"=")
1631+
# syntax TODO: This should parse to K"kw"
16321632
# x = a
16331633
if kind(kw[1]) != K"Identifier" && kind(kw[1]) != K"Placeholder"
16341634
throw(LoweringError(kw[1], "invalid $field_name name"))
@@ -1696,7 +1696,7 @@ end
16961696
function expand_kw_call(ctx, srcref, farg, args, kws)
16971697
@ast ctx srcref [K"block"
16981698
func := farg
1699-
kw_container := expand_named_tuple(ctx, srcref, kws;
1699+
kw_container := expand_named_tuple(ctx, srcref, kws, false;
17001700
field_name="keyword argument",
17011701
element_name="keyword argument")
17021702
if all(kind(kw) == K"..." for kw in kws)
@@ -1724,13 +1724,12 @@ end
17241724

17251725
# Expand the (sym,lib) argument to ccall/cglobal
17261726
function expand_C_library_symbol(ctx, ex)
1727-
expanded = expand_forms_2(ctx, ex)
17281727
if kind(ex) == K"tuple"
1729-
expanded = @ast ctx ex [K"static_eval"(meta=name_hint("function name and library expression"))
1730-
expanded
1728+
return @ast ctx ex [K"static_eval"(meta=name_hint("function name and library expression"))
1729+
mapchildren(e->expand_forms_2(ctx,e), ctx, ex)
17311730
]
17321731
end
1733-
return expanded
1732+
return expand_forms_2(ctx, ex)
17341733
end
17351734

17361735
function expand_ccall(ctx, ex)
@@ -1870,7 +1869,7 @@ function remove_kw_args!(ctx, args::SyntaxList)
18701869
for i in 1:length(args)
18711870
arg = args[i]
18721871
k = kind(arg)
1873-
if k == K"="
1872+
if k == K"kw"
18741873
if isnothing(kws)
18751874
kws = SyntaxList(ctx)
18761875
end
@@ -2278,7 +2277,7 @@ end
22782277
function expand_function_arg(ctx, body_stmts, arg, is_last_arg, is_kw, arg_id)
22792278
ex = arg
22802279

2281-
if kind(ex) == K"="
2280+
if kind(ex) == K"kw"
22822281
default = ex[2]
22832282
ex = ex[1]
22842283
else
@@ -2859,8 +2858,10 @@ function keyword_function_defs(ctx, srcref, callex_srcref, name_str, typevar_nam
28592858
kwcall_body_tail
28602859
]
28612860
else
2862-
scope_nest(ctx, kw_names, kw_values, kwcall_body_tail)
2861+
scope_nest(ctx, has_kw_slurp ? kw_names[1:end-1] : kw_names,
2862+
kw_values, kwcall_body_tail)
28632863
end
2864+
28642865
main_kwcall_typevars = trim_used_typevars(ctx, kwcall_arg_types, typevar_names, typevar_stmts)
28652866
push!(kwcall_method_defs,
28662867
method_def_expr(ctx, srcref, callex_srcref, kwcall_mtable,
@@ -3234,6 +3235,29 @@ end
32343235

32353236
#-------------------------------------------------------------------------------
32363237
# Anon function syntax
3238+
function expand_arrow_args(ctx, arglist)
3239+
k = kind(arglist)
3240+
# The arglist can sometimes be parsed as a block, or something else, and
3241+
# fixing this is extremely awkward when nested inside `where`. See
3242+
# https://github.com/JuliaLang/JuliaSyntax.jl/pull/522
3243+
if k == K"block"
3244+
@chk numchildren(arglist) == 2
3245+
kw = arglist[2]
3246+
if kind(kw) === K"="
3247+
kw = @ast ctx kw [K"kw" children(kw)...]
3248+
end
3249+
arglist = @ast ctx arglist [K"tuple"
3250+
arglist[1]
3251+
[K"parameters" kw]
3252+
]
3253+
elseif k != K"tuple"
3254+
arglist = @ast ctx arglist [K"tuple" arglist]
3255+
end
3256+
return mapchildren(ctx, arglist) do a
3257+
kind(a) === K"=" ? @ast(ctx, a, [K"kw" children(a)...]) : a
3258+
end
3259+
end
3260+
32373261
function expand_arrow_arglist(ctx, arglist, arrowname)
32383262
k = kind(arglist)
32393263
if k == K"where"
@@ -3242,23 +3266,9 @@ function expand_arrow_arglist(ctx, arglist, arrowname)
32423266
arglist[2]
32433267
]
32443268
else
3245-
# The arglist can sometimes be parsed as a block, or something else, and
3246-
# fixing this is extremely awkward when nested inside `where`. See
3247-
# https://github.com/JuliaLang/JuliaSyntax.jl/pull/522
3248-
if k == K"block"
3249-
@chk numchildren(arglist) == 2
3250-
arglist = @ast ctx arglist [K"tuple"
3251-
arglist[1]
3252-
[K"parameters" arglist[2]]
3253-
]
3254-
elseif k != K"tuple"
3255-
arglist = @ast ctx arglist [K"tuple"
3256-
arglist[1]
3257-
]
3258-
end
32593269
@ast ctx arglist [K"call"
32603270
arrowname::K"Placeholder"
3261-
children(arglist)...
3271+
children(expand_arrow_args(ctx, arglist))...
32623272
]
32633273
end
32643274
end
@@ -3281,7 +3291,7 @@ function expand_opaque_closure(ctx, ex)
32813291
func_expr = ex[5]
32823292
@chk kind(func_expr) == K"->"
32833293
@chk numchildren(func_expr) == 2
3284-
args = func_expr[1]
3294+
args = expand_arrow_args(ctx, func_expr[1])
32853295
@chk kind(args) == K"tuple"
32863296
check_no_parameters(ex, args)
32873297

@@ -3830,7 +3840,7 @@ function _rewrite_ctor_new_calls(ctx, ex, struct_name, global_struct_name, ctor_
38303840
)
38313841
end
38323842
# Rewrite a call to new()
3833-
kw_arg_i = findfirst(e->(k = kind(e); k == K"=" || k == K"parameters"), children(ex))
3843+
kw_arg_i = findfirst(e->(k = kind(e); k == K"kw" || k == K"parameters"), children(ex))
38343844
if !isnothing(kw_arg_i)
38353845
throw(LoweringError(ex[kw_arg_i], "`new` does not accept keyword arguments"))
38363846
end
@@ -4148,7 +4158,7 @@ function expand_struct_def(ctx, ex, docs)
41484158
struct_name
41494159
isnothing(docs) ? nothing_(ctx, ex) : docs[1]
41504160
::K"SourceLocation"(ex)
4151-
[K"="
4161+
[K"kw"
41524162
"field_docs"::K"Identifier"
41534163
[K"call" "svec"::K"core" field_docs...]
41544164
]
@@ -4195,7 +4205,7 @@ end
41954205
function expand_curly(ctx, ex)
41964206
@assert kind(ex) == K"curly"
41974207
check_no_parameters(ex, "unexpected semicolon in type parameter list")
4198-
check_no_assignment(children(ex), "misplace assignment in type parameter list")
4208+
check_no_assignment(children(ex), "misplaced assignment in type parameter list")
41994209

42004210
typevar_stmts = SyntaxList(ctx)
42014211
type_args = SyntaxList(ctx)
@@ -4513,9 +4523,9 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
45134523
if numchildren(ex) > 1
45144524
throw(LoweringError(ex[end], "unexpected semicolon in tuple - use `,` to separate tuple elements"))
45154525
end
4516-
expand_forms_2(ctx, expand_named_tuple(ctx, ex, children(ex[1])))
4526+
expand_forms_2(ctx, expand_named_tuple(ctx, ex, children(ex[1]), true))
45174527
elseif any_assignment(children(ex))
4518-
expand_forms_2(ctx, expand_named_tuple(ctx, ex, children(ex)))
4528+
expand_forms_2(ctx, expand_named_tuple(ctx, ex, children(ex), true))
45194529
else
45204530
expand_forms_2(ctx, @ast ctx ex [K"call"
45214531
"tuple"::K"core"
@@ -4559,7 +4569,7 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
45594569
ctx.mod ::K"Value"
45604570
[K"inert" ex]
45614571
[K"parameters"
4562-
[K"="
4572+
[K"kw"
45634573
"expr_compat_mode"::K"Identifier"
45644574
ctx.expr_compat_mode::K"Bool"
45654575
]

JuliaLowering/src/eval.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,16 @@ function _to_lowered_expr(ex::SyntaxTree, stmt_offset::Int)
412412
Expr(:meta, args...)
413413
elseif k == K"static_eval"
414414
@assert numchildren(ex) == 1
415-
_to_lowered_expr(ex[1], stmt_offset)
416-
elseif k == K"cfunction"
417-
args = Any[_to_lowered_expr(e, stmt_offset) for e in children(ex)]
418-
if kind(ex[2]) == K"static_eval"
419-
args[2] = QuoteNode(args[2])
415+
if kind(ex[1]) === K"tuple"
416+
# Should just be ccall library spec
417+
@assert numchildren(ex[1]) === 2
418+
Expr(:tuple, _to_lowered_expr(ex[1][1], stmt_offset),
419+
_to_lowered_expr(ex[1][2], stmt_offset))
420+
elseif kind(ex[1]) === K"function"
421+
QuoteNode(Expr(ex))
422+
else
423+
_to_lowered_expr(ex[1], stmt_offset)
420424
end
421-
Expr(:cfunction, args...)
422425
else
423426
# Allowed forms according to https://docs.julialang.org/en/v1/devdocs/ast/
424427
#
@@ -438,6 +441,7 @@ function _to_lowered_expr(ex::SyntaxTree, stmt_offset::Int)
438441
k == K"gc_preserve_begin" ? :gc_preserve_begin :
439442
k == K"gc_preserve_end" ? :gc_preserve_end :
440443
k == K"foreigncall" ? :foreigncall :
444+
k == K"cfunction" ? :cfunction :
441445
k == K"new_opaque_closure" ? :new_opaque_closure :
442446
nothing
443447
if isnothing(head)

0 commit comments

Comments
 (0)