Skip to content

Commit 911d8fb

Browse files
mlechuc42f
andcommitted
Apply suggestions from code review
Co-authored-by: Claire Foster <[email protected]>
1 parent 59e77d7 commit 911d8fb

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/desugaring.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,9 @@ function expand_assignment(ctx, ex, is_const=false)
13571357
# Identifier in lhs[1] is a variable type declaration, eg
13581358
# x::T = rhs
13591359
@ast ctx ex [K"block"
1360-
kind(x) === K"Placeholder" ? nothing : [K"decl" x T]
1360+
if kind(x) !== K"Placeholder"
1361+
[K"decl" x T]
1362+
end
13611363
is_const ? [K"const" [K"=" x rhs]] : [K"=" x rhs]
13621364
]
13631365
else
@@ -2172,8 +2174,12 @@ function make_lhs_decls(ctx, stmts, declkind, declmeta, ex, type_decls=true)
21722174
if kind(name) == K"Identifier"
21732175
push!(stmts, makenode(ctx, ex, K"decl", name, ex[2]))
21742176
else
2175-
# Setting the global type of underscores is likely undesired.
2176-
# Locals are debatable, though that isn't known here.
2177+
# TODO: Currently, this treats both globals and locals the same
2178+
# way by ignoring the LHS in `_::T = val`. For locals, we
2179+
# should probably do one of the following:
2180+
# - Throw a LoweringError if that's not too breaking
2181+
# - `convert(T, rhs)::T` and discard the result which is what
2182+
# `x::T = rhs` would do if x is never used again.
21772183
@chk kind(name) == K"Placeholder"
21782184
return
21792185
end
@@ -2316,11 +2322,14 @@ function expand_function_arg(ctx, body_stmts, arg, is_last_arg, is_kw, arg_id)
23162322
[K"=" ex name]
23172323
])
23182324
elseif k == K"Placeholder"
2319-
# The user shouldn't be able to access this name, but lowering should be
2320-
# able to use it as an rvalue internally, e.g. for kw method dispatch.
2321-
# Duplicate positional placeholder names should be allowed.
2322-
name_str = is_kw ? "#kw$(ex.name_val)#" : "#arg$(string(arg_id))#"
2323-
name = @ast ctx ex name_str::K"Identifier"
2325+
# Lowering should be able to use placeholder args as rvalues internally,
2326+
# e.g. for kw method dispatch. Duplicate positional placeholder names
2327+
# should be allowed.
2328+
name = if is_kw
2329+
@ast ctx ex ex=>K"Identifier"
2330+
else
2331+
new_local_binding(ctx, ex, "#arg$(string(arg_id))#"; kind=:argument)
2332+
end
23242333
elseif k == K"Identifier"
23252334
name = ex
23262335
else

src/macro_expansion.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,15 @@ function expand_forms_1(ctx::MacroExpansionContext, ex::SyntaxTree)
382382
k = kind(ex)
383383
if k == K"Identifier"
384384
name_str = ex.name_val
385-
if all(==('_'), name_str)
386-
@ast ctx ex ex=>K"Placeholder"
387-
elseif is_ccall_or_cglobal(name_str)
385+
if is_ccall_or_cglobal(name_str)
388386
# Lower special identifiers `cglobal` and `ccall` to `K"core"`
389387
# pseudo-refs very early so that cglobal and ccall can never be
390388
# turned into normal bindings (eg, assigned to)
391389
@ast ctx ex name_str::K"core"
392390
else
393-
layerid = get(ex, :scope_layer, current_layer_id(ctx))
394-
makeleaf(ctx, ex, ex, kind=K"Identifier", scope_layer=layerid)
391+
k = all(==('_'), name_str) ? K"Placeholder" : K"Identifier"
392+
scope_layer = get(ex, :scope_layer, current_layer_id(ctx))
393+
makeleaf(ctx, ex, ex; kind=k, scope_layer)
395394
end
396395
elseif k == K"StrMacroName" || k == K"CmdMacroName" || k == K"macro_name"
397396
# These can appear outside of a macrocall, e.g. in `import`

src/runtime.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,9 @@ function (g::GeneratedFunctionStub)(world::UInt, source::Method, @nospecialize a
337337

338338
__module__ = source.module
339339

340-
# Macro expansion. Looking at Core.GeneratedFunctionStub, it seems that
341-
# macros emitted by the generator are currently expanded in the latest
342-
# world, so do that for compatibility.
343-
macro_world = typemax(UInt)
340+
# Macro expansion. Note that we expand in `tls_world_age()` (see
341+
# Core.GeneratedFunctionStub)
342+
macro_world = Base.tls_world_age()
344343
ctx1 = MacroExpansionContext(graph, __module__, false, macro_world)
345344

346345
layer = only(ctx1.scope_layers)

0 commit comments

Comments
 (0)