Mehdi Akiki

Posts tagged "rust"

  • Published on

    Investigation · Part 4 of 10 · Types under the hood

    Shape Without Behavior: Two Structs With the Same Fields

    A Point and a Vector with the same two fields: TypeScript accepts one for the other, Rust refuses, and on this build the bytes and the instructions are identical, to the point that the optimized build keeps one function body under both names. The difference is a rule about names, and the name leaves no trace in the program.
  • Published on

    Investigation · Part 3 of 10 · Types under the hood

    A Type Is a Set: Why Human Has Two Members and Option of Human Has Three

    If a type is a set of allowed values, you can count its members. I counted fourteen Rust types and asked the compiler how many bytes each one needs. The size follows the count, with two exceptions I measured, the exhaustiveness error is arithmetic, and a type with zero members costs zero.
  • Published on

    Investigation · Part 2 of 10 · Types under the hood

    Does a Type Exist at Runtime? Following One Value From Source to Register

    I followed one u8 through the four stages of the Rust compiler: HIR, MIR, LLVM IR, and assembly. The type is a word, then a field, then a width, then nothing. The u8 and u32 versions of the same function compile to the same two instructions, and the one check a type does produce is the debug overflow guard.
  • Published on

    Investigation · Part 3 of 3 · Rust build times

    The Unit of Rebuild When You Split a Rust Workspace

    Measured with the same code as 1, 3 and 12 crates: splitting a Rust workspace narrows incremental rebuilds but increases total work, because generic instances are emitted once per crate.