Rust Sydney

rust-lang.org

huonw.github.io/rust-sydney-feb15

Hi

I'm Huon Wilson, long-time Rust contributor: wrote a patch, got hooked... Somehow now organising a meetup.

Preliminaries – Thanks

Preliminaries

Conduct of conduct, rust-lang.org/conduct.html. Summary:

Background

Open source (github.com/rust-lang/rust) programming language. Originally a personal project of Graydon Hoare, adopted by Mozilla Research in 2009.

1.0.0-alpha released a month ago, full stable release soon!

Rust's Aims

A haiku:

a systems language
pursuing the trifecta
safe, concurrent, fast

@lindsey

"Systems language"

Control is critical, overhead minimal.

No garbage collection, no "runtime", use the OS directly where possible... write the OS too.

farcaller on /r/rust

Safe

Memory safety is a priority, avoid GC with powerful static analysis:

Compiler uses annotations on pointers (etc.) to ensure they're always valid.

Safe – lifetimes

fn get_ten<'a>(map: &'a HashMap<i32, String>) -> &'a String {
    let val = &map[10];

    val
}

Concurrent

Rust provides tools to handle shared state and message passing safely, e.g.

No data races: locking/atomicity enforced when required.

Concurrent

Possible to implement a general parallel_map in safe code (in the near future: RFC 458), e.g. usable like:

// Eight integers on the stack
let mut stack_buffer = [0; 8];

// add one to each, in parallel
parallel_map(stack_buffer.iter_mut(), |item| {
    // item is a pointer into the main thread's stack
    *item += 1
});

println!("{:?}", &stack_buffer[]); // [1, 1, ..., 1];

Lifetimes, and the Send & Sync traits allow the compiler to guarantee safety.

Fast

Few runtime language features to stand in the way of the compiler. Standard libraries abstractions try to optimise well.

Benchmarks game, x86 one core

Fast

"Functional programming" iterators feel high-level:

pub fn sum(x: &[i32]) -> i32 {
    x.iter().fold(0, |a, b| a + *b)
}

Vectorised by LLVM! (16 i32s per iteration.)

.LBB0_4:
    vpaddd  -48(%rdx), %xmm0, %xmm0
    vpaddd  -32(%rdx), %xmm1, %xmm1
    vpaddd  -16(%rdx), %xmm2, %xmm2
    vpaddd  (%rdx), %xmm3, %xmm3
    addq    $64, %rdx
    addq    $-16, %rdi
    jne .LBB0_4

Projects