JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
266 stars 32 forks source link

0.4.8 lets `a.[1]` parse and lower #410

Open LilithHafner opened 5 months ago

LilithHafner commented 5 months ago

This came up at https://github.com/JuliaLang/julia/pull/53119

@LilithHafnerBot bisect()

using JuliaSyntax
JuliaSyntax.parse("a.[1]")
savq commented 5 months ago

Note that this was allowed in the flisp parser.

julia +lts -E ':(a.[1])'                                                                                                                                      
:(a.:([1]))
LilithHafner commented 5 months ago

There was a bug in the bisector backend. Should hopefully be fixed now.

@LilithHafnerBot bisect()

using JuliaSyntax
JuliaSyntax.parse(Expr, "a.[1]")
LilithHafnerBot commented 5 months ago

❌ Bisect failed

Commit stdout
b1c6d541ee41b0451d151a2074ca2a00f6c6e59c a.:([1])
a6f2d1580f7bbad11822033e8c83e607aa31f100 a.:([1])
LilithHafner commented 5 months ago

@LilithHafnerBot bisect()

using JuliaSyntax
JuliaSyntax.enable_in_core!()
eval(Meta.parse("""
Meta.lower(Main, :(a.[1]))
"""))
LilithHafnerBot commented 5 months ago

✅ Bisect succeeded! The first new commit is 296cd5ee4cded19cec84d8328da0b5ee1ce98f05

Commit stdout
b1c6d541ee41b0451d151a2074ca2a00f6c6e59c $(Expr(:error, "invalid syntax \"a.[1]\""))
e3e447da2fd849124bc4e520eb42a1f541f9bfce $(Expr(:error, "invalid syntax \"a.[1]\""))
8731bab86f14762cca8cf24224d8c7a6a89c21c5 $(Expr(:error, "invalid syntax \"a.[1]\""))
6da0fc487ad5af13fc4b1dd82679b4501a28c794 $(Expr(:error, "invalid syntax \"a.[1]\""))
5aad8126ac8380981ef8db75c01fea579956caff $(Expr(:error, "invalid syntax \"a.[1]\""))
296cd5ee4cded19cec84d8328da0b5ee1ce98f05 $(Expr(:thunk, CodeInfo(⏎ @ none within top-level scope⏎1 ─ %1 = Base.getproperty(a, $(Quote...
df84e02381b741f9982399b24c1c7bf2fbd630a2 $(Expr(:thunk, CodeInfo(⏎ @ none within top-level scope⏎1 ─ %1 = Base.getproperty(a, $(Quote...
a6f2d1580f7bbad11822033e8c83e607aa31f100 $(Expr(:thunk, CodeInfo(⏎ @ none within top-level scope⏎1 ─ %1 = Base.getproperty(a, $(Quote...
LilithHafner commented 5 months ago

@LilithHafnerBot bisect()

using JuliaSyntax
dump(JuliaSyntax.parse(Expr, "a.[1]"))
LilithHafnerBot commented 5 months ago

✅ Bisect succeeded! The first new commit is 296cd5ee4cded19cec84d8328da0b5ee1ce98f05

Commit stdout
b1c6d541ee41b0451d151a2074ca2a00f6c6e59c Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: Expr⏎ head: Symbol quo...
e3e447da2fd849124bc4e520eb42a1f541f9bfce Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: Expr⏎ head: Symbol quo...
8731bab86f14762cca8cf24224d8c7a6a89c21c5 Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: Expr⏎ head: Symbol quo...
6da0fc487ad5af13fc4b1dd82679b4501a28c794 Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: Expr⏎ head: Symbol quo...
5aad8126ac8380981ef8db75c01fea579956caff Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: Expr⏎ head: Symbol quo...
296cd5ee4cded19cec84d8328da0b5ee1ce98f05 Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: QuoteNode⏎ value: Expr...
df84e02381b741f9982399b24c1c7bf2fbd630a2 Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: QuoteNode⏎ value: Expr...
a6f2d1580f7bbad11822033e8c83e607aa31f100 Expr⏎ head: Symbol .⏎ args: Array{Any}((2,))⏎ 1: Symbol a⏎ 2: QuoteNode⏎ value: Expr...
LilithHafner commented 5 months ago

Alas, @savq, the old and new parsing results both print to :(a.:([1])), but they are not the same.

julia> old = Expr(:., :a, Expr(:quote, :([1])))
:(a.:([1]))

julia> new = Expr(:., :a, QuoteNode(:([1])))
:(a.:([1]))

julia> old == new
false

julia> Meta.lower(Main, old)
:($(Expr(:error, "invalid syntax \"a.[1]\"")))

julia> Meta.lower(Main, new)
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = Base.getproperty(a, $(QuoteNode(:([1]))))
└──      return %1
))))

From the commit message, this looks intentional; perhaps the appropriate fix is to prohibit this in lowering (and possibly gate the new parsing to new versions of Julia)

pfitzseb commented 5 months ago

Are Expr(:quote, ...) and QuoteNode(...) semantically identical?