Commit graph

213 commits

Author SHA1 Message Date
Camille GILLOT
5f98e5ee56 Simplify DepGraph creation. 2021-06-30 20:31:52 +02:00
Aman Arora
fc273e9bf2 Introduce -Zprofile-closures to evaluate the impact of 2229
This creates a CSV with name "closure_profile_XXXXX.csv", where the
variable part is the process id of the compiler.

To profile a cargo project you can run one of the following depending on
if you're compiling a library or a binary:

```
cargo +stage1 rustc --lib -- -Zprofile-closures
cargo +stage1 rustc --bin -- -Zprofile-closures
```
2021-06-28 14:21:55 -04:00
bors
a1411de9de Auto merge of #86267 - ZuseZ4:master, r=nagisa
Allow loading of llvm plugins on nightly

Based on a discussion in  #82734 / with `@wsmoses.`
Mainly moves [this](0149bc4e7e) behind a -Z flag, so it can only be used on nightly,
as requested by `@nagisa` in https://github.com/rust-lang/rust/issues/82734#issuecomment-835863940

This change allows loading of llvm plugins like Enzyme.
Right now it also requires a shared library LLVM build of rustc for symbol resolution.

```rust
// test.rs
extern { fn __enzyme_autodiff(_: usize, ...) -> f64; }

fn square(x : f64) -> f64 {
   return x * x;
}

fn main() {
   unsafe {
      println!("Hello, world {} {}!", square(3.0), __enzyme_autodiff(square as usize, 3.0));
   }
}
```
```
./rustc test.rs -Z llvm-plugins="./LLVMEnzyme-12.so" -C passes="enzyme"
./test
Hello, world 9 6!
```

I will try to figure out how to simplify the usage and get this into stable in a later iteration,
but having this on nightly will already help testing further steps.
2021-06-26 19:20:41 +00:00
Smitty
bdfcb88e8b Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
Aaron Hill
99f652ff22 Only hash OutputTypes keys in non-crate-hash mode
This effectively turns OutputTypes into a hybrid where keys (OutputType)
are TRACKED and the values (optional paths) are TRACKED_NO_CRATE_HASH.
2021-06-21 17:22:35 -07:00
Jeremy Fitzhardinge
f1f7f2f508 make -Zno-codegen TRACKED_NO_CRATE_HASH 2021-06-21 17:22:35 -07:00
Jeremy Fitzhardinge
48921ce300 Implement assert_non_crate_hash_different for tests 2021-06-21 17:22:35 -07:00
Jeremy Fitzhardinge
a26d99f348 In --emit KIND=PATH options, only hash KIND
The PATH has no material effect on the emitted artifact, and setting
the patch via `-o` or `--out-dir` does not affect the hash.

Closes https://github.com/rust-lang/rust/issues/86044
2021-06-21 17:22:35 -07:00
bors
ed33787335 Auto merge of #85284 - eggyal:custom-profiler-runtime, r=jackh726
Provide option for specifying the profiler runtime

Currently, if `-Zinstrument-coverage` is enabled, the target is linked
against the `library/profiler_builtins` crate (which pulls in LLVM's
compiler-rt runtime).

This option enables backends to specify an alternative runtime crate for
handling injected instrumentation calls.
2021-06-18 04:39:01 +00:00
Manuel Drehwald
4dbdcd1c5c allow loading of llvm plugins on nightly 2021-06-13 18:23:01 +02:00
bors
0a8629bff6 Auto merge of #85885 - bjorn3:remove_box_region, r=cjgillot
Don't use a generator for BoxedResolver

The generator is non-trivial and requires unsafe code anyway. Using regular unsafe code without a generator is much easier to follow.

