An OpenQASM 3.0 language server and runtime, written in Rust.
qc = QuantumCircuit(2) qc.h(0) qc.cx(0, 5) # ← no qubit 5 # discovered at runtime, # somewhere in a stack trace
Parses, type-checks and runs a .qasm file. Prints what the program measured.
The same front end, wired into your editor instead of a terminal.
~10,200 lines of Rust. Lexer, parser, type checker and interpreter all hand-written — no parser generator, no Python anywhere.
That last one is why this is written in Rust and not Python. A 24-qubit, 47-gate program runs in 1.3 seconds, using 2.8 cores' worth of CPU.
OPENQASM 3.0; qubit[2] q; output bit[2] result; h q[0]; cx q[0], q[1]; result[0] = measure q[0]; result[1] = measure q[1];
Random every time — but the two bits never disagree.
You will not see 01 or 10. Not in eight runs, not in eight million. Nobody coded that rule — it is simply what entanglement is.
Stages 01–03 are exactly what the language server runs. Diagnostics aren't a separate linter — they're a by-product of compiling.
TypeDef(Qubit) @ 0:0 len 5 Symbol(LBracket) @ 0:5 len 1 Literal(Integer(2)) @ 0:6 len 1 Symbol(RBracket) @ 0:7 len 1 Identifier("q") @ 0:9 len 1 Symbol(Semicolon) @ 0:10 len 1 …
Notice the @ line:col len on every single token. That's the span — and it is the reason every later stage can point back at your source.
Identifier("h") Identifier("q") Symbol(LBracket) Literal(Integer(0)) Symbol(RBracket) Symbol(Semicolon)
GateCall { name: "h", modifiers: [], params: [], qubits: [ IndexedIdent { name: "q", indices: [ Expr(Int(0)) ], span: Span { line: 1, col: 2 } } ] }
Recursive descent, written by hand. On a syntax error it doesn't stop — it skips to the next statement and keeps building, so an editor always has a tree to work with.
GateCall { name, modifiers, params, qubits } ClassicalDecl { ty, name, init } Assign { target, op, value } If { cond, then, else_ } For { var, ty, iter, body } Return(Option<Expr>), Break, Continue, … 24 variants
No value. You run it for its effect.
Int(i64), Float(f64), Bool(bool), Ident(String), IndexedIdent(…), Binary { op, lhs, rhs } Call { name, args } Cast { ty, expr } Measure(GateOperand), … 15 variants
Evaluates to something, and nests inside other expressions.
h q[0]; // statement — flips amplitudes, gives nothing back result[0] = measure q[0]; // measure is an expression — it has a value
The bridge between them is ExpressionStatement(Expr) — an expression evaluated purely for its side effect, with the value thrown away.
q : qubit // declared 3:6 x : int[32] // declaring…
A qubit is not a number, and no coercion rule turns one into the other. Rejected before anything runs.
The same pass does inference, bit widths, implicit coercions and gate arity — and records every symbol's definition and uses, which is the data rename and find-references query later.
GateCall { name: "h", modifiers: [], params: [], qubits: [ q[0] ] }
A name, some modifiers, some parameters, and some operands. The interpreter has to turn all four into something the simulator can apply, plus a list of qubit indices.
01 // params are expressions, not numbers params.iter().map(evaluate_expression) → Vec<f64> = [] 02 // q[0] is a name — which qubit is it? self.resolve_qubits(q) → Vec<Vec<usize>> = [[0]] 03 // what is "h"? self.functions.get("h") → a gate defined in stdgates.inc 04 // turn it into numbers self.resolve_gate(name, &func, ¶ms) → ResolvedGate::SingleQubit(Matrix2)
Step 04 is the odd one. h has no implementation in the Rust at all. To get one, the interpreter runs the gate's own QASM body and records what it does — then caches the result, keyed by name and parameters.
GateCall { name: "h", qubits: [ q[0] ] } amplitudes: Vec<Complex<f64>> // one per slot
Stage 04 handed over what h does and which qubit — qubit 0.
2 qubits → 2² = 4 slots 24 qubits → 2²⁴ = 16,777,216
Every qubit you add doubles the array — the whole difficulty of simulating quantum computers, in one line.
q[0] is the right-hand bit, so h pairs up the answers that differ only there. It never mixes 00 with 10.
slot 0 started at 1; h split it evenly → 0.707 each chance = the number squared → 0.707 × 0.707 = 0.5
The two pairs never touch, so both updates run at once — which is how a gate over 16.7 million slots still finishes fast.
Same shape every time, because they all come from the same spans. Only the third one needs the program to actually run — the goal is to keep moving errors leftward.
No build. No run. No queue. The squiggle appears while you type.
It is the exact same type checker from stage 03 — the only difference is that the diagnostic gets serialized to JSON and sent to the editor instead of printed to a terminal.
Which raises the obvious question: how does an editor that has never heard of OpenQASM know how to draw that?
Your editor launches it as a subprocess and talks to it over stdin and stdout in JSON. The editor knows nothing about the language; the server knows nothing about the editor.
Before this existed, every editor needed its own plugin for every language — ten languages across five editors meant fifty half-finished implementations. Now it's one server, and every editor gets it.
Every one of those is a query against data stages 01–03 already built. Hover reads the type checker's table. Rename reads the reference registry.
Built on tower-lsp and tokio; open files live in a DashMap and every keystroke re-runs the front end.
QASM Language Support — finds qasm-lsp and launches it for you.
github.com/wiji1/QuantumVM-VSCode
Same binary, same features, wired into the IntelliJ platform.
github.com/wiji1/QuantumVM-Jetbrains
Both plugins are thin — they start a process and forward messages. Everything they can do, any LSP-capable editor gets for free.
Each case is a real .qasm program plus the assertion that pins its result. Most of them have nothing to do with quantum at all.
output int[32] sum; sum = 0; for int[8] i in [0:3] { for int[8] j in [0:2] { sum += 1; } }
assert_int_output(&r, "sum", 12);
Ranges are inclusive, so that's 4 × 3, not 3 × 3. Exactly the off-by-one a test pins and a comment doesn't.
output int[32] result1; output int[32] result2; int[32] a = -7; int[32] b = 3; result1 = a % b; result2 = (-10) % 4;
assert_int_output(&r, "result1", -1); assert_int_output(&r, "result2", -2);
Languages disagree here — Python says 2, C says -1. The test is where that choice is written down.
const int[32] N = 10; N = 20; // Error: Cannot assign // to constant: N
assert_type_error(&r);
Plenty of cases assert the program is rejected. A type checker that accepts everything passes every happy-path test.
111 cases across four suites — classical ops, control flow, quantum ops, error handling — in under a tenth of a second. Every push runs them, plus clippy -D warnings.
Tag a commit and it builds five target triples, cuts a GitHub release, and publishes a Homebrew tap — plus shell and PowerShell installers.
Tests and clippy -D warnings on every PR — lints are errors, not suggestions. Release builds verified on all three OSes.
Maybe 5% of the work, and the reason anyone other than me can actually run it.
full simulation · custom gate definitions · gate modifiers
loops, switch, break/continue · functions · arrays & slicing
const & type coercion · input/output declarations
a --shots flag with histogram output
noise models · circuit visualization
incremental re-parsing in the language server