Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal instruction on 1.8.5 with varargs #50518

Closed
ericphanson opened this issue Jul 12, 2023 · 6 comments
Closed

Illegal instruction on 1.8.5 with varargs #50518

ericphanson opened this issue Jul 12, 2023 · 6 comments
Assignees

Comments

@ericphanson
Copy link
Contributor

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> function f(xs...=["a", "b", "c"]...; debug=false)
           return xs[1]
       end
f (generic function with 2 methods)

julia> f()
"a"

julia> f(; debug=false)
Unreachable reached at 0x7fd84373a5b6

signal (4): Illegal instruction
in expression starting at REPL[3]:1
f##kw at ./REPL[1]:1
unknown function (ip: 0x7fd84373a60d)
_jl_invoke at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2377 [inlined]
ijl_apply_generic at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2559
jl_apply at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/julia.h:1843 [inlined]
do_call at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/interpreter.c:126
eval_value at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/interpreter.c:215
eval_stmt_value at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/interpreter.c:166 [inlined]
eval_body at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/interpreter.c:612
jl_interpret_toplevel_thunk at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/interpreter.c:750
jl_toplevel_eval_flex at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/toplevel.c:906
jl_toplevel_eval_flex at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/toplevel.c:850
jl_toplevel_eval_flex at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/toplevel.c:850
ijl_toplevel_eval_in at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/toplevel.c:965
eval at ./boot.jl:368 [inlined]
eval_user_input at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:151
repl_backend_loop at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:247
start_repl_backend at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:232
#run_repl#47 at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:369
run_repl at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:355
jfptr_run_repl_65104.clone_1 at /home/ubuntu/.julia/juliaup/julia-1.8.5+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2377 [inlined]
ijl_apply_generic at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2559
#967 at ./client.jl:419
jfptr_YY.967_33139.clone_1 at /home/ubuntu/.julia/juliaup/julia-1.8.5+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2377 [inlined]
ijl_apply_generic at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2559
jl_apply at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/julia.h:1843 [inlined]
jl_f__call_latest at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/builtins.c:774
#invokelatest#2 at ./essentials.jl:729 [inlined]
invokelatest at ./essentials.jl:726 [inlined]
run_main_repl at ./client.jl:404
exec_options at ./client.jl:318
_start at ./client.jl:522
jfptr__start_38041.clone_1 at /home/ubuntu/.julia/juliaup/julia-1.8.5+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2377 [inlined]
ijl_apply_generic at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/gf.c:2559
jl_apply at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/julia.h:1843 [inlined]
true_main at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/jlapi.c:575
jl_repl_entrypoint at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/src/jlapi.c:719
main at /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/cli/loader_exe.c:59
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x401098)
Allocations: 2043817 (Pool: 2042285; Big: 1532); GC: 2
[1]    1759237 illegal hardware instruction (core dumped)  julia

on

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD EPYC 7R13 Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, znver3)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_PKG_USE_CLI_GIT = true
@ericphanson
Copy link
Contributor Author

On apple silicon, w/ Julia 1.8 and 1.9, this just seems to hang rather than crash.

@inkydragon
Copy link
Sponsor Member

Also confirmed in

  • Version 1.6.7, test on Win10 and Ubuntu 22.04.2
  • Version 1.10.0-alpha1, DEBUG build with assert
    Printed a similar stack trace.

@Keno Keno self-assigned this Jul 14, 2023
@Keno
Copy link
Member

Keno commented Jul 14, 2023

There's a couple of separate issues here:

  1. The xs...=["a", "b", "c"]... was never really supposed to work and only works by accident. @JeffBezanson thinks the syntax is reasonable for what is intended, but we need to decide where the boundaries of the syntax are.

1a. For example, what should the following do?

julia> function g(a=(1,2)..., b...=3)
           b
       end
g (generic function with 3 methods)

julia> g()
(2,)
  1. The lowering for that syntax in the keyword case is bad and uses an argument marked #unused#

  2. Even though we're using #unused#, we should be robust to that elsewhere (in particular lowering and codegen) to avoid a segfault.

Keno added a commit that referenced this issue Jul 14, 2023
Fixes the segfault in #50518 and turns it into a proper error at
both the syntax level (to catch lowering generating bad slot references)
as well as at the codegen level (to catch e.g. bad generated functions
and opaque closures). However, note that the latter case is technically
undefined behavior, because we do not model the possibility that an
otherwise-defined argument could throw at access time. Of course,
throwing an error is allowable as undefined behavior and preferable
to a segfault.
@Keno
Copy link
Member

Keno commented Jul 14, 2023

#50556 for issue 3.

Keno added a commit that referenced this issue Jul 14, 2023
Fixes the segfault in #50518 and turns it into a proper error at
both the syntax level (to catch lowering generating bad slot references)
as well as at the codegen level (to catch e.g. bad generated functions
and opaque closures). However, note that the latter case is technically
undefined behavior, because we do not model the possibility that an
otherwise-defined argument could throw at access time. Of course,
throwing an error is allowable as undefined behavior and preferable
to a segfault.
Keno added a commit that referenced this issue Jul 14, 2023
Fixes the case from #50518, but we actually have two test cases in
the tests that also hit this (e.g. this one:
```
f40964(xs::Int...=1; k = 2) = (xs, k)
```), but just happened not to hit the bad codegen path. #50556,
once merged would have complained on those definitions as well,
without this fix.
@Keno
Copy link
Member

Keno commented Jul 14, 2023

#50559 for issue 2.