Based on #85810 as it touches rustc_interface too.
2021-06-11 16:11:20 +00:00
bjorn3
4301d1ee7d Remove unnecessary transmute 2021-06-10 19:36:27 +02:00
bjorn3
2754d4e514 Add safety comments 2021-06-09 14:51:42 +02:00
bjorn3
e1aa45b64d Use explicit drop impl 2021-06-09 14:47:01 +02:00
Camille GILLOT
aeb050da9f Do not require the DefPathTable to construct the on-disk cache. 2021-06-08 22:23:03 +02:00
bjorn3
2bf839e870 Don't require LintStore to live for 'a in configure_and_expand_inner 2021-06-08 19:24:17 +02:00
bjorn3
cf1f92a2ca Revert "Let several methods take &Resolver instead of a BoxedResolver wrapper"
This reverts commit 5343ec338f72a61e2f51f9d90117092c8e8a725a.
2021-06-08 19:24:17 +02:00
bjorn3
5e148200d4 Use a submodule as safety boundary for BoxedResolver 2021-06-08 19:24:17 +02:00
bjorn3
86c2d1a2a7 Don't use a generator for BoxedResolver
The generator is non-trivial and requires unsafe code anyway. Using
regular unsafe code without a generator is much easier to follow.
2021-06-08 19:24:17 +02:00
bjorn3
36bdfdc411 Don't return a BoxedResolver on errors 2021-06-08 19:24:17 +02:00
bjorn3
9d9ccec3fc Inline two more methods 2021-06-08 19:24:17 +02:00
bjorn3
d376f032e6 Let several methods take &Resolver instead of a BoxedResolver wrapper 2021-06-08 19:24:16 +02:00
bjorn3
db4d8e2cab Store boxed metadata loader in CrateLoader 2021-06-08 19:24:16 +02:00
bjorn3
ecc68e7879 Replace Pin::new with .as_mut() 2021-06-08 19:24:16 +02:00
bjorn3
bddf151dea Use more accurate lifetimes 2021-06-08 19:24:16 +02:00
bjorn3
1b7ec34878 Inline PinnedGenerator 2021-06-08 19:24:16 +02:00
bjorn3
99e112d282 Inline the rest of box_region 2021-06-08 19:24:16 +02:00
bjorn3
86b3ebe2da Inline box_region macro calls 2021-06-08 19:24:15 +02:00
bjorn3
8f397bc8a0 Simplify box_region macros 2021-06-08 19:24:15 +02:00
bjorn3
8176ab8bc1 Revert "Merge CrateDisambiguator into StableCrateId"
This reverts commit d0ec85d3fb.
2021-06-07 10:37:45 +02:00
bors
cc9610bf5a Auto merge of #85810 - bjorn3:further_driver_cleanup, r=varkor
Driver improvements

This PR contains a couple of cleanups for the driver and a few small improvements for the custom codegen backend interface. It also implements `--version` and `-Cpasses=list` support for custom codegen backends.
2021-06-07 02:30:24 +00:00
bors
c79419af07 Auto merge of #84449 - alexcrichton:metadata-in-object, r=nagisa
rustc: Store metadata-in-rlibs in object files

This commit updates how rustc compiler metadata is stored in rlibs.
Previously metadata was stored as a raw file that has the same format as
`--emit metadata`. After this commit, however, the metadata is encoded
into a small object file which has one section which is the contents of
the metadata.

The motivation for this commit is to fix a common case where #83730
arises. The problem is that when rustc crates a `dylib` crate type it
needs to include entire rlib files into the dylib, so it passes
`--whole-archive` (or the equivalent) to the linker. The problem with
this, though, is that the linker will attempt to read all files in the
archive. If the metadata file were left as-is (today) then the linker
would generate an error saying it can't read the file. The previous
solution was to alter the rlib just before linking, creating a new
archive in a temporary directory which has the metadata file removed.

This problem from before this commit is now removed if the metadata file
is stored in an object file that the linker can read. The only caveat we
have to take care of is to ensure that the linker never actually
includes the contents of the object file into the final output. We apply
similar tricks as the `.llvmbc` bytecode sections to do this.

This involved changing the metadata loading code a bit, namely updating
some of the LLVM C APIs used to use non-deprecated ones and fiddling
with the lifetimes a bit to get everything to work out. Otherwise though
this isn't intended to be a functional change really, only that metadata
is stored differently in archives now.

