Skip to content

Commit 857ee49

Browse files
hackmd-deploytshepang
authored andcommitted
sync with hackmd
1 parent 53395b0 commit 857ee49

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/opaque-types-type-alias-impl-trait-inference.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,43 @@ Let's start by looking what happens when we type-check `main`. Initially we invo
5555

5656
#### Type-checking the `is_send` call
5757

58+
* Explain how it invokes `type_of`
59+
* We look at the bounds, we are able to type check it as is
60+
5861
```mermaid
5962
flowchart TD
6063
TypeChecking["type checking `main`"]
6164
subgraph TypeOfSeq["type_of(Seq<T>) query"]
62-
WalkModuleHir["Walk the HIR for the module `m`"]
63-
VisitProduceSingleton["visit produce_singleton"]
64-
VisitProduceDoubleton["visit produce_doubleton"]
65+
WalkModuleHir["Walk the HIR for the module `m`\nto find the hidden types from each\nfunction within"]
66+
VisitProduceSingleton["visit `produce_singleton`"]
67+
InterimType["`produce_singleton` hidden type is `Vec<T>`\nkeep searching"]
68+
VisitProduceDoubleton["visit `produce_doubleton`"]
69+
CompareType["`produce_doubleton` hidden type is also Vec<T>\nthis matches what we saw before ✅"]
70+
Done["Return `Vec<T>`"]
6571
end
72+
73+
BorrowCheckProduceSingleton["`borrow_check(produce_singleton)`"]
74+
TypeCheckProduceSingleton["`type_check(produce_singleton)`"]
75+
76+
BorrowCheckProduceDoubleton["`borrow_check(produce_doubleton)`"]
77+
TypeCheckProduceDoubleton["`type_check(produce_doubleton)`"]
78+
79+
Substitute["Substitute `T => u32`,\nyielding `Vec<i32>` as the hidden type"]
80+
CheckSend["Check that `Vec<i32>: Send` ✅"]
6681
6782
TypeChecking -- trait code for auto traits --> TypeOfSeq
6883
TypeOfSeq --> WalkModuleHir
6984
WalkModuleHir --> VisitProduceSingleton
70-
VisitProduceSingleton --> VisitProduceDoubleton
85+
VisitProduceSingleton --> BorrowCheckProduceSingleton
86+
BorrowCheckProduceSingleton --> TypeCheckProduceSingleton
87+
TypeCheckProduceSingleton --> InterimType
88+
InterimType --> VisitProduceDoubleton
89+
VisitProduceDoubleton --> BorrowCheckProduceDoubleton
90+
BorrowCheckProduceDoubleton --> TypeCheckProduceDoubleton
91+
TypeCheckProduceDoubleton --> CompareType --> Done
92+
Done --> Substitute --> CheckSend
7193
```
7294

73-
* Explain how it invokes `type_of`
74-
* We look at the bounds, we are able to type check it as is
75-
7695
### Within the `type_of` query
7796

7897
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.

0 commit comments

Comments
 (0)