Julia: `===` comparison changes behaviour in local scope

Created on 2 Apr 2019  Â·  1Comment  Â·  Source: JuliaLang/julia

This came up on Slack and I've subsequently posted on Discourse here. An MWE would be the following:

a = "a"
@show a === "a" # true
for _ in 1:1
    @show a === "a" # false
    @show a .=== "a" # true
end

and similarly:

f() = a === "a" # false

Output of versioninfo():

Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\ProgramData\LONNG9\atom\app-1.35.1\atom.exe"  -a
  JULIA_NUM_THREADS = 2
bug codegen

Most helpful comment

Just a quick check to show that it's a bug in emit_f_is

julia> a = "a"
"a"

julia> f() = a === "a" # false
f (generic function with 1 method)

julia> @code_llvm f()

;  @ REPL[2]:1 within `f'
define i8 @julia_f_12276() #0 {
top:
  %0 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** inttoptr (i64 4557995032 to %jl_value_t addrspace(10)**), align 8
  %1 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
  %2 = icmp eq %jl_value_t addrspace(11)* %1, addrspacecast (%jl_value_t* inttoptr (i64 4578598160 to %jl_value_t*) to %jl_value_t addrspace(11)*)
  %3 = zext i1 %2 to i8
  ret i8 %3
}

I'll push a fix shortly.

>All comments

Just a quick check to show that it's a bug in emit_f_is

julia> a = "a"
"a"

julia> f() = a === "a" # false
f (generic function with 1 method)

julia> @code_llvm f()

;  @ REPL[2]:1 within `f'
define i8 @julia_f_12276() #0 {
top:
  %0 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** inttoptr (i64 4557995032 to %jl_value_t addrspace(10)**), align 8
  %1 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
  %2 = icmp eq %jl_value_t addrspace(11)* %1, addrspacecast (%jl_value_t* inttoptr (i64 4578598160 to %jl_value_t*) to %jl_value_t addrspace(11)*)
  %3 = zext i1 %2 to i8
  ret i8 %3
}

I'll push a fix shortly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sbromberger picture sbromberger  Â·  3Comments

wilburtownsend picture wilburtownsend  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

omus picture omus  Â·  3Comments

felixrehren picture felixrehren  Â·  3Comments