Skip to content

Mimic 0.4.2

Choose a tag to compare

@github-actions github-actions released this 23 Nov 23:53
· 79 commits to main since this release
c1ff440

Step 0.4.2, ownership by analysis: in the functions the Mimic IR compiles, a list or record is released right after its last use, handed over instead of shared, and changed in place wherever nothing else holds it, through helper calls, record updates and branches, in debug builds as in optimised ones. Text and functions that call several others now go through the IR too, numbers and literals that live for the whole run are never counted, and operators on values of unknown type no longer allocate their results. Reference-count operations over the corpus fell by 40% (937 million to 563 million, short of the halving the plan aimed at; what is left is mostly in code the IR does not cover yet). mimic check --copies lists the copies a program still makes and why: paths' step makes none; qoi's steps are still compiled by the old code generator (they wait for typed empty lists and tuples holding lists, 0.4.3–0.4.4). sudoku 1.9× faster, vm 1.7×, tokenize 1.5×, totient 1.3×, paths 1.27×, hull 1.2×, lz77 1.18× on this machine; the whole corpus on Linux, macOS and Windows is in BENCHMARK.md.

Added

  • mimic check --copies lists every copy of a list or record the program still makes, where, and why: a put, push or { … with … } on a value used again later (and at which line), read from outside a loop, or borrowed from the caller. Functions the compiler does not analyse yet are listed with the reason. --emit-json gives the same as JSON.

Changed

  • A step function takes its record state wherever it hands it on or updates it last: a record parameter read first (let p = ps[s.i], s.v[i]) and then passed to a function that changes it, or used as the base of a { … with … }, is now taken over, so the change is made in place instead of on a copy: look(look(s, 0), 1), { grow(t, at) with k: t.k + 1 }, let e = learn(d, c) after codes[d.i]. And a field changed in one branch and kept in the other (next: if d == 0 { push(k.next, w) } else { k.next }) is two updates, the one taken in place. These shapes took minutes in 0.4.0 (docs/gaps.md); the corpus already avoids them.
  • A list field changed under a let and stored back is changed in place: let table = put(s.table, h, x) then { s with table: table } copied the whole list (the record still held it when the put ran); the change now happens in the with, which takes the field out of the record, so it is made in place when nothing else holds them. The same for chains of put and push, and { s with out: concat(s.out, ys) } now appends in place in the functions the IR compiles. lz77 is 15% faster (its table of 65,536 entries was copied for every byte).
  • Values are released as soon as they are last used, and handed over instead of shared (docs/design/ownership.md): in the functions the IR covers, a list or record is freed right after its last use (not at the end of its block), given as it is to a function that takes it over, and stored into a record without a new reference. A field read borrows its record. Records on the heap, { r with … } and functions that take over a record argument now go through the IR; floyd is 1.26× faster.
  • put and push on a list of i64 change it in place when nothing else holds it: a list the function owns at its last use (let g = push(h, x), put(put(h, p, b), i, a)) is changed where it is, and { s with v: put(s.v, i, x) } stores the number in place without a call. A function whose list parameter is changed this way at its last use (a heap's sift-up up(put(put(h, p, b), i, a), p)), or handed on to one that is, now takes the list from its caller, so the change is in place there too. Before, a bare put always copied the list.
  • Releasing a number, true, false or a literal no longer calls the runtime: these values live for the whole run, and compiled code now skips them where it releases a value. They were half or more of all reference-count operations in vm, soundex and url; vm is about 4% faster.
  • Text, and functions that call several others, now go through the IR: functions that take or return strings, and blocks with more than one call (only blocks the compiler would actually run in parallel, or start as a task, stay on the old path), now get release-at-last-use and in-place updates. sudoku is 1.9× faster, paths 1.27×; put/push on a list a function only borrows copies it directly instead of taking a reference first. MIMIC_IR=why prints why a function stays on the old path.
  • Comparing or computing with two numbers of unknown type no longer allocates: an operator on two single values whose type the compiler does not know (op == 0 in an interpreter's loop) gave a new value every time; a truth value or an integer from such an operator, and from not, - and ∣ on one value, is now the runtime's own true/false or cached small integer. vm is 1.7× faster (8× fewer values freed), tokenize 1.5×, brainf 6% faster.

Install

Download the file for your system below and unpack it. Then run the install script inside: it copies mimic to ~/.mimic/bin, puts that folder on your PATH, and checks what your system needs.

System File Install Also needed
Windows x86_64 (10, 11) mimic-0.4.2-windows-x86_64.zip Double-click install.cmd Nothing: Windows programs are linked with the MinGW-w64 inside mimic.
macOS Apple silicon mimic-0.4.2-macos-arm64.tar.gz ./install.sh The Xcode Command Line Tools (xcode-select --install), for the macOS SDK.
Linux x86_64 mimic-0.4.2-linux-x86_64.tar.gz ./install.sh glibc 2.28 or newer (Ubuntu 20.04, Debian 10, RHEL 8 or later) and a C compiler (cc) to link native programs. --target x86_64-linux needs nothing else.

On Windows, if double-clicking install.cmd does nothing (some company PCs block scripts), open PowerShell in the unpacked folder and run:

powershell -NoProfile -ExecutionPolicy Bypass -File ".\install.ps1"

The script says if something is missing and how to install it. Open a new terminal afterwards so the new PATH applies.

Upgrading from an earlier Mimic: run the new install script the same way. It replaces the old mimic, clears the build cache the old version left in ~/.mimic/cache (it is rebuilt on first use), and keeps your projects and installed libraries. If another mimic comes first on your PATH, it says where, and offers to remove it.

  • macOS: the script clears the download quarantine. If you copy mimic by hand instead, run xattr -d com.apple.quarantine mimic once.
  • Windows: the script unblocks the downloaded files. SmartScreen may still ask the first time: "More info" → "Run anyway".
  • Uninstall: ./install.sh --uninstall, or install.cmd -Uninstall on Windows. Your projects are not touched.

First program

mimic create hello
cd hello
mimic run

mimic --help lists every command. SHA256SUMS has the checksum of each file.