sync with hackmd

This commit is contained in:
HackMD 2022-02-07 22:45:11 +00:00 committed by Tshepang Mbambo
parent a6ed1bcb45
commit 441ab7ef90
1 changed files with 26 additions and 7 deletions

View File

@ -55,24 +55,43 @@ Let's start by looking what happens when we type-check `main`. Initially we invo
#### Type-checking the `is_send` call
* Explain how it invokes `type_of`
* We look at the bounds, we are able to type check it as is
```mermaid
flowchart TD
TypeChecking["type checking `main`"]
subgraph TypeOfSeq["type_of(Seq<T>) query"]
WalkModuleHir["Walk the HIR for the module `m`"]
VisitProduceSingleton["visit produce_singleton"]
VisitProduceDoubleton["visit produce_doubleton"]
WalkModuleHir["Walk the HIR for the module `m`\nto find the hidden types from each\nfunction within"]
VisitProduceSingleton["visit `produce_singleton`"]
InterimType["`produce_singleton` hidden type is `Vec<T>`\nkeep searching"]
VisitProduceDoubleton["visit `produce_doubleton`"]
CompareType["`produce_doubleton` hidden type is also Vec<T>\nthis matches what we saw before ✅"]
Done["Return `Vec<T>`"]
end
BorrowCheckProduceSingleton["`borrow_check(produce_singleton)`"]
TypeCheckProduceSingleton["`type_check(produce_singleton)`"]
BorrowCheckProduceDoubleton["`borrow_check(produce_doubleton)`"]
TypeCheckProduceDoubleton["`type_check(produce_doubleton)`"]
Substitute["Substitute `T => u32`,\nyielding `Vec<i32>` as the hidden type"]
CheckSend["Check that `Vec<i32>: Send` ✅"]
TypeChecking -- trait code for auto traits --> TypeOfSeq
TypeOfSeq --> WalkModuleHir
WalkModuleHir --> VisitProduceSingleton
VisitProduceSingleton --> VisitProduceDoubleton
VisitProduceSingleton --> BorrowCheckProduceSingleton
BorrowCheckProduceSingleton --> TypeCheckProduceSingleton
TypeCheckProduceSingleton --> InterimType
InterimType --> VisitProduceDoubleton
VisitProduceDoubleton --> BorrowCheckProduceDoubleton
BorrowCheckProduceDoubleton --> TypeCheckProduceDoubleton
TypeCheckProduceDoubleton --> CompareType --> Done
Done --> Substitute --> CheckSend
```
* Explain how it invokes `type_of`
* We look at the bounds, we are able to type check it as is
### Within the `type_of` query
The `type_of` query, when applied to an opaque type O, returns the hidden type. That hidden type is computed by combining the results from each constraining function within defining scope of O.