<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fh="http://purl.org/syndication/history/1.0"><channel><title>Glyim | Blog</title><description>Documentation for Glyim, a modular, from-scratch compiler for a Rust-like systems programming language, written in Rust.</description><link>https://vercel.app/</link><language>en</language><fh:complete/><atom:link rel="self" href="https://vercel.app/blog/rss.xml"/><item><title>How we built a 39-crate compiler with two backends</title><link>https://vercel.app/blog/welcome-to-glyim/</link><guid isPermaLink="true">https://vercel.app/blog/welcome-to-glyim/</guid><pubDate>Sun, 15 Nov 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Most toy compilers stop after the parser. Glyim doesn’t.&lt;/p&gt;
&lt;p&gt;We wanted a Rust-like systems language that goes from lexing to native code, but we didn’t want the architecture to become a black box. If you open the type checker, you shouldn’t have to mentally parse the borrow checker to understand it.&lt;/p&gt;
&lt;p&gt;That constraint drove our first major decision: a strict 39-crate workspace. Thirty-four handle the language and standard library; five handle tooling. The frontend is a sequence of discrete IRs (AST, HIR, THIR, MIR), and every phase has a narrow public API.&lt;/p&gt;
&lt;div&gt;&lt;h2 id=&quot;the-goal&quot;&gt;The Goal&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;We needed generics, traits, pattern matching, closures, and &lt;code dir=&quot;auto&quot;&gt;async&lt;/code&gt;/&lt;code dir=&quot;auto&quot;&gt;await&lt;/code&gt;, all compiling to native object files. We also needed it to be readable. Research-grade compilers are often dense monoliths. We opted for a modular design built on interning and arena allocation, borrowing ideas from &lt;code dir=&quot;auto&quot;&gt;rustc&lt;/code&gt; but writing everything from scratch.&lt;/p&gt;
&lt;div&gt;&lt;h2 id=&quot;the-architecture&quot;&gt;The Architecture&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;The pipeline is split into distinct, readable phases. The borrow checker (&lt;code dir=&quot;auto&quot;&gt;glyim-borrow&lt;/code&gt;) implements non-lexical lifetimes with Polonius-style region inference and two-phase borrows. The type inference crate uses unification variables with occurs-checks. Trait solving runs through a fulfillment context with obligation queues and HRTB support.&lt;/p&gt;
&lt;p&gt;There’s also a MIR interpreter used for &lt;code dir=&quot;auto&quot;&gt;const fn&lt;/code&gt; evaluation, and incremental compilation based on SHA-256 fingerprints of sources and build config.&lt;/p&gt;
&lt;div data-astro-cid-htlz5no4=&quot;&quot;&gt;&lt;article data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;svg data-astro-cid-r7gwjmbr=&quot;true&quot; aria-hidden=&quot;true&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; data-astro-cid-z7tqxewi=&quot;&quot;&gt;&lt;path d=&quot;M17 22H5a3 3 0 0 1-3-3V9a3 3 0 0 1 3-3h1a4 4 0 0 1 7.3-2.18c.448.64.692 1.4.7 2.18h3a1 1 0 0 1 1 1v3a4 4 0 0 1 2.18 7.3A3.86 3.86 0 0 1 18 18v3a1 1 0 0 1-1 1ZM5 8a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11v-3.18a1 1 0 0 1 1.33-.95 1.77 1.77 0 0 0 1.74-.23 2 2 0 0 0 .93-1.37 2 2 0 0 0-.48-1.59 1.89 1.89 0 0 0-2.17-.55 1 1 0 0 1-1.33-.95V8h-3.2a1 1 0 0 1-1-1.33 1.77 1.77 0 0 0-.23-1.74 1.939 1.939 0 0 0-3-.43A2 2 0 0 0 8 6c.002.23.046.456.13.67A1 1 0 0 1 7.18 8H5Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;span data-astro-cid-r7gwjmbr=&quot;&quot;&gt;Lexing to MIR&lt;/span&gt;&lt;/p&gt;&lt;div data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p&gt;A strict pipeline of AST, HIR, THIR, and MIR. Every phase is isolated so you can study one without getting lost in the others.&lt;/p&gt;&lt;/div&gt;&lt;/article&gt;&lt;article data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;svg data-astro-cid-r7gwjmbr=&quot;true&quot; aria-hidden=&quot;true&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; data-astro-cid-z7tqxewi=&quot;&quot;&gt;&lt;path d=&quot;M18.71 7.21a1 1 0 0 0-1.42 0l-7.45 7.46-3.13-3.14A1.02 1.02 0 1 0 5.29 13l3.84 3.84a1.001 1.001 0 0 0 1.42 0l8.16-8.16a1 1 0 0 0 0-1.47Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;span data-astro-cid-r7gwjmbr=&quot;&quot;&gt;Borrow Checker&lt;/span&gt;&lt;/p&gt;&lt;div data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p&gt;&lt;code dir=&quot;auto&quot;&gt;glyim-borrow&lt;/code&gt; handles non-lexical lifetimes, Polonius-style region inference, and two-phase borrows.&lt;/p&gt;&lt;/div&gt;&lt;/article&gt;&lt;article data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;svg data-astro-cid-r7gwjmbr=&quot;true&quot; aria-hidden=&quot;true&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; data-astro-cid-z7tqxewi=&quot;&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M1.44 8.855v-.001l3.527-3.516c.34-.344.802-.541 1.285-.548h6.649l.947-.947c3.07-3.07 6.207-3.072 7.62-2.868a1.821 1.821 0 0 1 1.557 1.557c.204 1.413.203 4.55-2.868 7.62l-.946.946v6.649a1.845 1.845 0 0 1-.549 1.286l-3.516 3.528a1.844 1.844 0 0 1-3.11-.944l-.858-4.275-4.52-4.52-2.31-.463-1.964-.394A1.847 1.847 0 0 1 .98 10.693a1.843 1.843 0 0 1 .46-1.838Zm5.379 2.017-3.873-.776L6.32 6.733h4.638l-4.14 4.14Zm8.403-5.655c2.459-2.46 4.856-2.463 5.89-2.33.134 1.035.13 3.432-2.329 5.891l-6.71 6.71-3.561-3.56 6.71-6.711Zm-1.318 15.837-.776-3.873 4.14-4.14v4.639l-3.364 3.374Z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M9.318 18.345a.972.972 0 0 0-1.86-.561c-.482 1.435-1.687 2.204-2.934 2.619a8.22 8.22 0 0 1-1.23.302c.062-.365.157-.79.303-1.229.415-1.247 1.184-2.452 2.62-2.935a.971.971 0 1 0-.62-1.842c-.12.04-.236.084-.35.13-2.02.828-3.012 2.588-3.493 4.033a10.383 10.383 0 0 0-.51 2.845l-.001.016v.063c0 .536.434.972.97.972H2.24a7.21 7.21 0 0 0 .878-.065c.527-.063 1.248-.19 2.02-.447 1.445-.48 3.205-1.472 4.033-3.494a5.828 5.828 0 0 0 .147-.407Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;span data-astro-cid-r7gwjmbr=&quot;&quot;&gt;LLVM Backend&lt;/span&gt;&lt;/p&gt;&lt;div data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p&gt;Using &lt;code dir=&quot;auto&quot;&gt;inkwell&lt;/code&gt;, we emit real object files with ABI lowering, debug info, and exception handling.&lt;/p&gt;&lt;/div&gt;&lt;/article&gt;&lt;article data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;svg data-astro-cid-r7gwjmbr=&quot;true&quot; aria-hidden=&quot;true&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; data-astro-cid-z7tqxewi=&quot;&quot;&gt;&lt;path d=&quot;M21 14h-1V7a3 3 0 0 0-3-3H7a3 3 0 0 0-3 3v7H3a1 1 0 0 0-1 1v2a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-2a1 1 0 0 0-1-1ZM6 7a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v7H6V7Zm14 10a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-1h16v1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;span data-astro-cid-r7gwjmbr=&quot;&quot;&gt;Bytecode VM&lt;/span&gt;&lt;/p&gt;&lt;div data-astro-cid-r7gwjmbr=&quot;&quot;&gt;&lt;p&gt;A compact stack machine verified by its own VM, letting you run Glyim code without a linker or embedding LLVM.&lt;/p&gt;&lt;/div&gt;&lt;/article&gt;&lt;/div&gt;
&lt;div&gt;&lt;h2 id=&quot;two-backends-one-pipeline&quot;&gt;Two Backends, One Pipeline&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;We built two backends for two different use cases.&lt;/p&gt;
&lt;p&gt;The primary LLVM backend (powered by &lt;code dir=&quot;auto&quot;&gt;inkwell&lt;/code&gt;) produces production-ready object files. The bytecode backend is a compact stack machine verified by its own VM. It lets you run Glyim code without a linker, which is useful for CI testing, embedding, or environments where shipping a full LLVM toolchain is overkill. You switch between them with a simple &lt;code dir=&quot;auto&quot;&gt;--backend&lt;/code&gt; flag.&lt;/p&gt;
&lt;div&gt;&lt;h2 id=&quot;gsx-a-first-class-view-syntax&quot;&gt;GSX: A First-Class View Syntax&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;We didn’t want the language to be purely for CLI tools. We added GSX: typed, host-agnostic view elements with their own compiler stage and an SSR emitter. View elements are first-class citizens in the AST, handled entirely by the compiler rather than a third-party macro. If you’re curious, the design docs in &lt;code dir=&quot;auto&quot;&gt;docs/design/GSX-in-Glyim.md&lt;/code&gt; go into the details.&lt;/p&gt;
&lt;div&gt;&lt;h2 id=&quot;the-build-tool-glyip&quot;&gt;The Build Tool: glyip&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;Because we were building a language, we needed a package manager. &lt;code dir=&quot;auto&quot;&gt;glyip&lt;/code&gt; uses a greedy breadth-first resolver with SemVer 2.0 matching, git and path dependencies, and lockfiles.&lt;/p&gt;
&lt;aside aria-label=&quot;The Trade-off&quot;&gt;&lt;p aria-hidden=&quot;true&quot;&gt;The Trade-off&lt;/p&gt;&lt;div&gt;&lt;p&gt;&lt;code dir=&quot;auto&quot;&gt;glyip&lt;/code&gt; doesn’t backtrack. A diamond dependency with incompatible versions is a hard error rather than a Cargo-style search. We chose this to keep the resolver predictable and fast, but it’s a constraint you feel in large graphs.&lt;/p&gt;&lt;/div&gt;&lt;/aside&gt;
&lt;div&gt;&lt;h2 id=&quot;what-it-cost&quot;&gt;What it cost&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;Building a compiler this way is not cheap. The modularity means more boilerplate for passing context between crates. The two backends mean every new language feature has to be implemented twice: once for MIR-to-LLVM and once for MIR-to-bytecode.&lt;/p&gt;
&lt;p&gt;We also have gaps. We track them in a readiness ledger—a set of CLI commands that record unwitnessed gaps, attach witness fixtures, and fail CI if something claims a witness that no longer exists. Currently, &lt;code dir=&quot;auto&quot;&gt;--lto fat&lt;/code&gt; errors cleanly because multi-CGU support isn’t implemented yet.&lt;/p&gt;
&lt;div&gt;&lt;h2 id=&quot;getting-started&quot;&gt;Getting started&lt;/h2&gt;&lt;/div&gt;
&lt;p&gt;If you want to build it, you’ll need LLVM 23 and a recent Rust toolchain.&lt;/p&gt;
&lt;div&gt;&lt;figure&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;cargo build --release&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;glyip new hello&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/div&gt;
&lt;p&gt;The code is readable. The gaps are written down. You can take it from here.&lt;/p&gt;</content:encoded></item></channel></rss>