Skip to content

Commit d3fa87a

Browse files
committed
docs: Enhance Rust documentation with new pages and updates
- Added documentation for compile-time and runtime execution phases - Created new pages for compile-time and runtime concepts - Updated existing Rust documentation with additional examples and clarifications
1 parent 3def69c commit d3fa87a

10 files changed

+170
-1
lines changed

journals/2025_11_27.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
- [[cargo/doc/--open]] can build the documentation for your deps and open it in your browser. Cool!
1717
- [[Rust/match]]
1818
- [[Programming/Pattern Matching]] - created general pattern matching concept documentation
19+
- [[Programming/Time/Compile]] and [[Programming/Time/Run]] - created documentation for compile-time and runtime execution phases
1920
-

journals/2025_11_28.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Rust Study
2+
- ### [[Rust/Book/TRPL/Interactive]]
3+
- [[Rust/Variable/Constant]]

pages/Convention___Naming.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alias:: [[Naming Convention]]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
alias:: [[Compile-time]], [[Compile-time Evaluation]]
2+
3+
- # Compile-Time
4+
- Also known as: compile time, compilation time, compile-time evaluation
5+
- The phase of program development when source code is transformed into executable code by a compiler
6+
- Operations and evaluations that occur during compilation, before the program runs
7+
- ## Definition
8+
- The period during which a compiler processes source code
9+
- Includes syntax analysis, semantic analysis, type checking, optimization, and code generation
10+
- Errors and checks that occur during this phase are called "compile-time errors"
11+
- ## Key Characteristics
12+
- **Static Analysis**: The compiler analyzes code without executing it
13+
- **Type Checking**: Types are verified before execution
14+
- **Constant Evaluation**: Constant expressions are evaluated during compilation
15+
- **Optimization**: Code optimizations are applied before runtime
16+
- **Code Generation**: Source code is transformed into machine code or bytecode
17+
- ## Compile-Time Operations
18+
- ### Syntax Analysis
19+
- Parsing source code into an abstract syntax tree (AST)
20+
- Detecting syntax errors
21+
- ### Semantic Analysis
22+
- Type checking and type inference
23+
- Scope resolution
24+
- Name resolution
25+
- ### Constant Folding
26+
- Evaluating constant expressions at compile-time
27+
- Example: `const x = 2 + 3` becomes `const x = 5` at compile-time
28+
- ### Macro Expansion
29+
- Processing macros and metaprogramming constructs
30+
- Template instantiation (in languages like C++)
31+
- ### Optimization
32+
- Dead code elimination
33+
- Inlining
34+
- Constant propagation
35+
- ## Compile-Time vs Runtime
36+
- **Compile-Time**: Errors caught before execution, constant values known, type safety enforced
37+
- **Runtime**: Program execution, dynamic behavior, user input processing
38+
- Many languages aim to catch as many errors as possible at compile-time
39+
- ## Language Examples
40+
- ### Rust
41+
- `const` values must be computable at compile-time
42+
- Type checking happens entirely at compile-time
43+
- Borrow checker operates at compile-time
44+
- ### C/C++
45+
- Template metaprogramming evaluated at compile-time
46+
- `constexpr` functions and variables
47+
- ### TypeScript
48+
- Type checking occurs at compile-time (transpilation)
49+
- No runtime type information
50+
- ## Benefits
51+
- **Early Error Detection**: Catch errors before deployment
52+
- **Performance**: Constant evaluation and optimization happen once, not on every execution
53+
- **Type Safety**: Prevent type-related errors before runtime
54+
- **Better Tooling**: IDEs can provide better autocomplete and error detection
55+
- ## Related
56+
- [[Programming/Time/Run]] - The execution phase of a program
57+
- [[Rust/Variable/Constant]] - Constants evaluated at compile-time in Rust
58+
- Static analysis and type systems

