Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #78707

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2be0596
Use with_no_trimmed_paths
bjorn3 Oct 27, 2020
4445e46
Add test where diagnostic span points to just the inlined function's …
oli-obk Sep 19, 2020
c8a866e
Show the inline stack of MIR lints that only occur after inlining
oli-obk Sep 19, 2020
888ef24
Address review comment
Oct 27, 2020
4206f9f
Prefer numeric associated constants in example
bstrie Oct 27, 2020
9842954
Merge pull request #1096 from bstrie/patch-1
bjorn3 Oct 27, 2020
5103a25
Rustup to rustc 1.49.0-nightly (07e968b64 2020-10-27)
bjorn3 Oct 28, 2020
4cc6b4f
Fix many clippy warnings
bjorn3 Oct 28, 2020
114be42
Rustup to rustc 1.49.0-nightly (ffe52882e 2020-10-30)
bjorn3 Oct 31, 2020
c067be0
Implement -Zfunction-sections
bjorn3 Oct 31, 2020
34be539
Use Pointer::dangling for ZST's in trans_const_value
bjorn3 Oct 31, 2020
6b1902a
Update Cranelift
bjorn3 Oct 31, 2020
f4e8af2
Update Cranelift
bjorn3 Nov 1, 2020
8063c37
Merge pull request #1099 from bjorn3/fix_rustc_bootstrap
bjorn3 Nov 1, 2020
d27f2f0
Rename trans to codegen
mominul Nov 1, 2020
c1cad03
Merge pull request #1100 from mominul/trans->codegen
bjorn3 Nov 1, 2020
c674c2c
Hide anonymous allocations from linked artifact
bjorn3 Nov 1, 2020
8b9c213
Fix transmutes between vectors and integers
bjorn3 Nov 1, 2020
c93d25b
reverse binding order in matches ...
vn-ki Nov 1, 2020
324e63d
Ensure that sysroot build works with CARGO_TARGET_DIR set
bjorn3 Nov 1, 2020
cb36760
Split the actual tests out into scripts/tests.sh
bjorn3 Nov 1, 2020
1ea618a
Make it easier to use build_sysroot.sh
bjorn3 Nov 1, 2020
9410b58
Update build instructions
bjorn3 Nov 1, 2020
0e2337a
Deny #[deprecated] on trait impl blocks.
m-ou-se Oct 31, 2020
706bc33
Use the right span for errors about #[deprecated] attributes.
m-ou-se Nov 1, 2020
6f1992a
Turn 'useless #[deprecated]' error into a lint.
m-ou-se Nov 1, 2020
9fc991a
Add test for #[deprecated] attribute on trait impl block.
m-ou-se Nov 1, 2020
ace02c4
Corrected suggestion for generic parameters in `function_item_referen…
ayrtonm Nov 2, 2020
5dee38d
update some ui tests and update move ref drop semantics output
vn-ki Nov 2, 2020
9088807
update mir tests
vn-ki Nov 2, 2020
9c647d1
Improve deprecation attribute diagnostic messages.
m-ou-se Nov 2, 2020
6bdce7b
new fix method and update tests
vn-ki Nov 2, 2020
0c34f5a
Refactor the build system
bjorn3 Nov 2, 2020
8315730
Upload prebuilt cg_clif
bjorn3 Nov 2, 2020
520a61f
Merge pull request #1104 from bjorn3/build_system_refactor
bjorn3 Nov 2, 2020
646b00f
Revert unintentional change
bjorn3 Nov 2, 2020
54b1d10
Test bootstrapping of rustc using cg_clif
bjorn3 Nov 1, 2020
03f01bb
Merge pull request #1105 from bjorn3/test_rustc_bootstrapping
bjorn3 Nov 2, 2020
22383b3
Use reparsed `TokenStream` if we captured any inner attributes
Aaron1011 Nov 2, 2020
1aedcd3
Suggest library/std when running all stage 0 tests
jyn514 Nov 2, 2020
f422e81
preserve bindings order for Some
vn-ki Nov 3, 2020
f44f96d
add tests
vn-ki Nov 3, 2020
216c4ae
Merge commit '03f01bbe901d60b71cf2c5ec766aef5e532ab79d' into update_c…
bjorn3 Nov 3, 2020
c32de75
lldb_batchmode: show more error information
pietroalbini Nov 3, 2020
5827fba
review comments
vn-ki Nov 3, 2020
7046855
Rollup merge of #76931 - oli-obk:const_prop_inline_lint_madness, r=we…
Dylan-DPC Nov 3, 2020
da3091b
Rollup merge of #78624 - bjorn3:update_cg_clif-2020-11-01, r=jyn514
Dylan-DPC Nov 3, 2020
d159121
Rollup merge of #78626 - fusion-engineering-forks:deprecated-trait-im…
Dylan-DPC Nov 3, 2020
6a7753e
Rollup merge of #78638 - vn-ki:bindigs-after-at-issue-69971, r=oli-obk
Dylan-DPC Nov 3, 2020
c450d4a
Rollup merge of #78659 - ayrtonm:fn-ref-lint-fix, r=oli-obk
Dylan-DPC Nov 3, 2020
86ef8d6
Rollup merge of #78677 - Aaron1011:fix/capture-inner-attrs, r=petroch…
Dylan-DPC Nov 3, 2020
858ddf2
Rollup merge of #78687 - jyn514:bootstrap-help, r=Mark-Simulacrum
Dylan-DPC Nov 3, 2020
4919b7c
Rollup merge of #78699 - pietroalbini:lldb-error, r=jyn514
Dylan-DPC Nov 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,19 +637,15 @@ pub struct Deprecation {
}

/// Finds the deprecation attribute. `None` if none exists.
pub fn find_deprecation(sess: &Session, attrs: &[Attribute], item_sp: Span) -> Option<Deprecation> {
find_deprecation_generic(sess, attrs.iter(), item_sp)
pub fn find_deprecation(sess: &Session, attrs: &[Attribute]) -> Option<(Deprecation, Span)> {
find_deprecation_generic(sess, attrs.iter())
}

fn find_deprecation_generic<'a, I>(
sess: &Session,
attrs_iter: I,
item_sp: Span,
) -> Option<Deprecation>
fn find_deprecation_generic<'a, I>(sess: &Session, attrs_iter: I) -> Option<(Deprecation, Span)>
where
I: Iterator<Item = &'a Attribute>,
{
let mut depr: Option<Deprecation> = None;
let mut depr: Option<(Deprecation, Span)> = None;
let diagnostic = &sess.parse_sess.span_diagnostic;

'outer: for attr in attrs_iter {
Expand All @@ -658,8 +654,11 @@ where
continue;
}

if depr.is_some() {
struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit();
if let Some((_, span)) = &depr {
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
.span_label(attr.span, "repeated deprecation attribute")
.span_label(*span, "first deprecation attribute")
.emit();
break;
}

Expand Down Expand Up @@ -780,7 +779,7 @@ where
sess.mark_attr_used(&attr);

let is_since_rustc_version = sess.check_name(attr, sym::rustc_deprecated);
depr = Some(Deprecation { since, note, suggestion, is_since_rustc_version });
depr = Some((Deprecation { since, note, suggestion, is_since_rustc_version }, attr.span));
}

depr
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Bootstrap rustc using cg_clif

on:
- push

jobs:
bootstrap_rustc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Cache cargo installed crates
uses: actions/cache@v2
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-installed-crates

- name: Cache cargo registry and index
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo target dir
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

- name: Prepare dependencies
run: |
git config --global user.email "[email protected]"
git config --global user.name "User"
./prepare.sh

- name: Test
run: |
# Enable backtraces for easier debugging
export RUST_BACKTRACE=1

./scripts/test_bootstrap.sh
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ jobs:
export COMPILE_RUNS=2
export RUN_RUNS=2

./test.sh --release
./test.sh

- name: Package prebuilt cg_clif
run: tar cvfJ cg_clif.tar.xz build

- name: Upload prebuilt cg_clif
uses: actions/upload-artifact@v2
with:
name: cg_clif-${{ runner.os }}
path: cg_clif.tar.xz
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ perf.data
perf.data.old
*.events
*.string*
/build_sysroot/sysroot
/build
/build_sysroot/sysroot_src
/rust
/rand
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cranelift-bforest"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-entity",
]

[[package]]
name = "cranelift-codegen"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"byteorder",
"cranelift-bforest",
Expand All @@ -70,7 +70,7 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen-shared",
"cranelift-entity",
Expand All @@ -79,17 +79,17 @@ dependencies = [
[[package]]
name = "cranelift-codegen-shared"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"

[[package]]
name = "cranelift-entity"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"

[[package]]
name = "cranelift-frontend"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"log",
Expand All @@ -100,7 +100,7 @@ dependencies = [
[[package]]
name = "cranelift-module"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -112,7 +112,7 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"raw-cpuid",
Expand All @@ -122,7 +122,7 @@ dependencies = [
[[package]]
name = "cranelift-object"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -135,7 +135,7 @@ dependencies = [
[[package]]
name = "cranelift-simplejit"
version = "0.67.0"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
dependencies = [
"cranelift-codegen",
"cranelift-entity",
Expand Down
37 changes: 26 additions & 11 deletions compiler/rustc_codegen_cranelift/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,56 @@

> ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠

The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/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.
The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/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
## Building and testing

```bash
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
$ cd rustc_codegen_cranelift
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
$ ./test.sh --release
$ ./build.sh
```

To run the test suite replace the last command with:

```bash
$ ./test.sh
```

This will implicitly build cg_clif too. Both `build.sh` 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.

[GHA]: https://github.com/bjorn3/rustc_codegen_cranelift/actions?query=branch%3Amaster+event%3Apush+is%3Asuccess

## 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 (`prepare.sh` and `test.sh`).
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`).

