News for hackers. Stuff that matters.
Re:A Case for a Native Runtime Compilation Language by PhilipVinc on Friday April 30, 2021 @04:08PM (#26998637)
Isn’t this roughly what Julia does?
Re:A Case for a Native Runtime Compilation Language by brrrrrm on Friday April 30, 2021 @06:33PM (#27000345)
yes! Julia does compile this way. Julia emphasizes JIT compilation based on runtime types rather than runtime values. I couldn't get runtime captures to work, e.g.

    a = 2
    function f(n)
      return n * a
    end

    println(f(4))
    @code_llvm f(4)
    @code_native f(4)
Re:A Case for a Native Runtime Compilation Language by eigenspace on Friday April 30, 2021 @07:16PM (#27000796)
That's because defining `a = 2` at the top level is a global constant, which can be changed at any time. Hence, the compiler can't optimize it out. If you tell the compiler it's a `const` though, it'll indeed do the optimization you were hoping for

    const a = 2
    f(n) = n * a

    julia> @code_llvm f(4)
    ;  @ REPL[2]:1 within `f'
    define i64 @julia_f_290(i64 signext %0) {
    top:
    ;  @ REPL[2]:2 within `f'
    ; ┌ @ int.jl:88 within `*'
       %1 = shl i64 %0, 1
    ; └
      ret i64 %1
    }

    julia> @code_native f(4)
            .text
    ; ┌ @ REPL[2]:2 within `f'
    ; │┌ @ int.jl:88 within `*'
            leaq    (%rdi,%rdi), %rax
    ; │└
            retq
            nopw    %cs:(%rax,%rax)
    ; └