about summary refs log tree commit diff
path: root/compiler/rustc_interface/src/passes.rs
AgeCommit message (Collapse)AuthorLines
2021-06-08Store boxed metadata loader in CrateLoaderbjorn3-2/+2
2021-06-08Replace Pin::new with .as_mut()bjorn3-3/+5
2021-06-08Use more accurate lifetimesbjorn3-8/+6
2021-06-08Inline PinnedGeneratorbjorn3-42/+29
2021-06-08Inline the rest of box_regionbjorn3-22/+79
2021-06-08Inline box_region macro callsbjorn3-5/+77
2021-06-08Simplify box_region macrosbjorn3-2/+1
2021-06-07Revert "Merge CrateDisambiguator into StableCrateId"bjorn3-8/+4
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
2021-06-04rustc: Store metadata-in-rlibs in object filesAlex Crichton-1/+1
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-01Avoid a clone of output_filenames.Camille GILLOT-1/+1
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-1/+1
2021-05-30Avoid a clone of output_filenames.Camille GILLOT-1/+1
2021-05-30Merge CrateDisambiguator into StableCrateIdbjorn3-4/+8
2021-05-25Don't panic when failing to initialize incremental directory.Eric Huss-1/+1
2021-05-24Make `thir_check_unsafety` itself responsible for checking gateLeSeulArtichaut-3/+2
2021-05-17Auto merge of #85178 - cjgillot:local-crate, r=oli-obkbors-12/+9
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-13Auto merge of #83129 - LeSeulArtichaut:thir-unsafeck, r=nikomatsakisbors-1/+5
Introduce the beginning of a THIR unsafety checker This poses the foundations for the THIR unsafety checker, so that it can be implemented incrementally: - implements a rudimentary `Visitor` for the THIR (which will definitely need some tweaking in the future) - introduces a new `-Zthir-unsafeck` flag which tells the compiler to use THIR unsafeck instead of MIR unsafeck - implements detection of unsafe functions - adds revisions to the UI tests to test THIR unsafeck alongside MIR unsafeck This uses a very simple query design, where bodies are unsafety-checked on a body per body basis. This however has some big flaws: - the unsafety-checker builds the THIR itself, which means a lot of work is duplicated with MIR building constructing its own copy of the THIR - unsafety-checking closures is currently completely wrong: closures should take into account the "safety context" in which they are created, here we are considering that closures are always a safe context I had intended to fix these problems in follow-up PRs since they are always gated under the `-Zthir-unsafeck` flag (which is explicitely noted to be unsound). r? `@nikomatsakis` cc https://github.com/rust-lang/project-thir-unsafeck/issues/3 https://github.com/rust-lang/project-thir-unsafeck/issues/7
2021-05-12Use () for analysis.Camille GILLOT-4/+2
2021-05-12Use () for privacy.Camille GILLOT-2/+2
2021-05-12Use () for proc_macro_decls_static.Camille GILLOT-1/+3
2021-05-12Use () for plugin_registrar_fn.Camille GILLOT-3/+1
2021-05-12Use () for entry_fn.Camille GILLOT-2/+1
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-10/+6
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12Auto merge of #83610 - bjorn3:driver_cleanup, r=cjgillotbors-9/+5
rustc_driver cleanup Best reviewed one commit at a time.
2021-05-11Introduce the (WIP) THIR unsafety checkerLeSeulArtichaut-1/+5
2021-05-05Use local and remapped paths where appropriateAndy Wang-9/+1
2021-05-05Use local name if available in write_out_depsAndy Wang-10/+14
2021-05-05Rename RealFileName::Named to LocalPath and Devirtualized to RemappedAndy Wang-4/+4
2021-05-02Let load_query_result_cache take a &DefPathTablebjorn3-9/+5
This allows removing a confusing mem::replace in create_global_ctxt
2021-04-04Rollup merge of #73945 - est31:unused_externs, r=Mark-SimulacrumDylan DPC-0/+7
Add an unstable --json=unused-externs flag to print unused externs This adds an unstable flag to print a list of the extern names not used by cargo. This PR will enable cargo to collect unused dependencies from all units and provide warnings. The companion PR to cargo is: https://github.com/rust-lang/cargo/pull/8437 The goal is eventual stabilization of this flag in rustc as well as in cargo. Discussion of this feature is mostly contained inside these threads: #57274 #72342 #72603 The feature builds upon the internal datastructures added by #72342 Externs are uniquely identified by name and the information is sufficient for cargo. If the mode is enabled, rustc will print json messages like: ``` {"unused_extern_names":["byteorder","openssl","webpki"]} ``` For a crate that got passed byteorder, openssl and webpki dependencies but needed none of them. ### Q: Why not pass -Wunused-crate-dependencies? A: See [ehuss's comment here](https://github.com/rust-lang/rust/issues/57274#issuecomment-624839355) TLDR: it's cleaner. Rust's warning system wasn't built to be filtered or edited by cargo. Even a basic implementation of the feature would have to change the "n warnings emitted" line that rustc prints at the end. Cargo ideally wants to synthesize its own warnings anyways. For example, it would be hard for rustc to emit warnings like "dependency foo is only used by dev targets", suggesting to make it a dev-dependency instead. ### Q: Make rustc emit used or unused externs? A: Emitting used externs has the advantage that it simplifies cargo's collection job. However, emitting unused externs creates less data to be communicated between rustc and cargo. Often you want to paste a cargo command obtained from `cargo build -vv` for doing something completely unrelated. The message is emitted always, even if no warning or error is emitted. At that point, even this tiny difference in "noise" matters. That's why I went with emitting unused externs. ### Q: One json msg per extern or a collective json msg? A: Same as above, the data format should be concise. Having 30 lines for the 30 crates a crate uses would be disturbing to readers. Also it helps the cargo implementation to know that there aren't more unused deps coming. ### Q: Why use names of externs instead of e.g. paths? A: Names are both sufficient as well as neccessary to uniquely identify a passed `--extern` arg. Names are sufficient because you *must* pass a name when passing an `--extern` arg. Passing a path is optional on the other hand so rustc might also figure out a crate's location from the file system. You can also put multiple paths for the same extern name, via e.g. `--extern hello=/usr/lib/hello.rmeta --extern hello=/usr/local/lib/hello.rmeta`, but rustc will only ever use one of those paths. Also, paths don't identify a dependency uniquely as it is possible to have multiple different extern names point to the same path. So paths are ill-suited for identification. ### Q: What about 2015 edition crates? A: They are fully supported. Even on the 2015 edition, an explicit `--extern` flag is is required to enable `extern crate foo;` to work (outside of sysroot crates, which this flag doesn't warn about anyways). So the lint would still fire on 2015 edition crates if you haven't included a dependency specified in Cargo.toml using `extern crate foo;` or similar. The lint won't fire if your sole use in the crate is through a `extern crate foo;` statement, but that's not its job. For detecting unused `extern crate foo` statements, there is the `unused_extern_crates` lint which can be enabled by `#![warn(unused_extern_crates)]` or similar. cc ```@jsgf``` ```@ehuss``` ```@petrochenkov``` ```@estebank```
2021-03-30Stream the dep-graph to a file.Camille GILLOT-3/+0
2021-03-29Don't duplicate the extern providers once for each cratebjorn3-8/+1
2021-03-08Rollup merge of #82415 - petrochenkov:modin3, r=davidtwcoDylan DPC-2/+4
expand: Refactor module loading This is an accompanying PR to https://github.com/rust-lang/rust/pull/82399, but they can be landed independently. See individual commits for more details. Anyone should be able to review this equally well because all people actually familiar with this code left the project.
2021-03-08Rollup merge of #82047 - the8472:fast-rename, r=davidtwcoDylan DPC-1/+1
bypass auto_da_alloc for metadata files This saves about 0.7% when rerunning the UI test suite. I.e. when the metadata files exist and will be overwritten. No improvements expected for a clean build. So it might show up in incr-patched perf results. ``` regular rename: Benchmark #1: touch src/tools/compiletest/src/main.rs ; RUSTC_WRAPPER="" schedtool -B -e ./x.py test src/test/ui Time (mean ± σ): 47.305 s ± 0.170 s [User: 1631.540 s, System: 412.648 s] Range (min … max): 47.125 s … 47.856 s 20 runs non-durable rename: Benchmark #1: touch src/tools/compiletest/src/main.rs ; RUSTC_WRAPPER="" schedtool -B -e ./x.py test src/test/ui Time (mean ± σ): 46.930 s ± 0.064 s [User: 1634.344 s, System: 396.038 s] Range (min … max): 46.759 s … 47.043 s 20 runs ``` There are more places that trigger auto_da_alloc behavior by overwriting existing files with O_TRUNC, but those are much harder to locate because `O_TRUNC` is set on `open()` but the writeback is triggered on `close()`. The latter is the part which shows up in profiles.
2021-03-08Emit the lint level of the unused-crate-dependenciesest31-0/+7
Also, turn off the lint when the unused dependencies json flag is specified so that cargo doesn't have to supress the lint
2021-03-05rustc_interface: Hide some hacky details of early linting from expandVadim Petrochenkov-2/+4
2021-02-25Rollup merge of #82269 - LeSeulArtichaut:cleanup-ppmode, r=spastorinoAaron Hill-1/+1
Cleanup `PpMode` and friends This PR: - Separates `PpSourceMode` and `PpHirMode` to remove invalid states - Renames the variant to remove the redundant `Ppm` prefix - Adds basic documentation for the different pretty-print modes - Cleanups some code to make it more idiomatic Not sure if this is actually useful, but it looks cleaner to me.
2021-02-19Move the query system to rustc_query_impl.Camille GILLOT-4/+4
2021-02-19Make QueryEngine opaque to TyCtxt.Camille GILLOT-9/+17
2021-02-19Cleanup `PpMode` and friendsLeSeulArtichaut-1/+1
2021-02-18Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.Eduard-Mihai Burtescu-3/+3
2021-02-15Index Modules using their LocalDefId.Camille GILLOT-11/+8
2021-02-13bypass auto_da_alloc for metadata filesThe8472-1/+1
2021-01-28Rollup merge of #81284 - jyn514:impl-times, r=wesleywiserYuki Okushi-5/+12
Make `-Z time-passes` less noisy - Add the module name to `pre_AST_expansion_passes` and don't make it a verbose event (since it normally doesn't take very long, and it's emitted many times) - Don't make the following rustdoc events verbose; they're emitted many times. + build_extern_trait_impl + build_local_trait_impl + build_primitive_trait_impl + get_auto_trait_impls + get_blanket_trait_impls - Remove the `get_auto_trait_and_blanket_synthetic_impls` rustdoc event; it's wholly covered by get_{auto,blanket}_trait_impls and not very useful. I found this while working on https://github.com/rust-lang/rust/pull/81275 but it's independent of those changes.
2021-01-23Make `-Z time-passes` less noisyJoshua Nelson-5/+12
- Add the module name to `pre_AST_expansion_passes` and don't make it a verbose event (since it normally doesn't take very long, and it's emitted many times) - Don't make the following rustdoc events verbose; they're emitted many times. + build_extern_trait_impl + build_local_trait_impl + build_primitive_trait_impl + get_auto_trait_impls + get_blanket_trait_impls - Remove `get_auto_trait_and_blanket_synthetic_impls`; it's wholly covered by get_{auto,blanket}_trait_impls and not very useful.
2021-01-23Calculate self-profile strings in `Compiler::enter` instead in codegenJoshua Nelson-7/+0
This avoids each tool having to separately find and call `self_profile_alloc_strings`. - Don't compute the global context if it hasn't yet been computed This avoids giving extraneous errors about unresolved names if an error occurs during parsing.
2021-01-12Remove DepKind::CrateMetadata and pre-allocation of DepNodesTyson Nottingham-6/+0
Remove much of the special-case handling around crate metadata dependency tracking by replacing `DepKind::CrateMetadata` and the pre-allocation of corresponding `DepNodes` with on-demand invocation of the `crate_hash` query.
2021-01-10resolve: Simplify built-in macro tableVadim Petrochenkov-1/+1
2020-12-29Remove `compile-fail` test suiteVadim Petrochenkov-1/+1
2020-12-28Rollup merge of #79662 - bjorn3:move_more_code_out_of_codegen_backend, r=oli-obkDylan DPC-0/+17
Move some more code out of CodegenBackend::{codegen_crate,link} Kind of a follow up to #77795