diff --git a/HOME_EXAM.md b/HOME_EXAM.md index 5d4ca1f2ed2cac9bc45d8682b0b2859d41645f60..5d5a87cfa7eed2893c52508abc8e0efb3aae232c 100644 --- a/HOME_EXAM.md +++ b/HOME_EXAM.md @@ -116,6 +116,37 @@ The Type Checker works as intended and rejects ill-typed programs. It does not u ## Your borrrow checker +### Borrow Checker Rules +The first major thing the borrow checker should keep track of is the moving of variables using a Move Path. +``` Rust +let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]); + +let b = a.0; // <- Acceptable borrow is done here, move path: a.b +let c = b; // Another acceptable borrow, move path: a.b.c +let d = b; // Ill formed borrow, variable already moved, + // cant borrow from anything + // but the end of a move path +``` +#### Illegal moves +- Moving a element of an array. If you have an array A a move of element A[n] can't be made. +- Move of static variables can't be made. +- Move away from a borrowed refrenece can't be done. + +Moving of variables as references can be done but it has some restrictions. When moving a nonmutable reference can be done multiple times: +``` Rust +let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]); +let b = &a; +let c = &a; // This move is completely legal due to b and c being nonmutable. +``` +Moving a mutable variable as a reference can also be done but only to one variable at a time: +``` Rust +let mut a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]); +let b = &mut a; +let c = &mut a; // Ill move, Can't move mutable references more then once. +``` +This error is there to prevent race conditions that can happen when a value can be changed in different places at the same time. + +### Comparision Not implemented. ## Your LLVM backend