rust/compiler/rustc_codegen_cranelift
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
..
.github/workflows Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
.vscode Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_clif-2021-07-07 2021-07-07 11:14:20 +02:00
build_sysroot Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
build_system Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
docs Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
example remove box_syntax uses from cranelift and tools 2021-08-18 09:31:51 +02:00
patches Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
scripts Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
src Auto merge of #88499 - eddyb:layout-off, r=nagisa 2021-09-05 16:14:41 +00:00
.cirrus.yml Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_clif-2021-07-07 2021-07-07 11:14:20 +02:00
.gitattributes
.gitignore Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
Cargo.lock Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
Cargo.toml Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
clean_all.sh Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
config.txt Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_clif-2021-07-07 2021-07-07 11:14:20 +02:00
LICENSE-APACHE
LICENSE-MIT
Readme.md Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_clif-2021-07-07 2021-07-07 11:14:20 +02:00
rust-toolchain Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00
rustfmt.toml
test.sh Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_clif-2021-07-07 2021-07-07 11:14:20 +02:00
y.rs Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06 2021-08-06 16:26:56 +02:00

Cranelift codegen backend for rust

The goal of this project is to create an alternative codegen backend for the rust compiler based on Cranelift. This has the potential to improve compilation times in debug mode. If your project doesn't use any of the things listed under "Not yet supported", it should work fine. If not please open an issue.

Building and testing

$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
$ cd rustc_codegen_cranelift
$ ./y.rs prepare # download and patch sysroot src and install hyperfine for benchmarking
$ ./y.rs build

To run the test suite replace the last command with:

$ ./test.sh

This will implicitly build cg_clif too. Both y.rs build and test.sh accept a --debug argument to build in debug mode.

Alternatively you can download a pre built version from GHA. It is listed in the artifacts section of workflow runs. Unfortunately due to GHA restrictions you need to be logged in to access it.

Usage

rustc_codegen_cranelift can be used as a near-drop-in replacement for cargo build or cargo run for existing projects.

Assuming $cg_clif_dir is the directory you cloned this repo into and you followed the instructions (y.rs prepare and y.rs build or test.sh).

In the directory with your project (where you can do the usual cargo build), run:

$ $cg_clif_dir/build/cargo build

This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.

For additional ways to use rustc_codegen_cranelift like the JIT mode see usage.md.

Configuration

See the documentation on the BackendConfig struct in config.rs for all configuration options.

Not yet supported

  • Inline assembly (no cranelift support)
    • On Linux there is support for invoking an external assembler for global_asm! and asm!. llvm_asm! will remain unimplemented forever. asm! doesn't yet support reg classes. You have to specify specific registers instead.
  • SIMD (tracked here, some basic things work)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.