about summary refs log tree commit diff
path: root/compiler/rustc_session
AgeCommit message (Collapse)AuthorLines
2021-05-12Auto merge of #83610 - bjorn3:driver_cleanup, r=cjgillotbors-1/+5
rustc_driver cleanup Best reviewed one commit at a time.
2021-05-12Implement span quoting for proc-macrosAaron Hill-0/+14
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2021-05-11Introduce the (WIP) THIR unsafety checkerLeSeulArtichaut-0/+2
2021-05-11Fix typo in variable nameLingMan-2/+2
All other sibling functions call this variable "slot", so "slote" was most likely a typo.
2021-05-10Rollup merge of #85152 - nagisa:target-search-rustlib, r=Mark-SimulacrumGuillaume Gomez-53/+15
Adjust target search algorithm for rustlib path With this the concerns expressed in #83800 should be addressed. r? `@Mark-Simulacrum`
2021-05-10Adjust target search algorithm for rustlib pathSimonas Kazlauskas-53/+15
With this the concerns expressed in #83800 should be addressed.
2021-05-10rustc_session: Use `Iterator::find` instead of manual searchVadim Petrochenkov-24/+19
2021-05-10rustc_session: Move more option building code from the `options!` macroVadim Petrochenkov-66/+87
2021-05-09Auto merge of #83800 - xobs:impl-16351-nightly, r=nagisabors-8/+14
Add default search path to `Target::search()` The function `Target::search()` accepts a target triple and returns a `Target` struct defining the requested target. There is a `// FIXME 16351: add a sane default search path?` comment that indicates it is desirable to include some sort of default. This was raised in https://github.com/rust-lang/rust/issues/16351 which was closed without any resolution. https://github.com/rust-lang/rust/pull/31117 was proposed, however that has platform-specific logic that is unsuitable for systems without `/etc/`. This patch implements the suggestion raised in https://github.com/rust-lang/rust/issues/16351#issuecomment-180878193 where a `target.json` file may be placed in `$(rustc --print sysroot)/lib/rustlib/<target-triple>/target.json`. This allows shipping a toolchain distribution as a single file that gets extracted to the sysroot.
2021-05-09Auto merge of #83894 - nikic:newpm, r=nagisabors-1/+1
Improve support for NewPM This adds various missing bits of support for NewPM and allows us to successfully run stage 2 tests with NewPM enabled. This does not yet enable NewPM by default, as there are still known issue on LLVM 12 (such as a weak fat LTO pipeline). The plan is to make the switch after we update to LLVM 13.
2021-05-08Remove unused `opt_span_warn` functionJoshua Nelson-6/+0
2021-05-08Make `Diagnostic::span_fatal` unconditionally raise an errorJoshua Nelson-3/+3
It had no callers which didn't immediately call `raise()`, and this unifies the behavior with `Session`.
2021-05-08Make -Z new-llvm-pass-manager an Option<bool>Nikita Popov-1/+1
To allow it to have an LLVM version dependent default.
2021-05-07Rollup merge of #84815 - richkadel:coverage-docs-update-2021-05, r=tmandryYuki Okushi-6/+6
Update coverage docs and command line help r? `@tmandry` cc: `@wesleywiser`
2021-05-06Update coverage docs and command line helpRich Kadel-6/+6
2021-05-05Implement RFC 2951: Native link modifiersLuqman Aden-47/+143
This commit implements both the native linking modifiers infrastructure as well as an initial attempt at the individual modifiers from the RFC. It also introduces a feature flag for the general syntax along with individual feature flags for each modifier.
2021-05-05Rollup merge of #84803 - jyn514:duplicate-macros, r=petrochenkovRalf Jung-57/+61
Reduce duplication in `impl_dep_tracking_hash` macros Cherry-picked from https://github.com/rust-lang/rust/pull/84234 since it will be a while until it lands.
2021-05-05Add -Z simulate-remapped-rust-src-base option to simulate path ↵Andy Wang-0/+3
virutalisation during bootstrapping
2021-05-05Use RealFileName for Session::working_dir as it may also be remappedAndy Wang-5/+9
2021-05-03Rollup merge of #84072 - nagisa:target-family-two-the-movie, r=petrochenkovDylan DPC-1/+1
Allow setting `target_family` to multiple values, and implement `target_family="wasm"` As per the conclusion in [this thread](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Are.20we.20comfortable.20with.20adding.20an.20insta-stable.20cfg.28wasm.29.3F/near/233158441), this implements an ability to specify any number of `target_family` values, allowing for more flexible generic groups, or "families", to be created than just the OS-based unix/windows dichotomy. cc https://github.com/rust-lang/reference/pull/1006
2021-05-02Remove dummy_configbjorn3-1/+5
2021-05-02Fix nit in rustc_session::optionsJoshua Nelson-1/+1
2021-05-01Reduce duplication in `impl_dep_tracking_hash` macrosJoshua Nelson-57/+61
2021-05-01Remove unused macro parametersJoshua Nelson-3/+3
2021-05-01Remove unused `parse_pathbuf_push` functionJoshua Nelson-12/+0
This also remove the `allow(dead_code)`.
2021-05-01Don't recompile the same functions for each debugging optionJoshua Nelson-412/+461
This reduces the amount of items in the crate by quite a lot.
2021-05-01Remove unused parse_opt_list functionJoshua Nelson-13/+0
2021-04-29Use doc-comment instad of comments consistentlyJoshua Nelson-58/+59
This makes the comments show up in the generated docs. - Fix markdown formatting
2021-04-27Make `real_rust_path_dir` a TRACKED_NO_CRATE_HASH optionJoshua Nelson-33/+45
This also adds support for doc-comments to Options.
2021-04-27Add [TRACKED_NO_CRATE_HASH] and [SUBSTRUCT] directivesJoshua Nelson-24/+62
This is necessary for options that should invalidate the incremental hash but *not* affect the crate hash (e.g. --remap-path-prefix). This doesn't add `for_crate_hash` to the trait directly because it's not relevant for *types*, only for *options*, which are fields on a larger struct. Instead, it adds a new `SUBSTRUCT` directive for options, which does take a `for_crate_hash` parameter. - Use TRACKED_NO_CRATE_HASH for --remap-path-prefix - Add test that `remap_path_prefix` is tracked - Reduce duplication in the test suite to avoid future churn
2021-04-27Test that non_default_option is not the default optionJoshua Nelson-4/+4
Otherwise the test is useless and does nothing. This caught 2 bugs in the test suite.
2021-04-25Rollup merge of #83519 - oli-obk:assign_shrink_your_normal_code, r=pnkfelixYuki Okushi-0/+16
Implement a lint that highlights all moves larger than a configured limit Tracking issue: #83518 [MCP 420](https://github.com/rust-lang/compiler-team/issues/420) still ~blazing~ in progress r? ```@pnkfelix``` The main open issue I see with this minimal impl of the feature is that the lint is immediately "stable" (so it can be named on stable), even if it is never executed on stable. I don't think we have the concept of unstable lint names or hiding lint names without an active feature gate, so that would be a bigger change.
2021-04-25Merge remote-tracking branch 'upstream/master' into impl-16351-nightlySean Cross-282/+270
Signed-off-by: Sean Cross <sean@xobs.io>
2021-04-24Rollup merge of #84436 - jyn514:private, r=petrochenkovYuki Okushi-2/+2
Make a few functions private These were made public in 3105bcfdc11030abf9855af7a693cbf904460813. This is so long ago I doubt anyone remembers why they're public. No one outside rustc_session uses them, including in-tree tools.
2021-04-23Remove unstable `--pretty` flagJoshua Nelson-80/+41
It doesn't do anything `--unpretty` doesn't, and due to a bug, also didn't show up in `--help`. I don't think there's any reason to keep it around, I haven't seen anyone using it.
2021-04-22Make a few functions privateJoshua Nelson-2/+2
These were made public in 3105bcfdc11030abf9855af7a693cbf904460813. This is so long ago I doubt anyone remembers why they're public. No one uses them, including in-tree tools.
2021-04-20Add an attribute to be able to configure the limitOli Scherer-0/+16
2021-04-20Improve the docstrings of the `Lto` struct.Edd Barrett-5/+7
2021-04-15Track `-C link-dead-code` during incremental compilationAaron Hill-1/+1
This option influences monomorphization, which participates in incremental compilation.
2021-04-11Allow using `-C force-unwind-tables=no` when `panic=unwind`hyd-dev-16/+9
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-0/+55
This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-11Allow setting `target_family` to multiple valuesSimonas Kazlauskas-1/+1
This enables us to set more generic labels shared between targets. For example `target_family="wasm"` across all targets that are conceptually "wasm". See https://github.com/rust-lang/reference/pull/1006
2021-04-10Don't tell users to use a nightly flag on the stable channelKornel-8/+11
Hint upgrading to a newer Rust version instead
2021-04-07Remove the insta-stable `cfg(wasm)`Simonas Kazlauskas-3/+0
The addition of `cfg(wasm)` was an oversight on my end that has a number of downsides: * It was introduced as an insta-stable addition, forgoing the usual staging mechanism we use for potentially far-reaching changes; * It is a breaking change for people who are using `--cfg wasm` either directly or via cargo for other purposes; * It is not entirely clear if a bare `wasm` cfg is a right option or whether `wasm` family of targets are special enough to warrant special-casing these targets specifically. As for the last point, there appears to be a fair amount of support for reducing the boilerplate in specifying architectures from the same family, while ignoring their pointer width. The suggested way forward would be to propose such a change as a separate RFC as it is potentially a quite contentious addition.
2021-04-05Rollup merge of #82483 - tmiasko:option-from-str, r=matthewjasperDylan DPC-14/+15
Use FromStr trait for number option parsing Replace `parse_uint` with generic `parse_number` based on `FromStr`. Use it for parsing inlining threshold to avoid casting later.
2021-04-05Rollup merge of #80525 - devsnek:wasm64, r=nagisaDylan DPC-0/+3
wasm64 support There is still some upstream llvm work needed before this can land.
2021-04-04Rollup merge of #73945 - est31:unused_externs, r=Mark-SimulacrumDylan DPC-3/+35
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-04-04wasm64Gus Caplan-0/+3
2021-04-03compiler: run `python3 ./x.py fmt`Sean Cross-2/+7
This fixes a build issue with formatting as part of #83800. Signed-off-by: Sean Cross <sean@xobs.io>
2021-04-03rustc: target: add sysroot to rust_target_pathSean Cross-8/+9
This enables placing a `target.json` file into the rust sysroot under the target-specific directory. Signed-off-by: Sean Cross <sean@xobs.io>