JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
274 stars 33 forks source link

Failures found using fuzz testing #380

Open c42f opened 1 year ago

c42f commented 1 year ago

Using the tools from #379 uncovers several bugs. For example

fuzz_test(try_parseall_failure, product_token_fuzz(cutdown_tokens, 2))
fuzz_test(try_hook_failure, product_token_fuzz(cutdown_tokens, 2))
fuzz_test(try_parseall_failure, random_token_fuzz(cutdown_tokens, 10, 10_000_000))

Some errors found with this:

Parser errors

Tree building errors

Hook errors

vtjnash commented 11 months ago

Are these also fuzz errors:

Parse core.jl: Test Failed at /home/pkgeval/.julia/packages/JuliaSyntax/r20Wu/test/test_utils.jl:241
  Expression: reduced_failures == []
   Evaluated: AbstractString["for f() in 1:3\n        push!(a, f())\n        push!(fs, f)\n    end",
                             " {{}}where{}"] == Any[]

https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/1fc9d54_vs_72cd63c/JuliaSyntax.primary.log

c42f commented 11 months ago

Thanks for pointing that out. Also now visible on JuliaSyntax dev branch with nightly (eg, https://github.com/JuliaLang/JuliaSyntax.jl/actions/runs/6968830137/job/18963527621#step:21:414)

Here's a slightly less minimal but more realistic reproduction of the new failure of parsing comparison of JuliaLang test/core.jl:

julia> dump(JuliaSyntax.fl_parse(Expr, "A where {T} == Z"))
Expr
  head: Symbol where
  args: Array{Any}((2,))
    1: Symbol A
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol ==
        2: Expr
          head: Symbol braces
          args: Array{Any}((1,))
            1: Symbol T
        3: Symbol Z

julia> dump(JuliaSyntax.parsestmt(Expr, "A where {T} == Z"))
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol ==
    2: Expr
      head: Symbol where
      args: Array{Any}((2,))
        1: Symbol A
        2: Symbol T
    3: Symbol Z

vs the following without the curlies which parses the same in both parsers

julia> dump(JuliaSyntax.parsestmt(Expr, "A where T == Z"))
Expr
  head: Symbol where
  args: Array{Any}((2,))
    1: Symbol A
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol ==
        2: Symbol T
        3: Symbol Z