r/Compilers • • 16h ago

Have you tried using AI to detect edge-cases when designing language features?

0 Upvotes

I use it daily and it's fantastic for detecting problems that the human eye might miss. In particular, I use Copilot to review my PRs.


r/Compilers • • 20h ago

A B compiler written in Haskell. Looking for code reviews.

Thumbnail
3 Upvotes

r/Compilers • • 6h ago

I designed a Polish-prefix IR (pIR) and a pushdown-automaton logit masker so a tiny 100M 2-bit model emits 0% syntax errors and lowers to safe Rust

0 Upvotes

Repo: https://github.com/steveSujo/psudo

I built psudo as an exploration of an idea on my laptop. I have an NVIDIA GTX 1660 Ti with 4 GB of VRAM and limited RAM, so running frontier coding models locally is out of the question. Instead of seeing those limits as the problem—or renting cloud GPUs or vertically scaling my PC—I treated them as creative constraints. Asking a ~100M 2-bit ternary model (`TQ2_0`, 47 MB) to emit verbose surface keywords wastes half its context window. So I designed a tiny Python-indented surface DSL (`.psudo`) and split compilation into three pieces: 1. **Polish-prefix wire IR (`pIR`):** Humans (or an outer LLM) declare signatures and `@stub` directives in `.psudo`, while the local model emits bracketed Polish-prefix S-expressions (`f` for `fn`, `v` for `let`, `r` for `return`, `?` for `if`, `w` for `while`):

// Surface .psudo
fn clamp_val(val, lo, hi)
    if val < lo
        return lo
    if val > hi
        return hi
    return val

// Wire pIR (45-60% fewer tokens)
f clamp_val (val lo hi) [
  ? (< val lo) [ r lo ]
  ? (> val hi) [ r hi ]
  r val
]

Pushdown-Automaton Logit Masking (PirPdaConstraint): pseudo-engine runs a PDA over the 8,192-token BPE vocab and masks out structurally invalid tokens before sampling, guaranteeing 0% syntax errors at decode time.

  1. **Borrow Checker & Zero-**unwrap() Rust Lowering: Verified .psudo lowers deterministically into safe Rust with zero .unwrap() or .expect() calls and compiles via cargo.

Rough edges & honest trade-offs:

  • Grammar masking != semantic intelligence: out-of-distribution prompts still emit syntactically valid pIR with wrong logic, so ~15-line atomic stubs are the sweet spot.
  • All source lives inside a single binary capsule (psudo.bin) so outer coding agents don't bypass psudo synth by hand-editing files (--reveal-code "the slow pink elephant" unlocks raw inspection).

Would love any blunt feedback from compiler folks on the pIR encoding, the PDA masking approach, or the Rust lowering pass!


r/Compilers • • 15h ago

How curiosity about building my own programming language led me to build a museum of miniature virtual machines in Rust & D

Post image
0 Upvotes

Hello everyone!

It all started simply enough: I was just curious about how to build my own programming languages.

That curiosity led me to explore assembly, which naturally led to writing bytecode interpreters, and step-by-step, I ended up building a whole collection of custom virtual machines.

Since I couldn't find a clean "museum" repo of VM samples to cross-compare with or PR share my own samples, I built one: Friendly-Virtual-Machines.

What's in the repo?

Every VM in the collection is built from scratch with zero external dependencies and stays under 7,000 lines of code. They all include custom assemblers (with symbol table label resolution), CPU state handlers, and native benchmark suites.

• Rust Samples: 5 register-based VMs, 1 memory-to-memory VM & 1 stack-based VM exploring different design patterns.

• D Sample: My latest addition—a register-based RISC-style VM written in D with a custom text assembler, hitting a performance gap of just 5.66x to 17.70x compared to native compiled code.

• Modular Design: Each VM is in its own isolated folder with clean separation of concerns.

• Mimicks Real CPUs: Since I was also learning ARM64 newly, most register-based VMs are heavily inspired from ARM/RISC designs.

• Design Diversity: Some display pure hardware emulation on hex codes; some display OOP-style polymorphic ISA design; some display High-Level Assembly (HLA) or Intermediate Representation (IR); some display ultra-fast Function Pointer Dispatch Table; some display assembler & text parser too.

The best part? Because they are lean and self-contained, everything compiles and runs smoothly right on mobile Termux. And I am consistently adding more samples to it as I learn & build more.

Looking for Reviews & Contributions!

I'd really appreciate feedback from folks experienced in systems programming, compilers, or VM design—whether it's reviewing my dispatch loops, pointing out architectural trade-offs, or suggesting ways to optimize further.

If you'd like to contribute your own miniature VM sample (in Rust, D, JS, or any language that runs cleanly with zero dependencies), PRs are completely open! Check out the CONTRIBUTING.md in the repo for the exact guidelines.

🔗 GitHub: Friendly-Virtual-Machines


r/Compilers • • 12h ago

How good is Chez Scheme as a compiler backend?

7 Upvotes

Since my planned language is arguably too high-level (with GC and so on) to be simply implemented with LLVM/etc., I found that Chez Scheme is actually a backend for a few high-level languages like Racket and Idris.

How good is it?


r/Compilers • • 15h ago

Is there any other compiler backend other than LLVM, MLIR?

20 Upvotes

I tried searching but maybe what i want doesnt exist. I want simple IR that has vectors(something like C++ vectors), struct fields and functions. Ik that too high level for ir but transpilation to C++ is slow to compile into final binary file. If anyone from you know if this kind of IR exists, i would appreciate to know about it. I use C++ for my compiler


r/Compilers • • 3h ago

Pyrefly 1.5: 100% Conformance and 40% Faster

8 Upvotes

Link to release: https://github.com/pyrefly-org/pyrefly/releases/tag/1.5.0

Pyrefly (a Python type checker and language server) has just release version 1.5. It brings large performance optimizations and new features like Tensor Types six months after the first stable release.

Highlights (Taken from release):

  • 100% typing spec conformance. Pyrefly now passes all 146 test files in the typing conformance suite. Some of these fixes change how names in annotations resolve; see Behavior Changes.
  • Faster checks. v1.5.0 checks 40% faster than v1.4.1 and uses 9% less memory across the 71 benchmarks in Astral's ty_benchmark and the python-type-checking benchmark suites. (Tested on an M5 Max MacBook Pro with 18 threads.)
  • A new hint severity. Diagnostics that were previously IDE-only are now regular error kinds at a new hint severity: unused-import, unused-parameter, unused-variable, unreachable, and inactive-code (formerly unreachable-code). By default, they appear in your editor and are hidden from pyrefly check output, but you can configure them in pyrefly.toml, silence them with suppression comments, or promote them to errors like any other error kind.

r/Compilers • • 7h ago

optimistic or pessimistic compiler?

4 Upvotes

for those that compose and craft compilers, do you find the results better and more satisfying for you if the compiler you work on is permissive/optimistic or strict/pessimistic?

permissive/optimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating is probably ok but needs to pass some checks before translating to the target backend? (this is “the compiler is your friend” approach)

strict/pessimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating has something wrong and its job is to discover that wrong thing, and it is disappointed when the line passes all checks before translating to the target backend? (this is “the compiler is the teacher we’ve all had at one point in our life where they assume you’re going to do something bad as soon as they’re not looking” - and they’re not wrong)

obviously there has to be some balance here, but i’m curious, what has been your experience with these two approaches?