pages/Programming___Time___Run.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
alias:: [[Runtime]]
2+
3+
- # Runtime
4+
- Also known as: run-time, runtime execution, execution time
5+
- The phase when a program is actually executing, after compilation
6+
- Operations and evaluations that occur while the program is running
7+
- ## Definition
8+
- The period during which a compiled program executes
9+
- The execution environment where program code runs
10+
- Dynamic behavior that cannot be determined until the program runs
11+
- ## Key Characteristics
12+
- **Dynamic Execution**: Code is executed with actual data and user input
13+
- **Runtime Environment**: The system that executes the program (virtual machine, interpreter, or native execution)
14+
- **Dynamic Behavior**: Values and control flow determined by runtime conditions
15+
- **Error Handling**: Runtime errors occur during execution
16+
- ## Runtime Operations
17+
- ### Program Execution
18+
- Instruction execution
19+
- Memory allocation and deallocation
20+
- Function calls and stack management
21+
- ### Dynamic Behavior
22+
- User input processing
23+
- Network requests
24+
- File I/O operations
25+
- Database queries
26+
- ### Runtime Checks
27+
- Array bounds checking (in some languages)
28+
- Null pointer checks
29+
- Type checks (in dynamically typed languages)
30+
- Resource availability checks
31+
- ### Memory Management
32+
- Heap allocation
33+
- Garbage collection (in managed languages)
34+
- Stack management
35+
- ## Runtime vs Compile-Time
36+
- **Runtime**: Dynamic behavior, user interaction, actual execution
37+
- **Compile-Time**: Static analysis, type checking, constant evaluation
38+
- Some languages (like Python, JavaScript) have minimal compile-time checks
39+
- ## Runtime Environments
40+
- ### Virtual Machines
41+
- JVM (Java Virtual Machine)
42+
- .NET CLR (Common Language Runtime)
43+
- Erlang BEAM
44+
- ### Interpreters
45+
- Python interpreter
46+
- JavaScript engines (V8, SpiderMonkey)
47+
- ### Native Execution
48+
- Compiled languages that run directly on hardware
49+
- Rust, C, C++, Go (when compiled to native code)
50+
- ## Runtime Errors
51+
- Errors that occur during program execution
52+
- Examples:
53+
- Null pointer exceptions
54+
- Array index out of bounds
55+
- Division by zero
56+
- File not found
57+
- Network timeouts
58+
- Contrast with compile-time errors, which prevent the program from being built
59+
- ## Language Examples
60+
- ### Dynamically Typed Languages
61+
- Python, JavaScript, Ruby: Most type checking happens at runtime
62+
- Type errors only discovered when code executes
63+
- ### Statically Typed Languages
64+
- Rust, Java, C#: Most type checking at compile-time
65+
- Runtime errors typically from logic errors or resource issues
66+
- ## Benefits and Trade-offs
67+
- **Flexibility**: Can handle dynamic data and user input
68+
- **Runtime Optimization**: Just-in-time (JIT) compilation can optimize hot paths
69+
- **Error Discovery**: Some errors only appear at runtime
70+
- **Performance Overhead**: Runtime checks add execution overhead
71+
- ## Related
72+
- [[Programming/Time/Compile]] - The compilation phase before execution
73+
- Runtime environments and virtual machines
74+
- Dynamic typing vs static typing

pages/Rust___Variable.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- [[Rust/Variable/Constant]]
2+
- `const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3;`
3+
- `const` can be used in global or function scope
4+
- `const` can be initialized with a specific subset of all possible expressions; see [Rust Reference’s section on constant evaluation](https://doc.rust-lang.org/reference/const_eval.html)
5+
- `const` is required to have a type parameter
6+
- {{embed [[Rust/Variable/let]]}}
7+
-
8+
-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
alias:: [[Rust/const]]
2+
3+
- declared with `const`
4+
- required to have a [[Rust/Type/Annotation]]
5+
- [[Naming Convention]]: all uppercase with underscores between words
6+
- [[Example]]
7+
- ```rust
8+
const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3;
9+
```
10+
- [[Rust/Expression/Constant]] [Rust Reference’s section on constant evaluation](https://doc.rust-lang.org/reference/const_eval.html)
11+
- There's a subset of expressions that can be used when creating a const. These are evaluated at [[Compile-time]].
12+
-
13+
- See also
14+
- [Variables and Mutability - The Rust Programming Language](https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html)

pages/Rust___Variable___let.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `let foo = 1`
2+
- `let` can only be used in function local scope
3+
- unlike `const`, it's not required to have a type annotation, but [[Rust/analyzer]] will likely make it difficult to create a new one without inserting the type, e.g. it will change `let foo = 1` to `let foo: u32 = 1`
4+
- [[Rust/mut]] - `let mut count = FOUR;`
5+
- `mut` is a `let` suffix that makes the variable mutable

pages/Rust___analyzer.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
alias:: [[rust-analyzer]]
2+
3+
- `rust-analyzer`
4+
- an [[LSP]] for [[Rust]]

pages/Rust___match.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- [`match`](https://rust-book.cs.brown.edu/ch06-02-match.html) expressions do [[Programming/Pattern Matching]]
2-
- consists of "arms"
2+
- consists of "arms" of a pattern leading to some code
33
- example
4+
collapsed:: true
45
- ```rust
56
match guess.cmp(&secret_number) {
67
Ordering::Less => println!("Too small!"),

0 commit comments

Comments
 (0)