github-merge-queue bot pushed a commit that referenced this issue Jul 15, 2023
Fixes the case from #50518, but we actually have two test cases in the
tests that also hit this (e.g. this one:
```
f40964(xs::Int...=1; k = 2) = (xs, k)
```
), but just happened not to hit the bad codegen path. #50556, once
merged would have complained on those definitions as well, without this
fix.
Keno added a commit that referenced this issue Jul 15, 2023
Pop quiz: Do you know what the following will do?
```
julia> function g1(a=(1,2)..., b...=3)
    b
end

julia> g1()

julia> function g2(a=(1,2)..., b=3, c=4)
    (b, c)
end

julia> g2()

julia> function g3(a=(1,2)..., b=3, c...=4)
    (b, c)
end

julia> g3()

julia> g3(1)
```

I don't either and I don't think it's particularly well defined.
Splatting a default argument makes sense on the last argument,
which can be a vararg, and it is desirable to be able to specify
the default for the whole varargs tuple at once (although arguably
that should just be the non-`...` behavior, but that'd be too
breaking a change). Ref #50518. However, for other arguments,
there isn't really a sensible semantic meaning. This PR disallows
this in lowering. This is technically a minor change, but I doubt
anybody is using this. Splatting in default values wasn't really
ever supposed to work anyway, it just happened to fall out of
our lowering.
@Keno
Copy link
Member

Keno commented Jul 15, 2023

#50563 for issue 1.

Keno added a commit that referenced this issue Jul 15, 2023
Pop quiz: Do you know what the following will do?
```
julia> function g1(a=(1,2)..., b...=3)
    b
end

julia> g1()

julia> function g2(a=(1,2)..., b=3, c=4)
    (b, c)
end

julia> g2()

julia> function g3(a=(1,2)..., b=3, c...=4)
    (b, c)
end

julia> g3()

julia> g3(1)
```

I don't either and I don't think it's particularly well defined.
Splatting a default argument makes sense on the last argument,
which can be a vararg, and it is desirable to be able to specify
the default for the whole varargs tuple at once (although arguably
that should just be the non-`...` behavior, but that'd be too
breaking a change). Ref #50518. However, for other arguments,
there isn't really a sensible semantic meaning. This PR disallows
this in lowering. This is technically a minor change, but I doubt
anybody is using this. Splatting in default values wasn't really
ever supposed to work anyway, it just happened to fall out of
our lowering.
Keno added a commit that referenced this issue Jul 15, 2023
Pop quiz: Do you know what the following will do?
```
julia> function g1(a=(1,2)..., b...=3)
    b
end

julia> g1()

julia> function g2(a=(1,2)..., b=3, c=4)
    (b, c)
end

julia> g2()

julia> function g3(a=(1,2)..., b=3, c...=4)
    (b, c)
end

julia> g3()

julia> g3(1)
```

I don't either and I don't think it's particularly well defined.
Splatting a default argument makes sense on the last argument,
which can be a vararg, and it is desirable to be able to specify
the default for the whole varargs tuple at once (although arguably
that should just be the non-`...` behavior, but that'd be too
breaking a change). Ref #50518. However, for other arguments,
there isn't really a sensible semantic meaning. This PR disallows
this in lowering. This is technically a minor change, but I doubt
anybody is using this. Splatting in default values wasn't really
ever supposed to work anyway, it just happened to fall out of
our lowering.
github-merge-queue bot pushed a commit that referenced this issue Jul 16, 2023
Fixes the segfault in #50518 and turns it into a proper error at both
the syntax level (to catch lowering generating bad slot references) as
well as at the codegen level (to catch e.g. bad generated functions and
opaque closures). However, note that the latter case is technically
undefined behavior, because we do not model the possibility that an
otherwise-defined argument could throw at access time. Of course,
throwing an error is allowable as undefined behavior and preferable to a
segfault.
KristofferC pushed a commit that referenced this issue Jul 17, 2023
Fixes the case from #50518, but we actually have two test cases in
the tests that also hit this (e.g. this one:
```
f40964(xs::Int...=1; k = 2) = (xs, k)
```), but just happened not to hit the bad codegen path. #50556,
once merged would have complained on those definitions as well,
without this fix.

(cherry picked from commit c272236)
Keno added a commit that referenced this issue Jul 18, 2023
Pop quiz: Do you know what the following will do?
```
julia> function g1(a=(1,2)..., b...=3)
    b
end

julia> g1()

julia> function g2(a=(1,2)..., b=3, c=4)
    (b, c)
end

julia> g2()

julia> function g3(a=(1,2)..., b=3, c...=4)
    (b, c)
end

julia> g3()

julia> g3(1)
```

I don't either and I don't think it's particularly well defined.
Splatting a default argument makes sense on the last argument, which can
be a vararg, and it is desirable to be able to specify the default for
the whole varargs tuple at once (although arguably that should just be
the non-`...` behavior, but that'd be too breaking a change). Ref
#50518. However, for other arguments, there isn't really a sensible
semantic meaning. This PR disallows this in lowering. This is
technically a minor change, but I doubt anybody is using this. Splatting
in default values wasn't really ever supposed to work anyway, it just
happened to fall out of our lowering.

---------

Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
@Keno Keno closed this as completed Jul 20, 2023
KristofferC pushed a commit that referenced this issue Aug 10, 2023
Fixes the case from #50518, but we actually have two test cases in
the tests that also hit this (e.g. this one:
```
f40964(xs::Int...=1; k = 2) = (xs, k)
```), but just happened not to hit the bad codegen path. #50556,
once merged would have complained on those definitions as well,
without this fix.

(cherry picked from commit c272236)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants