Last updated: 2026-11-15

U
Undergraduate level
EPH
Ephemeral / Tooling โ€” Knowledge that evolves in months to a year โ€” check for updates

PatLang 2.0: What Changed Since v1

For new readers

PatLang 2.0 is a new compiler and a new runtime, written in PatLang to a written specification, together with an interpreter that runs on the same runtime. Most programs written for v1 still run, but several rules a v1 program could lean on have changed: new returns an object, a call must pass exactly the arguments a function takes, global variables are gone, and a program's last value is no longer printed. This page lists every change a programmer will meet, then points to the pages in this group that cover each area in depth.

v1 here means the state of the repository at the pre-v2 tag, of 2 November 2026: the Rust-hosted pat interpreter, the self-hosted patc1 compiler and its x64 runtime, and WebAssembly built through generated Rust and rustc. v2 replaces all three. Its compiler is self_hosting/v2/compile.patlang, built as v2.exe; its interpreter is self_hosting/v2/interp.patlang, built as v2_interp.exe; and both run the runtime in self_hosting/v2/runtime/, which is ordinary PatLang compiled by the same stages as any program. No step of building, testing or running PatLang starts Rust any more.the compiler is now written in PatLang itself

At a glance Ephemeral / ToolingKnowledge that evolves in months to a year โ€” check for updates

Areav1 (pre-v2)v2
Interpreterpat --ir-run, written in Rustv2_interp.exe, written in PatLang, built by v2
Native compilerpatc1 --x64v2.exe SRC OUT.exe, one cached job per function, parallel workers
WebAssemblyGenerated Rust, then rustcv2.exe SRC OUT.wasm --wasm, its own encoder
BootstrapA Rust build of patA Python reader building the compiler from its own IR
A valueOne word, type in the top 16 bits, 48-bit immediate integersTwo words, a type word and a full 64-bit data word
The rulesWhatever each engine didA specification both engines are tested against, scenario by scenario

That last row explains most of the others. v1 had three engines, and where they disagreed, the program's meaning depended on which one ran it. The interpreter and native code even disagreed about whether 247ย +ย 9 was an int or a bigint. v2 starts from docs/spec/values-and-memory.md, whose Part 1 states what a program can observe and binds both engines alike. Its executable form, spec_library/values_and_memory/, runs every scenario on the compiler and on the interpreter, and a separate feature checks that the two give the same output.

Changes that can break a v1 program Applied / MethodologicalKnowledge with a 5โ€“10 year half-life โ€” stable practice

Each of these came out of compiling the 418 programs that existed at the pre-v2 tag with v2 and deciding, case by case, which behaviour the language should keep.

ChangeWhat to do in v1 code
new("Widget", "w1") returns the object, whose class is Widget. In v1 it returned the name "w1".Hold the object. A string holding an object's name still reaches its fields, so s.field keeps working where s is a name.
new takes a class and an optional name, nothing more.Declare inheritance with class ... inherits ....
A call must pass exactly as many arguments as the function takes. v1 padded missing ones with unit and dropped extras.Fix the call. A wrong count to a named function is refused when compiling; to a closure, it stops the program as a failed precondition.
A last parameter named rest collects any further arguments as a list.Rename a parameter called rest that was meant as an ordinary one.
takes none declares no parameters. In v1 it declared a parameter named none, which the padding hid.Nothing, unless a body read none.
set_global, get_global, set_var and get("__vars", ...) are gone.Pass state as a parameter, or hold it in an explicit context object (lib/context.patlang).
A program's last top-level value is not printed. pat printed it.Print what you want printed.
Logic facts are nested only: ["has_wood", ["yard"]].Rewrite flat facts such as ["has_wood", "yard"].
A bare name nothing defines is an error.Quote it, or define it.
chr of anything but an int, and band and its relatives on a float, stop the program.Convert first. v1 truncated silently.
bnot n gives the bitwise complement, -1ย -ย n.An early v2 build gave a bool; v1 and v2 now agree.
Strings count characters, not bytes, in .length, indexing, substr and char_code.Use byte_length where bytes were meant.
world_run, goal, plan_numeric, fluent_set, class_def and the functions tied to the Rust engine (run_ir, compile_ir, rustc_build* and others) are not in v2.Use worlds for world_run. A call to any of the others stops the program when reached, with host fn 'NAME' not found.

v1 behaviours v2 keeps on purpose Applied / MethodologicalKnowledge with a 5โ€“10 year half-life โ€” stable practice

Some v1 behaviours looked like accidents of one engine and were written into the specification instead of being dropped:

  • A function that ends without return gives the value of its last statement.
  • exec_capture gives what a command wrote to both standard output and standard error.
  • A file reached by several includes is included once, before the files that include it. The old compiler spliced text every time, so a file included twice ran its top-level statements twice.
  • The name unit is the unit value unless the program binds it.
  • A program may define a function with a name the runtime already has. Its own calls reach its definition, and the runtime keeps using its own.

New in the language Applied / MethodologicalKnowledge with a 5โ€“10 year half-life โ€” stable practice

FeatureWhere it is covered
Every value is an object of a class, and answers methods: 3.to_s, [1, 2].length.Values, objects and operator events
Operators are methods of the left operand's class, and a method can declare the events it raises. int's + raises added and added_to.Values, objects and operator events
Bool arrays, and a stated split between values and objects with identity.Values, objects and operator events
Arity checking, rest, and closures that know their own parameter count.Functions, calls and parameters
Intervals, max, min, and a precise integer rule at the 64-bit boundary.Numbers in PatLang 2.0
Integers modulo n, a built-in class, with constant-time arithmetic.Numbers and constant-time arithmetic
Rule stores, rule ... in NAME, goals from NAME, and using kb as logic do ... end blocks.Rule stores, using blocks and the planner
An A* planner that always finds a cheapest plan when one exists.Rule stores, using blocks and the planner
Worlds: isolated program state, with stops that end a call and not the program, and step budgets.Worlds, fibers and threads
thread_spawn(closure, args...) passes arguments, and each fiber has its own list of running events.Worlds, fibers and threads
syntax definitions may stand anywhere a statement may, and AST.Name(args) builds nodes in any code.Dynamic syntax
sed, cpu_count, cpu_times, memory_status, exec_measured, exec_peak_memory, progress_report and progress_status.Functions, calls and parameters

New in the toolchain Applied / MethodologicalKnowledge with a 5โ€“10 year half-life โ€” stable practice

  • A guaranteed memory bound. No program frees memory, and a program whose live data is bounded runs in bounded memory however long it runs. Reference counting under five ownership rules does the freeing; see Inside a compiled program.
  • Contracts on the runtime. Every runtime function and every compiler stage states its contract with require and ensure, checked in every build.
  • Per-function caching. The compiler runs one job per function, keyed by the function's IR and its callees' ownership summaries. A second program reuses every runtime job, and editing one function's body rebuilds that function alone. The swarm compiler covers the design.
  • A written IR. --ir writes a program's whole IR as text, and a reader in Python with only its standard library builds the compiler from it. See The v2 IR and its readers.
  • A browser backend with threads. --wasm writes a module whose threads and fibres each run on a Web Worker over one shared memory.
  • A constant-time check. --constant-time builds nothing and reports every place where a program's running time can depend on a secret.
  • Gates that run what changed. The test gates record each suite's inputs and run only the stale units, in parallel within the cores and memory the machine can spare. See The v2 toolchain.

Speed against v1 Ephemeral / ToolingKnowledge that evolves in months to a year โ€” check for updates

Compiled v2 code is 17 to 21 times faster than pat on call-heavy and loop-heavy benchmarks. The v2 interpreter, which is itself compiled PatLang, runs about four to five times slower than pat on the same benchmarks, and faster on string appends:

Benchmarkpat (v1)v2 nativev2 interpreter
bench_fib1,964 ms115 ms8.9 s
bench_manycalls2,832 ms145 ms14.6 s
bench_sumloop3,325 ms155 ms15.4 s
bench_strconcat1,951 ms0.18 s2.8 s

The pat column and the first three native figures come from the survey of 6 November 2026. The native bench_strconcat figure is from after the fix that stopped s = s + x copying the whole string, which took it from 266 seconds. The interpreter's figures are from a run on 14 November, after its last speed-up, in which pat took 2.1, 2.9, 3.4 and 6.9 seconds on the same four benchmarks.

Builds cost more.A warm build of a one-line program takes about 12 seconds, most of it linking the runtime's few hundred stored functions, against about 12 seconds for the old compiler cold. On large programs v2 pulls ahead, because a warm build reuses every unchanged function: the old compiler's warm builds were no faster than its cold ones.warm build caches unchanged function objects

The pages in this group Applied / MethodologicalKnowledge with a 5โ€“10 year half-life โ€” stable practice

PageCovers
Values, objects and operator eventsClasses on every value, methods, operators as methods, the events they raise, value and identity semantics, text, memory.
Functions, calls and parametersArity, rest, a function's value, includes, undeclared names, contexts in place of globals, how to group parameters.
Numbers in PatLang 2.0The integer rule, rationals, mathematical functions, intervals, integers modulo n.
Constant-time arithmeticWhy a modint's time depends on its modulus alone, how the check follows secrets, SHA-512, X25519 and Ed25519 in PatLang.
Rule stores, using blocks and the plannerStores as values, named stores, in and from, using blocks, the A* planner.
Worlds, fibers and threadsFibers, budgeted blocks, threads, worlds, stops and step budgets.
Inside a compiled programTwo-word values, heap blocks, calls, ownership, unwinding, the memory manager, contracts, the executable.
The v2 IR and its readersThe IR's text form and instructions, the Python reader, the WebAssembly form and host.
The v2 toolchainThe compiler's commands and stages, the cache, the interpreter, the debugger trace, the gates.

See also

Blocks, ownership and memory records the memory design review that decided to write v2. The swarm compiler explains the job graph v2's compiler is built on. Packages, resolution and trust covers the package layout and trust records that v2's cryptography was written for. Several older pages in this topic, such as the language reference and the standard library reference, describe v1; where they disagree with this group, this group describes the current language.

Graduate Attributes

Modelled on this page

  • Subject Specialist: Technical specifications are applied to resolve ambiguities between interpreter and compiler behaviour.
  • Researcher: Design decisions are justified by systematic testing of existing programs against new rules.
  • Critical Thinker: Performance metrics are presented with specific dates and conditions to allow accurate comparison.

University of Reading Graduate Attributes framework.