This should end up fixing #83730 because by default dylibs will no
longer have their rlib dependencies "altered" meaning that
split-debuginfo will continue to have valid paths pointing at the
original rlibs. (note that we still "alter" rlibs if LTO is enabled to
remove Rust object files and we also "alter" for the #[link(cfg)]
feature, but that's rarely used).

Closes #83730
2021-06-04 19:29:50 +00:00
Alex Crichton
0e0338744d rustc: Store metadata-in-rlibs in object files
This commit updates how rustc compiler metadata is stored in rlibs.
Previously metadata was stored as a raw file that has the same format as
`--emit metadata`. After this commit, however, the metadata is encoded
into a small object file which has one section which is the contents of
the metadata.

The motivation for this commit is to fix a common case where #83730
arises. The problem is that when rustc crates a `dylib` crate type it
needs to include entire rlib files into the dylib, so it passes
`--whole-archive` (or the equivalent) to the linker. The problem with
this, though, is that the linker will attempt to read all files in the
archive. If the metadata file were left as-is (today) then the linker
would generate an error saying it can't read the file. The previous
solution was to alter the rlib just before linking, creating a new
archive in a temporary directory which has the metadata file removed.

This problem from before this commit is now removed if the metadata file
is stored in an object file that the linker can read. The only caveat we
have to take care of is to ensure that the linker never actually
includes the contents of the object file into the final output. We apply
similar tricks as the `.llvmbc` bytecode sections to do this.

This involved changing the metadata loading code a bit, namely updating
some of the LLVM C APIs used to use non-deprecated ones and fiddling
with the lifetimes a bit to get everything to work out. Otherwise though
this isn't intended to be a functional change really, only that metadata
is stored differently in archives now.

This should end up fixing #83730 because by default dylibs will no
longer have their rlib dependencies "altered" meaning that
split-debuginfo will continue to have valid paths pointing at the
original rlibs. (note that we still "alter" rlibs if LTO is enabled to
remove Rust object files and we also "alter" for the #[link(cfg)]
feature, but that's rarely used).

Closes #83730
2021-06-04 10:05:20 -07:00
bjorn3
d96446c53c Use SyncOnceCell in get_codegen_backend
This reduces the amount of unsafe code in get_codegen_backend
2021-06-04 13:20:04 +02:00
bjorn3
1870f9b05f Allow printing the version of the default codegen backend if it isn't llvm 2021-06-04 13:20:04 +02:00
bjorn3
45c9775361 A couple of small cleanups 2021-06-04 13:20:04 +02:00
Yuki Okushi
36f1ed6de2
Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514
Remove unused feature gates

The first commit removes a usage of a feature gate, but I don't expect it to be controversial as the feature gate was only used to workaround a limitation of rust in the past. (closures never being `Clone`)

The second commit uses `#[allow_internal_unstable]` to avoid leaking the `trusted_step` feature gate usage from inside the index newtype macro. It didn't work for the `min_specialization` feature gate though.

The third commit removes (almost) all feature gates from the compiler that weren't used anyway.
2021-06-04 13:42:54 +09:00
Camille GILLOT
ba0ac88cd5 Avoid a clone of output_filenames. 2021-06-01 21:22:55 +02:00
Camille Gillot
0f0f3138cb
Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
bors
41278062c8 Auto merge of #85153 - cjgillot:qresolve, r=Aaron1011
Reduce the amount of untracked state in TyCtxt

Access to untracked global state may generate instances of #84970.

The GlobalCtxt contains the lowered HIR, the resolver outputs and interners.
By wrapping the resolver inside a query, we make sure those accesses are properly tracked.
As a no_hash query, all dependent queries essentially become `eval_always`,
what they should have been from the beginning.
2021-06-01 00:51:00 +00:00
bors
657bc01888 Auto merge of #85702 - Aaron1011:no-vec-sort, r=michaelwoerister
Don't sort a `Vec` before computing its `DepTrackingHash`

Previously, we sorted the vec prior to hashing, making the hash
independent of the original (command-line argument) order. However, the
original vec was still always kept in the original order, so we were
relying on the rest of the compiler always working with it in an
'order-independent' way.

This assumption was not being upheld by the `native_libraries` query -
the order of the entires in its result depends on the order of entries
in `Options.libs`. This lead to an 'unstable fingerprint' ICE when the
`-l` arguments were re-ordered.

This PR removes the sorting logic entirely. Re-ordering command-line
arguments (without adding/removing/changing any arguments) seems like a
really niche use case, and correctly optimizing for it would require
additional work. By always hashing arguments in their original order, we
can entirely avoid a cause of 'unstable fingerprint' errors.
2021-05-31 20:03:18 +00:00
bjorn3
312f964478 Remove unused feature gates 2021-05-31 13:55:43 +02:00
Camille GILLOT
e1e6949558 Avoid a clone of output_filenames. 2021-05-30 19:57:13 +02:00
bjorn3
d0ec85d3fb Merge CrateDisambiguator into StableCrateId 2021-05-30 12:51:34 +02:00
Aaron Hill
605513a513
Don't sort a Vec before computing its DepTrackingHash
Previously, we sorted the vec prior to hashing, making the hash
independent of the original (command-line argument) order. However, the
original vec was still always kept in the original order, so we were
relying on the rest of the compiler always working with it in an
'order-independent' way.

This assumption was not being upheld by the `native_libraries` query -
the order of the entires in its result depends on the order of entries
in `Options.libs`. This lead to an 'unstable fingerprint' ICE when the
`-l` arguments were re-ordered.

This PR removes the sorting logic entirely. Re-ordering command-line
arguments (without adding/removing/changing any arguments) seems like a
really niche use case, and correctly optimizing for it would require
additional work. By always hashing arguments in their original order, we
can entirely avoid a cause of 'unstable fingerprint' errors.
2021-05-25 22:11:39 -05:00
Eric Huss
074d667cf5 Don't panic when failing to initialize incremental directory. 2021-05-25 14:40:33 -07:00
LeSeulArtichaut
af3d9a3aa3 Make thir_check_unsafety itself responsible for checking gate 2021-05-24 15:09:33 +02:00
Alan Egerton
93c636211c
Provide option for specifying the profiler runtime
Currently, if `-Zinstrument-coverage` is enabled, the target is linked
against the `library/profiler_builtins` crate (which pulls in LLVM's
compiler-rt runtime).

This option enables backends to specify an alternative runtime crate for
handling injected instrumentation calls.
2021-05-17 08:31:33 +01:00
bors
3396a383bb Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-17 01:42:03 +00:00
Ralf Jung
c96d531a92 fix version_str comment 2021-05-15 14:22:29 +02:00