Memory mapping a file for reading sounds nice: turn inconvenient read calls and manual buffering into just simple indexing of a memory… but it does blocking IO under the hood, turn a &[u8] byte arrays into an async hazard and making “concurrent” async code actually run sequentially! Code affected likely runs slower, underutilises machine...
GitHub offers permalinks to versions of files and lines, within a repository. They’re easy to create (y keyboard shortcut) and have some nifty affordances like displaying a preview, plus they don’t become invalid as code changes. Use them! The permalinks use the commit hash of a particular version of the file, and thus the contents never changes,...
Encoding data in decimal requires many more characters than the same data encoded in base64—06513249 vs YWJj—but using decimal is better when stored in a QR code. The magic of QR modes means all those extra digits are stored efficiently, almost as though there was no encoding at all. Decimal encoding makes for QR codes that store more data, or...
Governments here in Australia have been telling us to keep distance from each other. Surprisingly, the same government has simultaneously put out posters that required people to get close, unnecessarily. They contain QR codes for contact-tracing check-ins that are small and dense, meaning they’re hard to scan. How could they be better? Here’s...
Error correction sounds good. It means fewer errors, right? When it comes to QR codes, that’ll mean easier scanning for people, surely? It seems like that’s not the whole story. I wondered about this, and couldn’t find an answer, so I did some exploration, and found there’s two factors in tension: the error correction on one hand, and the...
Taking shortcuts? Leaving edge-cases unconsidered and unhandled? Is this engineering?! My approach to programming and software engineering has been shaped by years of building open source compilers and libraries, where those edge cases matter, reliability is crucial and flexibility is important. It’s been a breath of fresh air to take a step back...
It’s glorious to work on one task at a time, to be able to take it from start to finish completely, and then move onto the next one. Sounds great, but reality is messier than that and context switches are common. Doing so can be annoying and inefficient, but not switching means tasks and colleagues are delayed. I combine git worktrees and pyenv...
The primitive integer types supported by CPUs are finite approximations to the infinite set of integers we’re all used to. This approximation breaks down and some computations will give results that don’t match real integers, like 255_u8 + 1 == 0. Often, this mismatch is something the programmer didn’t think about, and thus can easily result in...
Memory unsafety and memory leaks are arguably the two categories of bugs that have received the most attention for prevention and mitigation. As their names suggest, they are in the same part of “bug space”, however they are in some ways diametric opposites, and solving one does not solve the other. The widespread use of memory-safe managed...
Imagine being able to step forward and backwards as code runs in your debugger. Imagine being able to do an test run multiple times with exactly the same sequence of instructions and values, right down to memory addresses and IO. Imagine being able to run an executable thousands of times and then do all that in the one execution that triggers the...
I recently released version 0.3 of my simple_parallel crate, which builds on Aaron Turon’s crossbeam to resolve the stability and safety difficulties: the crate now works with Rust 1.3.0 stable, and offers safe data-parallel for loops and maps. I still don’t recommend it for general use, but I think it’s a neat demonstration of what Rust’s type...
A new scheme for SIMD in Rust is available in the latest nightly compilers, fresh off the builders (get it while it’s hot!). For the last two months, I’ve been interning at Mozilla Research, working on improving the state of SIMD parallelism in Rust: exposing more CPU instructions in the compiler, and an in-progress library that provides a...
I’m currently in San Francisco doing an internship at Mozilla Research, working on creating functionality for SIMD in the Rust programming language. (This post is designed to describe what I’m doing for people not necessarily familiar with programming or SIMD.) What is SIMD? SIMD stands for “Single Instruction, Multiple Data”, and refers to...
I just pushed travis-cargo version 0.1.3, which adds a --no-sudo command to the coveralls and coverage subcommands to allow recording/uploading test coverage without needing sudo. This is based0 on @seanmonstar’s investigation/implementation of sudo-less kcov. It works because Travis’s apt addon has whitelisted everything necessary....
Over the past few weeks I’ve been working on improving my slow_primes library, culminating in needing rename and the 0.2 release of primal, a Rust crate for computing properties of prime numbers with state-of-the-art algorithms, while still maintaining an idiomatic and easy-to-use interface. primal My computer takes a quarter of a second and...
Rust has some powerful tricks to model properties of aggregate types via unsafe traits with default and negative implementations. These features motivated by offering flexible concurrency/parallelism, and allow powerful closure-based APIs without losing any thread-safety (or memory-safety) guarantees at all. I realised that my recent post on the...
Rust 1.0 was made with0… .number { text-align: right; } table { max-width: 600px; border-spacing: 0 0.4em; border-collapse: separate; } td { vertical-align: top; } 1stable release 2‘Rust’ compilers 3bots on Github 4years of bootstrapping (7b95b5c is the innocuous commit of the first snapshot) 5years of git ~9years total 120.x releases ~28launch...
Have you ever used an iterator adapter in Rust? Called a method on Option? Spawned a thread? You’ve almost certainly used a closure. The design in Rust may seem a little complicated, but it slides right into Rust’s normal ownership model so let’s reinvent it from scratch. The new design was introduced in RFC 114, moving Rust to a model for...
The concept of object safety in Rust was recently refined to be more flexible in an important way: the checks can be disabled for specific methods by using where clauses to restrict them to only work when Self: Sized. This post is a rather belated fourth entry in my series on trait objects and object safety: Peeking inside Trait Objects, The...
After announcing travis-cargo a few days ago in Helping Travis catch the rustc train, I got some great hints/contributions from Jan Segre and had a fun little time automating code coverage collection via coveralls.io. Unfortunately, this is a breaking change for existing users of travis-cargo, but the migration is easy. (If you’re wondering what...
I’ve been putting off configuring my continuous integration settings to match the Rust train model: it involves non-trivial branching on the configuration, and duplicating that over a pile of repos is not something I looked forward to. So, instead, I wrote travis-cargo to make things easier. Branching on configuration? One approach to developing...
I’ve been having a lot of fun recently solving “little” problems in Rust. I have a long term project to make something for displaying my (GPS-tagged) photos nicely and, along the way, I’ve discovered and filled in a few gaps by creating focused crates for small tasks. My travels over the last few years, as...
Rust is a reasonably large project: the compiler and standard libraries are over 350kloc, built across nearly 40000 commits by the hands of around 900 contributors. Not only that: there are more than 30 other repositories in the rust-lang GitHub organisation that shouldn’t fall by the wayside, and, for rust-lang/rust alone, there are often more...
If you’ve been in the #rust-internals IRC channel recently, you may’ve caught a madman raving about how much they like Rust: 1 2 3 4 5 ... [15:50:03] I love this language ... [20:02:07] did you know: Rust is awesome. ... I was (and still am) losing my mind over how well Sync and Send interact with everything, especially now that the...
Rust Sydney had its first event last Monday! The first Rust gathering I know of in Sydney, in Australia, or in the whole southern hemisphere. I had fun meeting all sorts of people interested in Rust: some who’d dived in deep already, some who’d only recently started playing with it, and some who’d been following for a while but had unfortunately...
A trait object in Rust0 can only be constructed out of traits that satisfy certain restrictions, which are collectively called “object safety”. This object safety can appear to be a needless restriction at first, I’ll try to give a deeper understanding into why it exists and related compiler behaviour. This is the second (and a half) in a short...
An important piece in my story about trait objects in Rust0 is the Sized trait, so I’m slotting in this short post between my discussion of low-level details and the post on “object safety”. Other posts in this series on trait objects Peeking inside Trait Objects The Sized Trait Object Safety Where Self Meets Sized: Revisting...
One of the most powerful parts of the Rust programming language0 is the trait system. They form the basis of the generic system and polymorphic functions and types. There’s an interesting use of traits, as so-called “trait objects”, that allows for dynamic polymorphism and heterogeneous uses of types, which I’m going to look at in more detail...
Rust is a systems programming language that comes with an awesome package manager Cargo, which hooks into the crates.io registry as one of its possible sources of packages. The packages can have dependency relationships between each other, making the database into a natural directed graph. Rust as we have it today is still relatively new, Cargo...
Rust is an in-development0 systems programming language with a strong focus on no-overhead memory safety. This is achieved through a powerful type system (with similarities to Haskell), and careful tracking of ownership and pointers, guaranteeing safety. However, this is too restrictive for a low-level systems language, an escape hatch is...
After posting a Rust translation of some k-nearest neighbour code, I got a few comments asking “how would you handle errors if you wanted to?”. This is the perfect chance to briefly demonstrate a few idioms. See my previous post for context and the original code; like with the code in that post, this code compiles with rustc 0.11.0-pre-nightly...
In my voyages around the internet, I came across a pair of blog posts which compare the implementation of a k-nearest neighbour (k-NN) classifier in F# and OCaml. I couldn’t resist writing the code into Rust to see how it fared. Rust is a memory-safe systems language under heavy development; this code compiles with the latest nightly (as of...