<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Himanshu Gupta</title>
    <description>The latest articles on DEV Community by Himanshu Gupta (@himanshu_gupta_99).</description>
    <link>https://dev.to/himanshu_gupta_99</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4168904%2F0c219682-fcb6-445e-a137-a92103b2f051.png</url>
      <title>DEV Community: Himanshu Gupta</title>
      <link>https://dev.to/himanshu_gupta_99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshu_gupta_99"/>
    <language>en</language>
    <item>
      <title>I Built a Python Rust Compiler: Inside Tarvos</title>
      <dc:creator>Himanshu Gupta</dc:creator>
      <pubDate>Wed, 07 Oct 2026 13:47:55 +0000</pubDate>
      <link>https://dev.to/himanshu_gupta_99/i-built-a-python-rust-compiler-inside-tarvos-3go7</link>
      <guid>https://dev.to/himanshu_gupta_99/i-built-a-python-rust-compiler-inside-tarvos-3go7</guid>
      <description>&lt;p&gt;I built &lt;strong&gt;Tarvos&lt;/strong&gt;, an open-source compiler that takes a defined, statically analyzable subset of Python and compiles it into standalone native executables using Rust.&lt;/p&gt;

&lt;p&gt;The basic pipeline looks like this:&lt;/p&gt;

&lt;p&gt;Python&lt;br&gt;
   ↓&lt;br&gt;
Ruff Parser&lt;br&gt;
   ↓&lt;br&gt;
Tarvos AST&lt;br&gt;
   ↓&lt;br&gt;
Semantic Analysis / Type Inference&lt;br&gt;
   ↓&lt;br&gt;
Tarvos IR&lt;br&gt;
   ↓&lt;br&gt;
Optimization&lt;br&gt;
   ↓&lt;br&gt;
Rust Code Generation&lt;br&gt;
   ↓&lt;br&gt;
rustc&lt;br&gt;
   ↓&lt;br&gt;
Native Executable&lt;/p&gt;

&lt;p&gt;The interesting part isn't simply converting Python syntax into Rust syntax.&lt;/p&gt;

&lt;p&gt;The real challenge is preserving Python semantics while moving execution into a native compilation pipeline.&lt;/p&gt;

&lt;p&gt;Why &lt;strong&gt;Tarvos&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Python is incredibly productive, but executing Python normally means relying on the Python runtime and its dynamic semantics.&lt;/p&gt;

&lt;p&gt;I wanted to explore a different question:&lt;/p&gt;

&lt;p&gt;How much of Python can be compiled into a real native executable when the compiler knows enough about the program?&lt;/p&gt;

&lt;p&gt;That led to Tarvos.&lt;/p&gt;

&lt;p&gt;It is not a replacement for CPython, and it doesn't attempt to compile every Python program.&lt;/p&gt;

&lt;p&gt;Instead, Tarvos deliberately targets a defined subset that can be analyzed and lowered safely.&lt;/p&gt;

&lt;p&gt;The Supported Subset&lt;/p&gt;

&lt;p&gt;Tarvos currently supports things such as:&lt;/p&gt;

&lt;p&gt;int, float, bool, str, lists and tuples&lt;br&gt;
Arithmetic, bitwise and logical operations&lt;br&gt;
if, for, while, break, continue&lt;br&gt;
Functions and type inference&lt;br&gt;
List comprehensions&lt;br&gt;
Native math operations&lt;br&gt;
Native os.path and time operations&lt;br&gt;
Local Python module imports&lt;br&gt;
CPython-compatible behavior for supported cases&lt;/p&gt;

&lt;p&gt;The compiler also handles cases where Python semantics differ from straightforward native operations.&lt;/p&gt;

&lt;p&gt;For example, Python's / and // don't mean the same thing, especially when negative values are involved.&lt;/p&gt;

&lt;p&gt;These details matter when the goal is compilation rather than simply producing code that looks similar.&lt;/p&gt;

&lt;p&gt;From AST to IR&lt;/p&gt;

&lt;p&gt;The compiler does not directly translate Python syntax into Rust.&lt;/p&gt;

&lt;p&gt;Python source is parsed first and represented internally using Tarvos's own structures.&lt;/p&gt;

&lt;p&gt;The program is then lowered into an intermediate representation.&lt;/p&gt;

&lt;p&gt;That gives the compiler a place to perform transformations before code generation.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Python Source&lt;br&gt;
     ↓&lt;br&gt;
AST&lt;br&gt;
     ↓&lt;br&gt;
Semantic Analysis&lt;br&gt;
     ↓&lt;br&gt;
IR&lt;br&gt;
     ↓&lt;br&gt;
Optimization&lt;br&gt;
     ↓&lt;br&gt;
Rust&lt;/p&gt;