### Cargo

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

```bash
$ $cg_clif_dir/cargo.sh run
$ $cg_clif_dir/build/cargo.sh run
```

This should build and run your project with rustc_codegen_cranelift instead of the usual LLVM backend.

If you compiled cg_clif in debug mode (aka you didn't pass `--release` to `./test.sh`) you should set `CHANNEL="debug"`.

### Rustc

> You should prefer using the Cargo method.

```bash
$ $cg_clif_dir/target/release/cg_clif my_crate.rs
$ $cg_clif_dir/build/cg_clif my_crate.rs
```

### Jit mode
Expand All @@ -47,13 +62,13 @@ In jit mode cg_clif will immediately execute your code without creating an execu
> The jit mode will probably need cargo integration to make this possible.

```bash
$ $cg_clif_dir/cargo.sh jit
$ $cg_clif_dir/build/cargo.sh jit
```

or

```bash
$ $cg_clif_dir/target/release/cg_clif --jit my_crate.rs
$ $cg_clif_dir/build/cg_clif --jit my_crate.rs
```

### Shell
Expand All @@ -62,7 +77,7 @@ These are a few functions that allow you to easily run rust code from the shell

```bash
function jit_naked() {
echo "$@" | $cg_clif_dir/target/release/cg_clif - --jit
echo "$@" | $cg_clif_dir/build/cg_clif - --jit
}

function jit() {
Expand Down
47 changes: 47 additions & 0 deletions compiler/rustc_codegen_cranelift/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

# Settings
export CHANNEL="release"
build_sysroot=1
target_dir='build'
while [[ $# != 0 ]]; do
case $1 in
"--debug")
export CHANNEL="debug"
;;
"--without-sysroot")
build_sysroot=0
;;
"--target-dir")
target_dir=$2
shift
;;
*)
echo "Unknown flag '$1'"
echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR]"
;;
esac
shift
done

# Build cg_clif
export RUSTFLAGS="-Zrun_dsymutil=no"
if [[ "$CHANNEL" == "release" ]]; then
cargo build --release
else
cargo build
fi

rm -rf $target_dir
mkdir $target_dir
cp -a target/$CHANNEL/cg_clif{,_build_sysroot} target/$CHANNEL/*rustc_codegen_cranelift* $target_dir/
cp -a rust-toolchain scripts/config.sh scripts/cargo.sh $target_dir

if [[ "$build_sysroot" == "1" ]]; then
echo "[BUILD] sysroot"
export CG_CLIF_INCR_CACHE_DISABLED=1
dir=$(pwd)
cd $target_dir
time $dir/build_sysroot/build_sysroot.sh
fi
27 changes: 15 additions & 12 deletions compiler/rustc_codegen_cranelift/build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
# Requires the CHANNEL env var to be set to `debug` or `release.`

set -e
cd $(dirname "$0")

pushd ../ >/dev/null
source ./scripts/config.sh
popd >/dev/null
source ./config.sh

# Cleanup for previous run
# v Clean target dir except for build scripts and incremental cache
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true
rm -r sysroot/ 2>/dev/null || true
dir=$(pwd)

# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
# build scripts are still compiled using cg_llvm.
export RUSTC=$(pwd)/../"target/"$CHANNEL"/cg_clif_build_sysroot"
export RUSTC=$dir"/cg_clif_build_sysroot"
export RUSTFLAGS=$RUSTFLAGS" --clif"

cd $(dirname "$0")

# Cleanup for previous run
# v Clean target dir except for build scripts and incremental cache
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true

# We expect the target dir in the default location. Guard against the user changing it.
export CARGO_TARGET_DIR=target

# Build libs
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
if [[ "$1" == "--release" ]]; then
if [[ "$1" != "--debug" ]]; then
sysroot_channel='release'
# FIXME Enable incremental again once rust-lang/rust#74946 is fixed
# FIXME Enable -Zmir-opt-level=2 again once it doesn't ice anymore
Expand All @@ -32,5 +35,5 @@ else
fi

# Copy files to sysroot
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
mkdir -p $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -a target/$TARGET_TRIPLE/$sysroot_channel/deps/* $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

rm -rf $DST_DIR
mkdir -p $DST_DIR/library
cp -r $SRC_DIR/library $DST_DIR/
cp -a $SRC_DIR/library $DST_DIR/

pushd $DST_DIR
echo "[GIT] init"
Expand Down
Loading