From 441ab7ef902820b35e91044b932240bc13c98eef Mon Sep 17 00:00:00 2001 From: HackMD Date: Mon, 7 Feb 2022 22:45:11 +0000 Subject: [PATCH] sync with hackmd --- ...e-types-type-alias-impl-trait-inference.md | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/opaque-types-type-alias-impl-trait-inference.md b/src/opaque-types-type-alias-impl-trait-inference.md index b47216aa..0d738c88 100644 --- a/src/opaque-types-type-alias-impl-trait-inference.md +++ b/src/opaque-types-type-alias-impl-trait-inference.md @@ -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) 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`\nkeep searching"] + VisitProduceDoubleton["visit `produce_doubleton`"] + CompareType["`produce_doubleton` hidden type is also Vec\nthis matches what we saw before ✅"] + Done["Return `Vec`"] 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` as the hidden type"] + CheckSend["Check that `Vec: 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.