rust/src/librustc_codegen_ssa
bors 7e11379f3b Auto merge of #74113 - lcnr:type-dependent-consts-2, r=eddyb
Support const args in type dependent paths (Take 2)

once more, except it is sound this time 🥰 previously #71154

-----
```rust
#![feature(const_generics)]

struct A;
impl A {
    fn foo<const N: usize>(&self) -> usize { N }
}
struct B;
impl B {
    fn foo<const N: usize>(&self) -> usize { 42 }
}

fn main() {
    let a = A;
    a.foo::<7>();
}
```
When calling `type_of` for generic const arguments, we now use the `TypeckTables` of the surrounding body to get the expected type.

This alone causes cycle errors though, as we now have `typeck_tables_of(main)` -> `...` ->
`type_of(main_ANON0 := 7)` -> `typeck_tables_of(main)`  (see https://github.com/rust-lang/rust/issues/68400#issuecomment-611760290)

To prevent this we must not call `type_of(const_arg)` during `typeck_tables_of`. This is achieved by
calling `type_of(param_def_id)` instead.

We have to somehow remember the `DefId` of the param through all of typeck, which is done using the
struct `ty::WithOptConstParam<DefId>`, which replaces `DefId` where needed and contains an `Option<DefId>` to
be able to store the const parameter in case it exists.

Queries which are currently cached on disk are split into two variants: `query_name`(cached) and `query_name_(of|for)_const_arg`(not cached), with `query_name_of_const_arg` taking a pair `(did, param_did): (LocalDefId, DefId)`.

For some queries a method `query_name_of_opt_const_arg` is added to `TyCtxt` which takes a `ty::WithOptConstParam` and either calls `query_name` or `query_name_of_const_arg` depending on the value of `const_param_did`.

r? @eddyb @varkor
2020-07-15 12:49:25 +00:00
..
back Auto merge of #74113 - lcnr:type-dependent-consts-2, r=eddyb 2020-07-15 12:49:25 +00:00
coverageinfo add spans to injected coverage counters 2020-06-29 12:31:25 -07:00
debuginfo Modify type names on MSVC to make tuples .natvis compatible. 2020-06-24 19:28:12 -07:00
mir const_eval_resolve 2020-07-15 12:58:32 +02:00
traits Undo the const_str changes from the previous commit. 2020-07-15 14:38:00 +10:00
base.rs Avoid "whitelist" 2020-07-10 07:39:28 -04:00
build.rs rustbuild: include channel in sanitizers installed name 2020-02-11 09:40:58 +01:00
Cargo.toml Make things build again 2020-06-02 20:38:24 +03:00
common.rs Prepare for LLVM 11 2020-06-25 18:52:41 -07:00
glue.rs rustc -> rustc_middle part 2 2020-03-30 07:16:56 +02:00
lib.rs Use for<'tcx> fn pointers in Providers, instead of having Providers<'tcx>. 2020-07-05 23:00:14 +03:00
meth.rs rustc -> rustc_middle part 2 2020-03-30 07:16:56 +02:00
mono_item.rs Change SymbolName::name to a &str. 2020-07-15 14:37:55 +10:00
README.md fix rustc-dev-guide url in src/librustc_codegen_ssa 2020-04-10 22:48:34 +08:00

Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.