miri
play

Miri An interpreter for Rusts mid-level intermediate representation - PowerPoint PPT Presentation

Miri An interpreter for Rusts mid-level intermediate representation Scott Olson Supervisor: Christopher Dutchyn CMPT 400 University of Saskatchewan https://www.rust-lang.org What is Rust? [review] } } println!("{}",


  1. Miri An interpreter for Rust’s mid-level intermediate representation Scott Olson Supervisor: Christopher Dutchyn CMPT 400 University of Saskatchewan https://www.rust-lang.org

  2. What is Rust? [review] } } println!("{}", factorial(x)); for x in 1..6 { According to the website… fn main() { (1..n).fold(1, |a, b| a * b) fn factorial(n: u64 ) -> u64 { It’s a new programming language from Mozilla, and it looks like this: guarantees thread safety. blazingly fast, prevents nearly all segfaults, and Rust is a systems programming language that runs } // ⇒ 1 // ⇒ 1 // ⇒ 2 // ⇒ 6 // ⇒ 24

  3. How does Rust compile code? [review] MIR CPU Execution Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify Source Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST ? Code Machine Code Miri

  4. How does Rust compile code? [review] MIR CPU Execution Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify Source Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Miri

  5. How does Rust compile code? [review] MIR CPU Execution Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify Source Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Miri

  6. How does Rust compile code? [review] MIR CPU Execution Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify Source Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Miri

  7. How does Rust compile code? [review] MIR CPU Execution Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify Source Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Miri

  8. How does Rust compile code? [review] Mid-level Intermediate CPU Execution Magic Translate Representation Low-level Intermediate LLVM IR Lower Representation MIR Source Simplify Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Miri

  9. How does Rust compile code? MIR CPU Execution Magic Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify [review] Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Source Miri

  10. How does Rust compile code? MIR CPU Execution Magic Translate Representation Low-level Intermediate LLVM IR Lower Representation Mid-level Intermediate Simplify [review] Representation High-level Intermediate HIR Parse Abstract Syntax Tree AST Code Machine Code Source Miri

  11. Why build Miri? execution of unsafe code, but shifued my goals along the way. Now it serves as an experimental implementation of the upcoming compile-time function evaluation feature in Rust. Similar to C++14’s constexpr feature. You can do complicated calculations at compile time and compile their results into the executable. For example, you can compute a “perfect hash function” for a statically-known map at compile-time and have guaranteed no-collision lookup at runtime. Miri actually supports far more of Rust than C++14’s constexpr does of C++ — even heap allocation and unsafe code. ◮ For fun and learning. ◮ I originally planned to use it for testing the compiler and

  12. Why build Miri? execution of unsafe code, but shifued my goals along the way. upcoming compile-time function evaluation feature in Rust. Similar to C++14’s constexpr feature. You can do complicated calculations at compile time and compile their results into the executable. For example, you can compute a “perfect hash function” for a statically-known map at compile-time and have guaranteed no-collision lookup at runtime. Miri actually supports far more of Rust than C++14’s constexpr does of C++ — even heap allocation and unsafe code. ◮ For fun and learning. ◮ I originally planned to use it for testing the compiler and ◮ Now it serves as an experimental implementation of the

  13. Why build Miri? execution of unsafe code, but shifued my goals along the way. upcoming compile-time function evaluation feature in Rust. compile their results into the executable. For example, you can compute a “perfect hash function” for a statically-known map at compile-time and have guaranteed no-collision lookup at runtime. Miri actually supports far more of Rust than C++14’s constexpr does of C++ — even heap allocation and unsafe code. ◮ For fun and learning. ◮ I originally planned to use it for testing the compiler and ◮ Now it serves as an experimental implementation of the ◮ Similar to C++14’s constexpr feature. ◮ You can do complicated calculations at compile time and

  14. Why build Miri? execution of unsafe code, but shifued my goals along the way. upcoming compile-time function evaluation feature in Rust. compile their results into the executable. statically-known map at compile-time and have guaranteed no-collision lookup at runtime. Miri actually supports far more of Rust than C++14’s constexpr does of C++ — even heap allocation and unsafe code. ◮ For fun and learning. ◮ I originally planned to use it for testing the compiler and ◮ Now it serves as an experimental implementation of the ◮ Similar to C++14’s constexpr feature. ◮ You can do complicated calculations at compile time and ◮ For example, you can compute a “perfect hash function” for a

  15. Why build Miri? execution of unsafe code, but shifued my goals along the way. upcoming compile-time function evaluation feature in Rust. compile their results into the executable. statically-known map at compile-time and have guaranteed no-collision lookup at runtime. constexpr does of C++ — even heap allocation and unsafe code. ◮ For fun and learning. ◮ I originally planned to use it for testing the compiler and ◮ Now it serves as an experimental implementation of the ◮ Similar to C++14’s constexpr feature. ◮ You can do complicated calculations at compile time and ◮ For example, you can compute a “perfect hash function” for a ◮ Miri actually supports far more of Rust than C++14’s

  16. How was it built? At first I wrote a naive version with a number of downsides: where every value was the same size. about low-level value layout essentially impossible. ◮ represented values in a traditional dynamic language format, ◮ didn’t work well for aggregates (structs, enums, arrays, etc.). ◮ made unsafe programming tricks that make assumptions

  17. How was it built? machine” with specialized value layout which solved my previous problems. His proposal was intended for a compile-time function evaluator in the Rust compiler, so I effectively implemented an experimental version of that. Afuer this point, making Miri work well was primarily a sofuware engineering problem. ◮ Later, a Rust compiler team member proposed a “Rust abstract

  18. How was it built? machine” with specialized value layout which solved my previous problems. evaluator in the Rust compiler, so I effectively implemented an experimental version of that. Afuer this point, making Miri work well was primarily a sofuware engineering problem. ◮ Later, a Rust compiler team member proposed a “Rust abstract ◮ His proposal was intended for a compile-time function

  19. How was it built? machine” with specialized value layout which solved my previous problems. evaluator in the Rust compiler, so I effectively implemented an experimental version of that. engineering problem. ◮ Later, a Rust compiler team member proposed a “Rust abstract ◮ His proposal was intended for a compile-time function ◮ Afuer this point, making Miri work well was primarily a sofuware

  20. Data layout “abstract allocations”. 1. An array of raw bytes with a size based on the type of the value 2. A set of relocations — pointers into other abstract allocations 3. A mask determining which bytes are undefined ◮ Memory in Miri is literally a HashMap from “allocation IDs” to ◮ Allocations are represented by:

  21. Data layout “abstract allocations”. 1. An array of raw bytes with a size based on the type of the value 2. A set of relocations — pointers into other abstract allocations 3. A mask determining which bytes are undefined ◮ Memory in Miri is literally a HashMap from “allocation IDs” to ◮ Allocations are represented by:

  22. Data layout “abstract allocations”. 1. An array of raw bytes with a size based on the type of the value 2. A set of relocations — pointers into other abstract allocations 3. A mask determining which bytes are undefined ◮ Memory in Miri is literally a HashMap from “allocation IDs” to ◮ Allocations are represented by:

  23. Data layout “abstract allocations”. 1. An array of raw bytes with a size based on the type of the value 2. A set of relocations — pointers into other abstract allocations 3. A mask determining which bytes are undefined ◮ Memory in Miri is literally a HashMap from “allocation IDs” to ◮ Allocations are represented by:

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend