@@ -25,7 +25,7 @@ function expr_to_syntaxtree(@nospecialize(e), lnn::Union{LineNumberNode, Nothing
2525 kind= Kind, syntax_flags= UInt16,
2626 source= SourceAttrType, var_id= Int, value= Any,
2727 name_val= String, is_toplevel_thunk= Bool,
28- scope_layer= LayerId)
28+ scope_layer= LayerId, meta = CompileHints )
2929 expr_to_syntaxtree (graph, e, lnn)
3030end
3131
@@ -188,17 +188,23 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
188188 if isnothing (e)
189189 st_id = _insert_tree_node (graph, K " core" , src; name_val= " nothing" )
190190 return st_id, src
191+ elseif e isa LineNumberNode
192+ # A LineNumberNode in value position evaluates to nothing
193+ st_id = _insert_tree_node (graph, K " core" , src; name_val= " nothing" )
194+ return st_id, e
191195 elseif e isa Symbol
192196 st_id = _insert_tree_node (graph, K " Identifier" , src; name_val= String (e))
193197 return st_id, src
194- elseif e isa QuoteNode && e. value isa Symbol
195- # Undo special handling from st->expr
196- return _insert_convert_expr (Expr (:quote , e. value), graph, src)
197- # elseif e isa QuoteNode
198- # st_id = _insert_tree_node(graph, K"inert", src)
199- # quote_child, _ = _insert_convert_expr(e.value, graph, src)
200- # setchildren!(graph, st_id, NodeId[quote_child])
201- # return st_id, src
198+ elseif e isa QuoteNode
199+ if e. value isa Symbol
200+ return _insert_convert_expr (Expr (:quoted_symbol , e. value), graph, src)
201+ elseif e. value isa Expr
202+ return _insert_convert_expr (Expr (:inert , e. value), graph, src)
203+ elseif e. value isa LineNumberNode
204+ return _insert_tree_node (graph, K " Value" , src; value= e. value), src
205+ else
206+ return _insert_convert_expr (e. value, graph, src)
207+ end
202208 elseif e isa String
203209 st_id = _insert_tree_node (graph, K " string" , src)
204210 id_inner = _insert_tree_node (graph, K " String" , src; value= e)
@@ -207,7 +213,9 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
207213 elseif ! (e isa Expr)
208214 # There are other kinds we could potentially back-convert (e.g. Float),
209215 # but Value should work fine.
210- st_k = e isa Integer ? K " Integer" : find_kind (string (typeof (e)))
216+ st_k = e isa Bool ? K " Bool" :
217+ e isa Integer ? K " Integer" :
218+ find_kind (string (typeof (e)))
211219 st_id = _insert_tree_node (graph, isnothing (st_k) ? K " Value" : st_k, src; value= e)
212220 return st_id, src
213221 end
@@ -354,6 +362,7 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
354362 lam_args = Any[]
355363 lam_eqs = Any[]
356364 for a in a1. args
365+ a isa LineNumberNode && continue
357366 a isa Expr && a. head === :(= ) ? push! (lam_eqs, a) : push! (lam_args, a)
358367 end
359368 ! isempty (lam_eqs) && push! (lam_args, Expr (:parameters , lam_eqs... ))
@@ -399,6 +408,10 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
399408 callargs = collect_expr_parameters (e. args[1 ], 2 )
400409 if e. args[1 ]. head === :macrocall
401410 st_k = K " macrocall"
411+ if callargs[2 ] isa LineNumberNode
412+ src = callargs[2 ]
413+ end
414+ deleteat! (callargs, 2 )
402415 c1,c1_esc = unwrap_esc (callargs[1 ])
403416 callargs[1 ] = c1_esc (Expr (:MacroName , c1))
404417 else
@@ -442,12 +455,6 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
442455 st_k = K " latestworld_if_toplevel"
443456 elseif e. head === Symbol (" hygienic-scope" )
444457 st_k = K " hygienic_scope"
445- elseif e. head === :escape
446- if length (e. args) == 1 && unwrap_esc_ (e. args[1 ]) isa LineNumberNode
447- # escape containing only a LineNumberNode will become empty and
448- # thus must be removed before lowering sees it.
449- st_k = K " TOMBSTONE"
450- end
451458 elseif e. head === :meta
452459 # Messy and undocumented. Only sometimes we want a K"meta".
453460 @assert e. args[1 ] isa Symbol
@@ -549,25 +556,27 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
549556 if isnothing (child_exprs)
550557 return st_id, src
551558 else
552- st_child_ids, last_src = _insert_child_exprs (child_exprs, graph, src)
559+ st_child_ids, last_src = _insert_child_exprs (e . head, child_exprs, graph, src)
553560 setchildren! (graph, st_id, st_child_ids)
554561 return st_id, last_src
555562 end
556563end
557564
558- function _insert_child_exprs (child_exprs:: Vector{Any} , graph :: SyntaxGraph ,
559- src:: SourceAttrType )
565+ function _insert_child_exprs (head :: Symbol , child_exprs:: Vector{Any} ,
566+ graph :: SyntaxGraph , src:: SourceAttrType )
560567 st_child_ids = NodeId[]
561568 last_src = src
562- for c in child_exprs
563- if c isa LineNumberNode
564- last_src = c
569+ for (i, c) in enumerate (child_exprs)
570+ c_unwrapped, _ = unwrap_esc (c)
571+ # If c::LineNumberNode is anywhere in a block OR c is not in tail
572+ # position, we don't need to insert `nothing` here
573+ if c_unwrapped isa LineNumberNode && (head === :block || head === :toplevel && i != length (child_exprs))
574+ last_src = c_unwrapped
565575 else
566- (c_id, c_src ) = _insert_convert_expr (c, graph, last_src)
576+ (c_id, last_src ) = _insert_convert_expr (c, graph, last_src)
567577 if ! isnothing (c_id)
568578 push! (st_child_ids, c_id)
569579 end
570- last_src = something (c_src, src)
571580 end
572581 end
573582 return st_child_ids, last_src
0 commit comments