INTERMEDIATE REPRESENTATIONS OF THE SOURCE CODE IN THE RUSTC COMPILER

Authors

  • Aleksa Bajat Autor

DOI:

https://doi.org/10.24867/33BE08Bajat

Keywords:

rustc, compiler, intermediate representations

Abstract

This paper explores the architecture of the Rust compiler's (rustc) frontend, focusing on the crucial role of intermediate representations (IRs) of source code in the compilation process. Phases from lexical analysis and parsing to the generation of the Abstract Syntax Tree (AST), through the High-Level Intermediate Representation (HIR), Typed HIR (THIR), to the Mid-Level Intermediate Representation (MIR) are analyzed. The paper explains how each of these representations enables key features of the Rust language, including type checking, error diagnostics, incremental compilation, borrow checking, and preparation for further optimization and code generation in LLVM. The aim is to demonstrate how generation of compiler infrastructure contributes to Rust's guarantees of memory safety and high performance.

References

[1] MSRC, “A proactive approach to more secure code | MSRC Blog | Microsoft Security Re-

sponse Center,” Microsoft.com, Jul. 16, 2019. https://msrc.microsoft.com/blog/2019/07/

a-proactive-approach-to-more-secure-code/ (pristupljeno u septembru 2024.)

[2] “Parsing” Rochester.edu, 2024. https://www.cs.rochester.edu/u/nelson/courses/csc_

173/grammars/parsing.html#:~:text=Recursive%2Ddescent%20parsing%20is%20one,

non%2Dterminal%20with%20a%20procedure (pristupljeno u septembru 2024.)

[3] A. V. Aho, M. S. Lam, R. Sethi, and J. D. Ullman, Compilers: Principles, Techniques, and Tools, 2nd ed. Boston, MA, USA: Addison-Wesley, 2006.

[4] “Getting Started - Rust Compiler Development Guide,” Rust-lang.org, 2024. https:

//rustc-dev-guide.rust-lang.org/getting-started.html (pristupljeno u Septembru 2024.)

[5] “Introduction - The Rust Reference,” Rust-lang.org, 2015. https://doc.rust-lang.org/

reference/introduction.html (pristupljeno u septembru 2024.)

[6] “Meet Safe and Unsafe - The Rustonomicon,” Rust-lang.org, 2024. https://doc.rust-lang.

org/nomicon/meet-safe-and-unsafe.html (pristupljeno u septembru 2024)

[7] “What are editions? - The Rust Edition Guide,” Rust-lang.org, 2024. https://doc.rust-lang.

org/edition-guide/editions/ (pristupljeno u oktobru 2024.)

[8] “The Unstable Book - The Rust Unstable Book,” Rust-lang.org, 2024. https://doc.rust-lang.

org/unstable-book/index.html (pristupljeno u oktobru 2024.)

[9] Li, Chenghao, et al. “Demystifying Compiler Unstable Feature Usage and Impacts in the Rust Ecosys-

tem.” 26 Oct. 2023. arXiv, (pristupljeno u oktobru 2024.)

[10] Bugden W, Alahmar A. Rust: The programming language for safety and performance. arXiv preprint arXiv:2206.05503. 2022 Jun 11.

[11] P. Mainardi, “The Rising Threat of Software Supply Chain Attacks: Managing Dependencies of Open Source projects,” Linuxfoundation.eu, Aug. 15, 2023. https://linuxfoundation.eu/newsroom/

the-rising-threat-of-software-supply-chain-attacks-managing-dependencies-of-open-source-p

(pristupljeno u oktobru 2024.)

[12] “The Architecture of Open Source Applications (Volume 1)LLVM,” Aosabook.org, 2024. https:

//aosabook.org/en/v1/llvm.html (pristupljeno u novembru 2024.)

[13] “The LLVM Compiler Infrastructure Project,” Llvm.org, 2024. https://llvm.org/ (pristupljeno u novembru 2024.)

Published

2026-01-30

Issue

Section

Electrotechnical and Computer Engineering