rust/compiler/rustc_codegen_llvm/src
bors e2750baf53 Auto merge of #88499 - eddyb:layout-off, r=nagisa
Provide `layout_of` automatically (given tcx + param_env + error handling).

After #88337, there's no longer any uses of `LayoutOf` within `rustc_target` itself, so I realized I could move the trait to `rustc_middle::ty::layout` and redesign it a bit.

This is similar to #88338 (and supersedes it), but at no ergonomic loss, since there's no funky `C: LayoutOf<Ty = Ty>` -> `Ty: TyAbiInterface<C>` generic `impl` chain, and each `LayoutOf` still corresponds to one `impl` (of `LayoutOfHelpers`) for the specific context.

After this PR, this is what's needed to get `trait LayoutOf` (with the `layout_of` method) implemented on some context type:
* `TyCtxt`, via `HasTyCtxt`
* `ParamEnv`, via `HasParamEnv`
* a way to transform `LayoutError`s into the desired error type
  * an error type of `!` can be paired with having `cx.layout_of(...)` return `TyAndLayout` *without* `Result<...>` around it, such as used by codegen
  * this is done through a new `LayoutOfHelpers` trait (and so is specifying the type of `cx.layout_of(...)`)

When going through this path (and not bypassing it with a manual `impl` of `LayoutOf`), the end result is that only the error case can be customized, the query itself and the success paths are guaranteed to be uniform.

(**EDIT**: just noticed that because of the supertrait relationship, you cannot actually implement `LayoutOf` yourself, the blanket `impl` fully covers all possible context types that could ever implement it)

Part of the motivation for this shape of API is that I've been working on querifying `FnAbi::of_*`, and what I want/need to introduce for that looks a lot like the setup in this PR - in particular, it's harder to express the `FnAbi` methods in `rustc_target`, since they're much more tied to `rustc` concepts.

r? `@nagisa` cc `@oli-obk` `@bjorn3`
2021-09-05 16:14:41 +00:00
..
back Move add_rlib and add_native_library to cg_ssa 2021-09-01 14:43:27 +02:00
coverageinfo Auto merge of #85178 - cjgillot:local-crate, r=oli-obk 2021-05-17 01:42:03 +00:00
debuginfo Auto merge of #88499 - eddyb:layout-off, r=nagisa 2021-09-05 16:14:41 +00:00
llvm Handle SrcMgr diagnostics 2021-08-16 18:28:17 +02:00
abi.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
allocator.rs Include debug info for the allocator shim 2021-08-31 15:24:20 -07:00
asm.rs Rollup merge of #88350 - programmerjake:add-ppc-cr-xer-clobbers, r=Amanieu 2021-09-01 09:23:26 +02:00
attributes.rs Add support for leaf fn frame pointer elimination 2021-06-30 19:45:17 +03:00
base.rs Always use llvm.used for coverage symbols 2021-08-21 10:08:05 +02:00
builder.rs ty::layout: split LayoutOf into required and (blanket) provided halves. 2021-09-02 01:17:14 +03:00
callee.rs Fix static relocation model for PowerPC64 2021-05-28 03:48:39 +02:00
common.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
consts.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
context.rs ty::layout: split LayoutOf into required and (blanket) provided halves. 2021-09-02 01:17:14 +03:00
declare.rs Remove the decl arg from FnAbi::llvm_type 2021-08-05 10:58:55 -07:00
intrinsic.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
lib.rs Include debug info for the allocator shim 2021-08-31 15:24:20 -07:00
llvm_util.rs Revert machine outliner disabling on LLVM 13 2021-08-28 15:11:46 +08:00
mono_item.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
type_.rs Auto merge of #87254 - rusticstuff:rustc_codegen_llvm_dont_emit_zero_sized_padding, r=eddyb 2021-08-11 01:36:23 +00:00
type_of.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
va_arg.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
value.rs