# What could the Julia compiler learn from the LPython compiler?

**URL:** <https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226>\
**Category:** Offtopic\
**Created:** [July 29, 2023, 7:45am UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226 "2023-07-29T07:45:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [July 29, 2023, 7:45am UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/1 "2023-07-29T07:45:14Z")

</div>

LPython is a Python compiler that can compile Python code with type annotations into optimized machine code, and offers Just-In-Time (JIT) compilation and seamless interoperability with CPython.

> **[LPython: Novel, Fast, Retargetable Python Compiler](https://lpython.org/blog/2023/07/lpython-novel-fast-retargetable-python-compiler/)**
>
> About LPython is a Python compiler that can compile type-annotated Python code to optimized machine code. LPython offers several backends such as LLVM, C, C++, WASM, Julia and x86. LPython features quick compilation and runtime performance, as we...

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [July 29, 2023, 11:42am UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/2 "2023-07-29T11:42:22Z")

</div>

Note, Julia is mentioned in the announcement as a possible backend, but after a short exploration of both LPython and LFortran websites (both .org and GitHub) I could not find any other trace of it …

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [July 30, 2023, 4:32am UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/3 "2023-07-30T04:32:36Z")

</div>

> <https://github.com/lcompilers/lpython/blob/main/src/libasr/codegen/asr_to_julia.cpp>

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [July 30, 2023, 9:44am UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/4 "2023-07-30T09:44:51Z")

</div>

So it was in libasr. Thanks for the ref. I wonder if somebody could try (I may be doing that later) / have an opinion of converting python to Julia ?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 30, 2023, 12:02pm UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/5 "2023-07-30T12:02:11Z")

</div>

> [@jdad](#):
>
> I wonder if somebody could try (I may be doing that later) / have an opinion of converting python to Julia ?

This [is a FAQ](https://docs.julialang.org/en/v1/manual/faq/#Why-don't-you-compile-Matlab/Python/R/%E2%80%A6-code-to-Julia?).

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 30, 2023, 12:04pm UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/6 "2023-07-30T12:04:18Z")

</div>

From what I can see, LPython is compiling code where every variable type is declared and concrete. Like a Fortran code. It doesn’t include a type inference machinery. Julia does not have a declaration syntax that guarantees that a label is assigned always to the same type. Thus that conversion is probably limited.

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [July 30, 2023, 12:20pm UTC](https://discourse.julialang.org/t/what-could-the-julia-compiler-learn-from-the-lpython-compiler/102226/7 "2023-07-30T12:20:36Z")

</div>

Yes, now I remember it. The FAQ item explains very clearly why Julia as a compiler is needed/much better solution than thinking of it as a front end.

My asking/wondering was more on the two following other points , 1) why do a Julia backend, is there any interest for those LPython users - or developers-?, and 2) could it help to pushed some Python users to Julia?

That was only my 2cts of contribution inspired by the news,

PS. For 1), I was (notably) thinking of the possible usefulness of Julia stack of GPU, that is CUDA.jl, AMDGpu.jl, Metal.jl, oneAPI.jl, …
