Repository: rust
Issue: [incremental] skip type-checking
Labels: C-enhancement,I-compiletime,T-compiler,A-incr-comp

This is a kind of meta-bug aimed at skipping type-checking, which is (to some extent) the "holy grail" of incremental compilation. This bug only contains a list of issues and a task breakdown. [For background on the general approach we have in mind, see this gist.](https://gist.github.com/nikomatsakis/6e9fae5319be49c70e7efbe67c09fc1a)

Substeps:

- [x] https://github.com/rust-lang/rust/issues/45210: Introduce the `ensure` operation [first described here](https://github.com/rust-lang/rust/issues/45156#issuecomment-335537847) and use it on the `typeck_tables_of` invocations. -- @theotherjimmy is [on it](https://github.com/rust-lang/rust/issues/45208#issuecomment-335896368)
- [x] https://github.com/rust-lang/rust/issues/45214: Isolate the "used trait imports" part of typeck tables into a distinct query
- [ ] Enable serialization and deserialization of incremental results, at least for some types.
    - In particular, we will need to support serializing and re-loading `Vec<DefId>`. It wouldn't hurt to support `()` while we're at it.
    - This is likely best tackled by @michaelwoerister or @alexcrichton, but that may not be the case.

Ultimately, all of the the uses of `typeck_tables_of` must be analyzed and eliminated. These uses are listed here in order to mine for producing more subtasks. =)

<details><p>

- [ ] `src/librustc_passes/consts.rs:142:        self.tables = self.tcx.typeck_tables_of(item_def_id);`
- [x] `src/librustc_typeck/check_unused.rs:69:        let tables = tcx.typeck_tables_of(item_def_id);`
- [ ] `src/librustc_save_analysis/dump_visitor.rs:109:            let tables = self.tcx.typeck_tables_of(item_def_id);`
- [ ] `src/librustc_typeck/collect.rs:1155:                return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id);`
- [ ] `src/librustc_typeck/collect.rs:1192:            tcx.typeck_tables_of(owner).node_id_to_type(hir_id)`
- [ ] `src/librustc_typeck/collect.rs:1244:            tcx.typeck_tables_of(def_id).closure_tys()[hir_id]`
- [ ] `src/librustc_privacy/lib.rs:503:        replace(tables, tcx.typeck_tables_of(def_id))`
- [ ] `src/librustc_const_eval/pattern.rs:606:                        self.tables = self.tcx.typeck_tables_of(def_id);`
- [ ] `src/librustc_const_eval/eval.rs:381:            tables: tcx.typeck_tables_of(def_id),`
- [ ] `src/librustc_const_eval/eval.rs:770:    let tables = tcx.typeck_tables_of(def_id);`
- [ ] `src/librustc_borrowck/borrowck/mod.rs:100:    let tables = tcx.typeck_tables_of(owner_def_id);`
- [ ] `src/librustc_borrowck/borrowck/mod.rs:198:    let tables = tcx.typeck_tables_of(owner_def_id);`
- [ ] `src/librustc/cfg/construct.rs:57:    let tables = tcx.typeck_tables_of(owner_def_id);`
- [x] `src/librustc/ty/mod.rs:2108:        self.typeck_tables_of(self.hir.body_owner_def_id(body))`
    - not a direct user, see calls of `body_tables()` below
- [ ] `src/librustc/middle/intrinsicck.rs:136:        let tables = self.tcx.typeck_tables_of(owner_def_id);`
- [ ] `src/librustc_typeck/check/mod.rs:734:            tcx.typeck_tables_of(body_owner_def_id);`
- [ ] `src/librustc_typeck/check/mod.rs:756:    tcx.typeck_tables_of(def_id).generator_sigs()[hir_id].map(|s| ty::Binder(s))`
- [ ] `src/librustc_typeck/check/mod.rs:764:    tcx.typeck_tables_of(def_id).closure_kinds()[hir_id].0`
- [ ] `src/librustc_typeck/check/mod.rs:857:        return tcx.typeck_tables_of(outer_def_id);`
- [ ] `src/librustc_typeck/check/mod.rs:1152:        tcx.typeck_tables_of(tcx.hir.local_def_id(it.id));`
- [ ] `src/librustc_typeck/check/mod.rs:1574:            tcx.typeck_tables_of(tcx.hir.local_def_id(e.node_id));`
- [ ] `src/librustc_mir/transform/generator.rs:712:        let interior = *tcx.typeck_tables_of(def_id).generator_interiors().get(hir_id).unwrap();`
- [ ] `src/librustc_mir/hair/cx/mod.rs:96:            tables: tcx.typeck_tables_of(src_def_id),`
- [ ] `src/tools/clippy/clippy_lints/src/consts.rs:302:                        tables: self.tcx.typeck_tables_of(def_id),`
- [ ] `src/librustc_privacy/lib.rs:518:        let orig_tables = replace(&mut self.tables, self.tcx.body_tables(body));`
- [ ] `src/librustc_privacy/lib.rs:672:        let orig_tables = replace(&mut self.tables, self.tcx.body_tables(body));`
- [ ] `src/librustc_driver/pretty.rs:505:            self.tables.set(self.tcx.body_tables(id));`
- [ ] `src/librustc_const_eval/check_match.rs:53:            tables: self.tcx.body_tables(b),`
- [ ] `src/librustc/lint/context.rs:636:        self.tables = self.tcx.body_tables(body);`
- [ ] `src/librustc/lint/context.rs:696:        self.tables = self.tcx.body_tables(body_id);`
- [ ] `src/librustc/middle/liveness.rs:530:        let tables = ir.tcx.body_tables(body);`
- [ ] `src/librustc/middle/reachable.rs:101:        self.tables = self.tcx.body_tables(body);`
- [ ] `src/librustc/middle/dead.rs:218:        self.tables = self.tcx.body_tables(body);`
- [ ] `src/librustc_mir/build/mod.rs:106:                    let gen_ty =  tcx.body_tables(body_id).node_id_to_type(fn_hir_id);`
- [ ] `src/librustc_mir/build/mod.rs:247:    let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_hir_id);`
- [ ] `src/tools/clippy/clippy_lints/src/attrs.rs:172:        is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)`
- [ ] `src/tools/clippy/clippy_lints/src/attrs.rs:180:        ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value),`
- [ ] `src/tools/clippy/clippy_lints/src/attrs.rs:189:            is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)`
- [ ] `src/tools/clippy/clippy_lints/src/functions.rs:154:                let tables = cx.tcx.body_tables(body.id());`

</p></details>