@@ -597,20 +597,19 @@ Borrow is used at multiple locations, therefor it is mutable from different refe
...
@@ -597,20 +597,19 @@ Borrow is used at multiple locations, therefor it is mutable from different refe
Below follows the rewritten examples that are accepted by the borrow checker.
Below follows the rewritten examples that are accepted by the borrow checker.
```rust
```rust
fna(x:&muti32)->(){
fna(x:&muti32)->(){
*x+=1;
*x=*x+1;
}
}
fnmain()->(){
fnmain()->(){
letmuty:i32=5;
letmuty:i32=5;
a(&muty);
a(&muty);
}
}
```
```
```rust
```rust
fnb(x:&muti32,y:&muti32)->(){
fnb(x:&muti32,y:&muti32)->(){
*x+=1;
*x=*x+1;
*y+=1;
*y=*y+1;
}
}
fnmain()->(){
fnmain()->(){
letmutx:i32=5;
letmutx:i32=5;
...
@@ -621,16 +620,17 @@ fn main() -> () {
...
@@ -621,16 +620,17 @@ fn main() -> () {
```rust
```rust
fnmain()->(){
fnmain()->(){
letmutx=0;
letmutx:i32=0;
lety=&mutx;
lety:i32=&mutx;
*y+=1;
*y=*y+1;
x+=1;
x=x+1;
}
}
```
```
The borrowchecker should make sure that:
The borrowchecker should make sure that:
- One reference can only be mutable at a time.
- One reference can only be mutable at a time.
- Multiple immutable references can be used.
- Multiple immutable references can be used.
- One mutable reference and multiple immutable references can not exist at the same time
This ensures that a variable can not be changed at the same time that another reference tries to read it.
This ensures that a variable can not be changed at the same time that another reference tries to read it.
...
@@ -648,5 +648,4 @@ The process of implementing the type checker and the interpreter was similar. Th
...
@@ -648,5 +648,4 @@ The process of implementing the type checker and the interpreter was similar. Th
- Code optimization and register allocation. Machine code generation for common architectures. [Both LLVM/Crane-Lift does the "dirty work" of backend optimization/register allocation leveraging the SSA form of the LLVM-IR]
- Code optimization and register allocation. Machine code generation for common architectures. [Both LLVM/Crane-Lift does the "dirty work" of backend optimization/register allocation leveraging the SSA form of the LLVM-IR]
It has been difficult to write good structured code because this is the first time I worked with Rust. Therefor the rules and structure was new to me which ended up in very messy code. I focused on getting as much as possible to work to get a broad understanding instead. It would be really fun to rewrite everything from the beginning now with the knowledge and insight the course have given!
Comment on additional things that you have experienced and learned throughout the course.