Jump to content

Compile time

From Wikipedia, the free encyclopedia

In computer science, compile time (or compile-time) describes the time window during which a language's statements are converted into binary instructions for the processor to execute.[1] The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (run time).

For example, compile-time requirements are programming language requirements that must be met by source code before compilation and compile-time properties are properties of the program that can be reasoned about during compilation. The actual length of time it takes to compile a program is usually referred to as compilation time.

Overview

[edit]

Most compilers have at least the following compiler phases (which therefore occur at compile-time): syntax analysis, semantic analysis, and code generation. During optimization phases, constant expressions in the source code can also be evaluated at compile-time using compile-time execution, which reduces the constant expressions to an immediate, single value.[2][3] This is not necessary for correctness, but to improve program performance during runtime.

Programming language definitions usually specify compile time requirements that source code must meet to be successfully compiled. For example, languages may stipulate that the amount of storage required by types and variables can be deduced.

Properties of a program that can be reasoned about at compile time include range-checks (e.g., proving that an array index will not exceed the array bounds), deadlock freedom in concurrent languages, or timings (e.g., proving that a sequence of code takes no more than an allocated amount of time). For statically-typed languages such as Java or Rust, types are checked at compile time to ensure type safety.[4]

Compile-time occurs before link time (when the output of one or more compiled files are joined) and runtime (when a program is executed). However, in the case of dynamic compilation, the final transformations into machine language happen at run time. Some compile-time operations can also be deferred to link-time while still not incurring a run-time cost.

See also

[edit]

References

[edit]
  1. ^ "A History of Computer Programming Languages". Retrieved 2022-12-25.
  2. ^ Yongwei, Wu (October 7, 2024). "C++ Compile-Time Programming". accu.org. Retrieved 2025-04-26.
  3. ^ "Compile Time Evaluation". C3. Retrieved 2025-04-26.
  4. ^ "Data Types - The Rust Programming Language". doc.rust-lang.org. Retrieved 2025-04-26.