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

const redefinition crashes with illegal hardware instruction #57566

Closed
adienes opened this issue Feb 27, 2025 · 2 comments · Fixed by #57567
Closed

const redefinition crashes with illegal hardware instruction #57566

adienes opened this issue Feb 27, 2025 · 2 comments · Fixed by #57567

Comments

@adienes
Copy link
Member

adienes commented Feb 27, 2025

same MWE as #57565 but I noticed it crashes Julia so making that a separate issue to track


julia> versioninfo()
Julia Version 1.13.0-DEV.128
Commit c8cd8fdb832 (2025-02-27 16:26 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-19.1.7 (ORCJIT, apple-m1)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)
julia> const x = 1
1

julia> function foo()
           while rand() < 0.99
               global x = (rand(1:2:11)^2) % 4
               println(x)
           end
       end
foo (generic function with 1 method)

julia> foo()

[89197] signal 4 (1): Illegal instruction: 4
in expression starting at REPL[4]:1
foo at ./REPL[3]:3
unknown function (ip: 0x113a70133) at (unknown file)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/./julia.h:2290 [inlined]
do_call at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/interpreter.c:124
eval_stmt_value at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/interpreter.c:193
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/interpreter.c:688
jl_interpret_toplevel_thunk at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/interpreter.c:897
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/toplevel.c:1032
__repl_entry_eval_expanded_with_loc at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:340
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/./julia.h:2290 [inlined]
jl_f__call_latest at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/builtins.c:883
#invokelatest#1 at ./essentials.jl:1090 [inlined]
invokelatest at ./essentials.jl:1086 [inlined]
toplevel_eval_with_hooks at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:347
toplevel_eval_with_hooks at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:351
toplevel_eval_with_hooks at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:344 [inlined]
eval_user_input at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:369
repl_backend_loop at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:481
#start_repl_backend#41 at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:466
start_repl_backend at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:463 [inlined]
#run_repl#48 at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:689
run_repl at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/usr/share/julia/stdlib/v1.13/REPL/src/REPL.jl:675
jfptr_run_repl_20745.1 at /Users/andy/.julia/juliaup/julia-nightly/share/julia/compiled/v1.13/REPL/u0gqU_j73Rz.dylib (unknown line)
run_std_repl at ./client.jl:488
jfptr_run_std_repl_60938.1 at /Users/andy/.julia/juliaup/julia-nightly/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/./julia.h:2290 [inlined]
jl_f__call_latest at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/builtins.c:883
#invokelatest#1 at ./essentials.jl:1090 [inlined]
invokelatest at ./essentials.jl:1086 [inlined]
run_main_repl at ./client.jl:509
repl_main at ./client.jl:596 [inlined]
_start at ./client.jl:571
jfptr__start_60157.1 at /Users/andy/.julia/juliaup/julia-nightly/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/./julia.h:2290 [inlined]
true_main at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/jlapi.c:964
jl_repl_entrypoint at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-master/src/jlapi.c:1124
Allocations: 2088352 (Pool: 2088276; Big: 76); GC: 3
[1]    89197 trace trap  julia +nightly
@adienes adienes changed the title const redefinition segfaults with illegal hardware instruction const redefinition crashes with illegal hardware instruction Feb 27, 2025
@Keno
Copy link
Member

Keno commented Feb 28, 2025

A simpler reproducer is

julia> const x = 1
1

julia> f() = global x = 1
f (generic function with 1 method)

julia> f()
Unreachable reached at 0x7f6758b062ee

[577425] signal 4 (2): Illegal instruction

The compiler thinks assignment to const without the const keyword should always error, but it is in fact allowed if and only if the rhs is egal to the value that's already there. That said, I think we should consider removing the special case and just making assignments to const bindings universally an error (as the compiler assumes they are).

Keno added a commit that referenced this issue Feb 28, 2025
We have historically allowed the following without warning or error:

```
const x = 1
x = 1
```

As well as
```
const x = 1
x = 2
```
with a UB warning.

In 1.12, we made the second case error, as part of the general binding
partition changes, but did not touch the first case, because it did not
have the warning.

I think this made a reasonable amount of sense, because we essentially
treated constants as special kinds of mutable globals (to which assignment
happened to be UB).

However, in the 1.12+ design, constants and globals are quite sepearate
beasts, and I think it makes sense to extend the error to the egal case
also, even if it is technically more breaking.

In fact, I already thought that's what I did when I implemented the new
effect model for global assignment, causing #57566. I can't think of a
legitimate reason to keep this special case. For those who want to do
binding replacement, the `const` keyword is mandatory, so the assignment
is now literally always a semantic no-op or an error.

Fixes #57566.
@adienes
Copy link
Member Author

adienes commented Feb 28, 2025

ah gotcha, thanks.

I think we should consider removing the special case and just making assignments to const bindings universally an error (as the compiler assumes they are).

not that anybody asked me, but I would 1000% agree

Keno added a commit that referenced this issue Feb 28, 2025
We have historically allowed the following without warning or error:

```
const x = 1
x = 1
```

As well as
```
const x = 1
x = 2
```
with a UB warning.

In 1.12, we made the second case error, as part of the general binding
partition changes, but did not touch the first case, because it did not
have the warning.

I think this made a reasonable amount of sense, because we essentially
treated constants as special kinds of mutable globals (to which assignment
happened to be UB).

However, in the 1.12+ design, constants and globals are quite sepearate
beasts, and I think it makes sense to extend the error to the egal case
also, even if it is technically more breaking.

In fact, I already thought that's what I did when I implemented the new
effect model for global assignment, causing #57566. I can't think of a
legitimate reason to keep this special case. For those who want to do
binding replacement, the `const` keyword is mandatory, so the assignment
is now literally always a semantic no-op or an error.

Fixes #57566.
Keno added a commit that referenced this issue Feb 28, 2025
We have historically allowed the following without warning or error:

```
const x = 1
x = 1
```

As well as
```
const x = 1
x = 2
```
with a UB warning.

In 1.12, we made the second case error, as part of the general binding
partition changes, but did not touch the first case, because it did not
have the warning.

I think this made a reasonable amount of sense, because we essentially
treated constants as special kinds of mutable globals (to which
assignment happened to be UB).

However, in the 1.12+ design, constants and globals are quite sepearate
beasts, and I think it makes sense to extend the error to the egal case
also, even if it is technically more breaking.

In fact, I already thought that's what I did when I implemented the new
effect model for global assignment, causing #57566. I can't think of a
legitimate reason to keep this special case. For those who want to do
binding replacement, the `const` keyword is mandatory, so the assignment
is now literally always a semantic no-op or an error.

Fixes #57566.
KristofferC pushed a commit that referenced this issue Mar 3, 2025
We have historically allowed the following without warning or error:

```
const x = 1
x = 1
```

As well as
```
const x = 1
x = 2
```
with a UB warning.

In 1.12, we made the second case error, as part of the general binding
partition changes, but did not touch the first case, because it did not
have the warning.

I think this made a reasonable amount of sense, because we essentially
treated constants as special kinds of mutable globals (to which
assignment happened to be UB).

However, in the 1.12+ design, constants and globals are quite sepearate
beasts, and I think it makes sense to extend the error to the egal case
also, even if it is technically more breaking.

In fact, I already thought that's what I did when I implemented the new
effect model for global assignment, causing #57566. I can't think of a
legitimate reason to keep this special case. For those who want to do
binding replacement, the `const` keyword is mandatory, so the assignment
is now literally always a semantic no-op or an error.

Fixes #57566.

(cherry picked from commit 8f00a51)
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

Successfully merging a pull request may close this issue.

2 participants