Skip to content

Mimic 0.4.1-preview.1

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 21 Nov 03:40
· 134 commits to main since this release
f68d90e

A preview of the next version: not a stable release. Install it with mimic upgrade --preview.

Step 0.4.1, the Mimic IR, so far (0.4.1-preview.1): its first part (functions of plain numbers through a typed intermediate representation, off by default), a security fix for the HTTP client's redirects, and the slowest benchmarks of 0.4.0 traced and most of them made several times faster without a change to the programs: tuples of numbers and short lists stay in registers, lists grown in a loop and lists from flatten stay typed, let lambdas and count's lambda are compiled as functions, gather/trail with a lambda are typed loops, and debug builds change lists in place. fnv1a, crc32, adler32, pagerank, topo and siphash 7–25× faster, sha256 13×, diff 7×, utf8 5.6×; no benchmark slower on Linux, macOS or Windows.

Added

  • The first step of the Mimic IR (docs/design/ir.md): functions of plain numbers and truth values can be compiled through a typed intermediate representation, with the same results. Off by default while it grows: MIMIC_IR=1 turns it on, MIMIC_IR=print shows each function's IR.

Security

  • The HTTP client keeps credentials to the server they were meant for. A redirect from https to http is refused with an Err (the request would go on unencrypted), and a redirect to another server (a different scheme, host or port) leaves Authorization, Cookie and Proxy-Authorization behind; other headers still go along. Before, http::request sent them on to wherever it was redirected.

Changed

  • Lists grown in a loop stay typed: push of a number onto a list of that kind of number gives such a list, a loop whose list state changes length (⍳ 16 grown to 64 by push) keeps it typed, and a tuple holding short lists of known length ((i, [8 words])) stays in registers. sha256 13× faster (4.7 s → 0.35 s).
  • A function declared -> [i64] (or [f64]) returns a typed list: a body joining [] with [x] gave a list of unknown type, which the declaration only checked, so the caller worked on boxed values. The result is now made typed as it is returned. diff 7× faster (3.8 s → 0.54 s). A function that returns something else under such a declaration now stops at its return instead of later.
  • flatten(xs ¨ (x => …)) of lists of numbers is typed: its result had no known type, so everything after it ran on the generic path; when the lambda gives a list of numbers, the result is that list of numbers. utf8 5.6× faster (4.0 s → 0.71 s).
  • gather and trail with a lambda over numbers are a typed loop: ways ▷ gather((x, y) => (x + y) % p) sent every pair through the runtime boxed; a lambda that gives back the same kind of number as the list's is now typed and folded in a loop. 3,000,000 numbers: 2.35 s → 0.08 s. A lambda giving another type keeps the general path.
  • count(xs, x => …) is typed and fused: the prelude's count called its lambda as a function value for every element; given a lambda, the call is now written out as its body, +/ (xs ¨ (x => …)). maze 5× and markdown 1.2× faster.
  • A list of literals is built once: ["M" "CM" "D" …] or [1 2 3 …] in a function was built again on every call; it is now built the first time and shared after (a change to it copies, as to any list held twice). roman 2.1× faster (3.2 s → 1.5 s of CPU).
  • A lambda kept in a let and only called is a function: let at = (x, y) => table[…], then at(a, b), called the lambda as a function value, every argument boxed; it now becomes a hidden function taking what it captures as arguments, specialised like any function. 8 million calls in a map: 5.8 s → 0.03 s. A lambda used as a value, or one that assigns, returns or sees a variable that changes later, stays as it was.
  • Tuples of numbers stay in registers: a settle or evolve over a tuple state (a sequential pass, a hash, a binary search) allocated and freed a tuple on every step; a tuple of numbers and truth values is now kept in registers, as records of numbers are. crc32 6.8 s → 0.79 s, fnv1a 4.5 s → 0.62 s, topo 5.1 s → 0.79 s (one core, macOS).
  • Small programs build faster: a one-line program in about 0.45 s instead of 0.6 s on macOS. The linker runs inside mimic instead of as a second process (which took ~0.1 s just to start), and the macOS SDK and OS version are read from their files instead of asking xcrun and sw_vers on every build (~70 ms). MIMIC_DEBUG_PHASES=1 also times code generation, the runtime and linking.

Fixed

  • push onto a short list no longer reallocates every time: a list that had grown past its first block kept asking realloc for more room on each push, though it had plenty. levenshtein (rows built a number at a time) runs 2.5× faster on macOS, more on Windows.
  • MIMIC_IR and MIMIC_DEBUG_DISABLE are part of the build cache's key: a program built with one of them could be reused by a build without it (and the other way round).
  • A redirect to //host/path goes to that host with the request's scheme; it was taken as a path on the same server. A Location too long to follow is an Err instead of a cut-short URL.
  • Debug builds update records in place, as optimised ones do: { s with f: put(s.f, …) } copied the whole list on every step in a debug build (functions never took over their parameters there). A debug sieve of 200,000 took over ten minutes; now 1.8 s.
  • A program with only small maps no longer opens Metal on macOS: the GPU was asked before the map's size was checked, and asking opens Metal (~0.13 s). A program over 1,000 numbers ran in 0.14 s; now 0.01 s. Large maps go to the GPU as before.

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.1-preview.1-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.1-preview.1-macos-arm64.tar.gz ./install.sh The Xcode Command Line Tools (xcode-select --install), for the macOS SDK.
Linux x86_64 mimic-0.4.1-preview.1-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.