&lt;p&gt;This separation is important because optimization and code generation shouldn't have to understand every detail of the original Python syntax.&lt;/p&gt;

&lt;p&gt;Optimization&lt;/p&gt;

&lt;p&gt;Tarvos already has compiler-level optimization passes including:&lt;/p&gt;

&lt;p&gt;Constant propagation&lt;br&gt;
Copy propagation&lt;br&gt;
Dead-code elimination&lt;br&gt;
Loop-related optimizations&lt;br&gt;
Native lowering for supported operations&lt;/p&gt;

&lt;p&gt;The goal is not to make Python "look like Rust."&lt;/p&gt;

&lt;p&gt;The goal is to generate better native code from the information available to the compiler.&lt;/p&gt;

&lt;p&gt;Native Rust Code Generation&lt;/p&gt;

&lt;p&gt;Once the program has passed analysis and optimization, Tarvos generates Rust code.&lt;/p&gt;

&lt;p&gt;That code is then compiled using rustc to produce the final native executable.&lt;/p&gt;

&lt;p&gt;The resulting executable is intended to run without requiring the Python runtime on the target machine.&lt;/p&gt;

&lt;p&gt;That's one of the main differences between simply packaging a Python application and compiling supported Python into native code.&lt;/p&gt;

&lt;p&gt;Unsupported Python&lt;/p&gt;

&lt;p&gt;Python is extremely dynamic.&lt;/p&gt;

&lt;p&gt;Trying to pretend that every Python feature can be statically compiled would be misleading.&lt;/p&gt;

&lt;p&gt;Tarvos therefore explicitly diagnoses unsupported features instead of silently generating incorrect behavior.&lt;/p&gt;

&lt;p&gt;Where applicable, Tarvos can use a hybrid fallback path for functionality that cannot currently be lowered natively.&lt;/p&gt;

&lt;p&gt;This is an important part of the compiler design:&lt;/p&gt;

&lt;p&gt;unsupported does not mean silently wrong.&lt;/p&gt;

&lt;p&gt;Testing Against CPython&lt;/p&gt;

&lt;p&gt;A compiler can produce an executable successfully and still be wrong.&lt;/p&gt;

&lt;p&gt;So Tarvos includes compatibility testing against CPython for supported programs.&lt;/p&gt;

&lt;p&gt;The goal is to compare behavior rather than simply checking whether compilation succeeds.&lt;/p&gt;

&lt;p&gt;That includes things such as:&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
Errors&lt;br&gt;
Exit codes&lt;br&gt;
Supported semantic behavior&lt;/p&gt;

&lt;p&gt;This makes compatibility testing part of the compiler workflow rather than an afterthought.&lt;/p&gt;

&lt;p&gt;What's Next?&lt;/p&gt;

&lt;p&gt;The next phase is focused on two things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;More Python&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Expanding support for more advanced Python features while keeping the compiler's semantics explicit and testable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I want to benchmark specific workloads across:&lt;/p&gt;

&lt;p&gt;CPython&lt;br&gt;
Nuitka&lt;br&gt;
Numba&lt;br&gt;
Cython&lt;br&gt;
Tarvos&lt;br&gt;
Native Rust&lt;/p&gt;

&lt;p&gt;But I'm deliberately avoiding blanket claims like:&lt;/p&gt;

&lt;p&gt;"Tarvos is X times faster than Python."&lt;/p&gt;

&lt;p&gt;Different tools solve different problems, and performance depends heavily on the workload.&lt;/p&gt;

&lt;p&gt;The goal is to produce reproducible benchmarks on identical workloads and understand where each approach performs well.&lt;/p&gt;

&lt;p&gt;Why I Built It&lt;/p&gt;

&lt;p&gt;Tarvos started as an engineering problem I wanted to understand.&lt;/p&gt;

&lt;p&gt;It pushed me much deeper into:&lt;/p&gt;

&lt;p&gt;Python internals&lt;br&gt;
Compiler frontends&lt;br&gt;
ASTs&lt;br&gt;
Intermediate representations&lt;br&gt;
Type inference&lt;br&gt;
Optimization&lt;br&gt;
Rust&lt;br&gt;
Native code generation&lt;br&gt;
Systems engineering&lt;/p&gt;

&lt;p&gt;And it is still evolving.&lt;/p&gt;

&lt;p&gt;The project is open source, and I'd genuinely like feedback from people working with Python, Rust, compilers and systems programming.&lt;/p&gt;

&lt;p&gt;What would you improve, add, or change in Tarvos?&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/repo-tech/tarvos" rel="noopener noreferrer"&gt;https://github.com/repo-tech/tarvos&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>programming</category>
      <category>python</category>
      <category>rust</category>
    </item>
  </channel>
</rss>
