|
1 | 1 | # Architecture Notes |
2 | 2 |
|
| 3 | +## The effect of imports and flattening on the CMR |
| 4 | + |
| 5 | +Imports and the flattening phase have **no impact** on the CMR. The underlying order of calculation is strictly determined by the `main` function. |
| 6 | + |
| 7 | +For example, consider the following code: |
| 8 | + |
| 9 | +```rust |
| 10 | +fn a() -> u32 { 5 } |
| 11 | +fn b() -> u32 { 6 } |
| 12 | + |
| 13 | +fn main() { |
| 14 | + let a: u32 = a(); |
| 15 | + let b: u32 = b(); |
| 16 | + let (_, c): (bool, u32) = jet::add_32(a, b); |
| 17 | + assert!(jet::eq_32(c, 11)); |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +It does not matter whether `fn a()` or `fn b()` is declared first; the driver can reorder these declarations as it sees fit without affecting the CMR. |
| 22 | + |
| 23 | +The flattening phase behaves in the exact same way. While it wraps the file's contents into a `mod unit_N { ... }` block, it does not alter the execution order inside `main`. The CMR will change if and only if we explicitly modify the execution order (e.g., swapping the evaluation of `let a` and `let b`) within the `main` function itself. |
| 24 | + |
| 25 | +Below are three scenarios where resolution errors corrupt the CMR: |
| 26 | + |
| 27 | +1. Incorrect Aliasing or Function Substitution |
| 28 | +If the resolution phase maps an alias to the wrong function, the compiler silently substitutes one implementation for another. Since the program logic has changed, the resulting CMR will be entirely different. |
| 29 | + |
| 30 | +2. Entry Point Fallback (main hijacking) |
| 31 | +The CMR is rooted at the main function of the entry file. If the compiler does not enforce this, it may traverse the dependency graph and pick up a main from a dependency instead. This completely changes the execution graph. |
| 32 | + |
| 33 | +3. Resolution Cache Poisoning (use path collisions) |
| 34 | +When different package roots share structurally identical import paths (e.g., both a binary and a library declare `use crate::A::foo`), an improperly isolated resolution cache may link one context's import to the other's physical file. (See `functional_tests::identical_crate_uses_in_different_package_roots_do_not_poison_resolution_cache`.) |
| 35 | + |
| 36 | +*Note: The scenarios listed above reflect bugs discovered during current testing. The list is ***not exhaustive*** and may be expanded as further testing uncovers additional edge cases.* |
| 37 | + |
3 | 38 | ## Crate and Module Paths |
4 | 39 |
|
5 | 40 | The `crate` keyword is used to construct absolute paths where the path root is the current package's root directory. This provides an explicit and readable way to distinguish local imports from external library imports. |
|
0 commit comments