about summary refs log tree commit diff
path: root/compiler/rustc_mir/src
AgeCommit message (Collapse)AuthorLines
2021-05-12Use () for codegen queries.Camille GILLOT-10/+8
2021-05-12Use () for mir_keys.Camille GILLOT-7/+6
2021-05-12Use () for entry_fn.Camille GILLOT-1/+1
2021-05-12Use () in reachable_set.Camille GILLOT-5/+7
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-13/+24
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-12Implement span quoting for proc-macrosAaron Hill-3/+6
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-11Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, ↵Rich Kadel-48/+16
r=tmandry" This reverts commit e5f83d24aee866a14753a7cedbb4e301dfe5bef5, reversing changes made to ac888e8675182c703c2cd097957878faf88dad94.
2021-05-11Auto merge of #85100 - HKalbasi:issue-68049-fix, r=Aaron1011bors-10/+82
Fix invalid suggestion of changing impl trait signature Fix #68049
2021-05-11Fix CI problemshamidreza kalbasi-41/+37
2021-05-11Split span_to_string into span_to_diagnostic/embeddable_stringAndy Wang-10/+15
2021-05-10remove big matchhamidreza kalbasi-63/+48
2021-05-10Auto merge of #84507 - crlf0710:codegen_nonlocal_main_wrapper, r=nagisabors-2/+4
Add primary marker on codegen unit and generate main wrapper on primary codegen. This is the codegen part of changes extracted from #84062. This add a marker called `primary` on each codegen units, where exactly one codegen unit will be `primary = true` at a time. This specific codegen unit will take charge of generating `main` wrapper when `main` is imported from a foreign crate after the implementation of RFC 1260. cc #28937 I'm not sure who should i ask for review for codegen changes, so feel free to reassign. r? `@nagisa`
2021-05-10move logic to a functionhamidreza kalbasi-81/+79
2021-05-09Check the ABI of `body.source`hyd-dev-11/+15
2021-05-09Add primary marker on codegen unit to take charge of main_wrapper for ↵Charles Lew-2/+4
non-local cases.
2021-05-09Try to fix issue 68049hamidreza kalbasi-10/+103
2021-05-07Avoid predecessors having Drop implsMark Rousskov-2/+2
2021-05-07Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandrybors-16/+48
Report coverage `0` of dead blocks Fixes: #84018 With `-Z instrument-coverage`, coverage reporting of dead blocks (for example, blocks dropped because a conditional branch is dropped, based on const evaluation) is now supported. If `instrument-coverage` is enabled, `simplify::remove_dead_blocks()` finds all dropped coverage `Statement`s and adds their `code_region`s as `Unreachable` coverage `Statement`s to the `START_BLOCK`, so they are still included in the coverage map. Check out the resulting changes in the test coverage reports in this PR (in [commit 1](https://github.com/rust-lang/rust/pull/84797/commits/0b0d293c7c46bdadf80e5304a667e34c53c0cf7e)). r? `@tmandry` cc: `@wesleywiser`
2021-05-07Rollup merge of #84972 - RalfJung:null-ptr-msg, r=oli-obkYuki Okushi-3/+4
CTFE inbounds-error-messages tweak * use CheckInAllocMsg::PointerArithmeticTest for ptr_offset error * nicer errors for some null pointer cases r? `@oli-obk`
2021-05-07Rollup merge of #84897 - richkadel:cover-closure-macros, r=tmandryYuki Okushi-3/+24
Coverage instruments closure bodies in macros (not the macro body) Fixes: #84884 This solution might be considered a compromise, but I think it is the better choice. The results in the `closure.rs` test correctly resolve all test cases broken as described in #84884. One test pattern (in both `closure_macro.rs` and `closure_macro_async.rs`) was also affected, and removes coverage statistics for the lines inside the closure, because the closure includes a macro. (The coverage remains at the callsite of the macro, so we lose some detail, but there isn't a perfect choice with macros. Often macro implementations are split across the macro and the callsite, and there doesn't appear to be a single "right choice" for which body should be covered. For the current implementation, we can't do both. The callsite is most likely to be the preferred site for coverage. r? `@tmandry` cc: `@wesleywiser`
2021-05-06Coverage instruments closure bodies in macros (not the macro body)Rich Kadel-3/+24
Fixes: #84884 This solution might be considered a compromise, but I think it is the better choice. The results in the `closure.rs` test correctly resolve all test cases broken as described in #84884. One test pattern (in both `closure_macro.rs` and `closure_macro_async.rs`) was also affected, and removes coverage statistics for the lines inside the closure, because the closure includes a macro. (The coverage remains at the callsite of the macro, so we lose some detail, but there isn't a perfect choice with macros. Often macro implementations are split across the macro and the callsite, and there doesn't appear to be a single "right choice" for which body should be covered. For the current implementation, we can't do both. The callsite is most likely to be the preferred site for coverage. I applied this fix to all `MacroKinds`, not just `Bang`. I'm trying to resolve an issue of lost coverage in a `MacroKind::Attr`-based, function-scoped macro. Instead of only searching for a body_span that is "not a function-like macro" (that is, MacroKind::Bang), I'm expanding this to all `MacroKind`s. Maybe I should expand this to `ExpnKind::Desugaring` and `ExpnKind::AstPass` (or subsets, depending on their sub-kinds) as well, but I'm not sure that's a good idea. I'd like to add a test of the `Attr` macro on functions, but I need time to figure out how to constract a good, simple example without external crate dependencies. For the moment, all tests still work as expected (no change), this new commit shouldn't have a negative affect, and more importantly, I believe it will have a positive effect. I will try to confirm this.
2021-05-06use CheckInAllocMsg::PointerArithmeticTest for ptr_offset errorRalf Jung-3/+4
2021-05-05Use local and remapped paths where appropriateAndy Wang-3/+9
2021-05-04CTFE engine: rename copy → copy_intrinsic, move to intrinsics.rsRalf Jung-34/+34
2021-05-02Change 'NULL' to 'null'Brent Kerby-13/+13
2021-05-01add docstrings and add issue to FIXMEsChris Pardy-1/+3
2021-05-01Update compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rsChrisPardy-1/+1
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-05-01Update compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rsChrisPardy-1/+1
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-05-01Update compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rsChrisPardy-2/+2
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-05-01Closure capture borrow diagnostics for disjoint capturesChris Pardy-79/+174
2021-05-01Report coverage `0` of dead blocksRich Kadel-16/+48
Fixes: #84018 With `-Z instrument-coverage`, coverage reporting of dead blocks (for example, blocks dropped because a conditional branch is dropped, based on const evaluation) is now supported. If `instrument-coverage` is enabled, `simplify::remove_dead_blocks()` finds all dropped coverage `Statement`s and adds their `code_region`s as `Unreachable` coverage `Statement`s to the `START_BLOCK`, so they are still included in the coverage map. Check out the resulting changes in the test coverage reports in this PR.
2021-05-01Auto merge of #84582 - richkadel:issue-84561, r=tmandrybors-52/+222
Vastly improves coverage spans for macros Fixes: #84561 This resolves problems where macros like `trace!(...)` would show zero coverage if tracing was disabled, and `assert_eq!(...)` would show zero coverage if the assertion did not fail, because only one coverage span was generated, for the branch. This PR started with an idea that I could just drop branching blocks with same span as expanded macro. (See the fixed issue for more details.) That did help, but it didn't resolve everything. I also needed to add a span specifically for the macro name (plus `!`) to ensure the macro gets coverage even if it's internal expansion adds conditional branching blocks that are retained, and would otherwise drop the outer span. Now that outer span is _only_ the `(argument, list)`, which can safely be dropped now), because the macro name has its own span. While testing, I also noticed the spanview debug output can cause an ICE on a function with no body. The workaround for this is included in this PR (separate commit). r? `@tmandry` cc? `@wesleywiser`
2021-04-30Rebuilt out of date tests and fixed an old bug now exposedRich Kadel-8/+25
2021-04-30Auto merge of #84401 - crlf0710:impl_main_by_path, r=petrochenkovbors-2/+2
Implement RFC 1260 with feature_name `imported_main`. This is the second extraction part of #84062 plus additional adjustments. This (mostly) implements RFC 1260. However there's still one test case failure in the extern crate case. Maybe `LocalDefId` doesn't work here? I'm not sure. cc https://github.com/rust-lang/rust/issues/28937 r? `@petrochenkov`
2021-04-29Auto merge of #84556 - RalfJung:const-fn-trait-bound, r=oli-obkbors-11/+2
use correct feature flag for impl-block-level trait bounds on const fn I am not sure what that special hack was needed for, but it doesn't seem needed any more... This removes the last use of the `const_fn` feature flag -- Cc https://github.com/rust-lang/rust/issues/84510 r? `@oli-obk`
2021-04-29don't let const_fn feature flag affect impl-block-level trait boundsRalf Jung-11/+2
2021-04-28addressed review feedbackRich Kadel-12/+40
2021-04-28spanview debug output caused ICE when a function had no bodyRich Kadel-9/+10
2021-04-28More improvements to macro coverageRich Kadel-51/+112
2021-04-28Drop branching blocks with same span as expanded macroRich Kadel-17/+80
Fixes: #84561
2021-04-29Implement RFC 1260 with feature_name `imported_main`.Charles Lew-2/+2
2021-04-28Remove extra word in `rustc_mir` docspierwill-1/+1
Changes "is includes" to "includes" in `rustc_mir::borrow_check::type_check::type_check`.
2021-04-28Auto merge of #84562 - richkadel:issue-83601, r=tmandrybors-0/+6
Adds feature-gated `#[no_coverage]` function attribute, to fix derived Eq `0` coverage issue #83601 Derived Eq no longer shows uncovered The Eq trait has a special hidden function. MIR `InstrumentCoverage` would add this function to the coverage map, but it is never called, so the `Eq` trait would always appear uncovered. Fixes: #83601 The fix required creating a new function attribute `no_coverage` to mark functions that should be ignored by `InstrumentCoverage` and the coverage `mapgen` (during codegen). Adding a `no_coverage` feature gate with tracking issue #84605. r? `@tmandry` cc: `@wesleywiser`
2021-04-28Auto merge of #83401 - fee1-dead:master, r=davidtwcobors-7/+10
Fix ICE of for-loop mut borrowck where no suggestions are available Fixes #83309.
2021-04-28Rollup merge of #84529 - richkadel:issue-84180, r=tmandryYuki Okushi-1/+11
Improve coverage spans for chained function calls Fixes: #84180 For chained function calls separated by the `?` try operator, the function call following the try operator produced a MIR `Call` span that matched the span of the first call. The `?` try operator started a new span, so the second call got no span. It turns out the MIR `Call` terminator has a `func` `Operand` for the `Constant` representing the function name, and the function name's Span can be used to reset the starting position of the span. r? `@tmandry` cc: `@wesleywiser`
2021-04-27Derived Eq no longer shows uncoveredRich Kadel-0/+6
The Eq trait has a special hidden function. MIR `InstrumentCoverage` would add this function to the coverage map, but it is never called, so the `Eq` trait would always appear uncovered. Fixes: #83601 The fix required creating a new function attribute `no_coverage` to mark functions that should be ignored by `InstrumentCoverage` and the coverage `mapgen` (during codegen). While testing, I also noticed two other issues: * spanview debug file output ICEd on a function with no body. The workaround for this is included in this PR. * `assert_*!()` macro coverage can appear covered if followed by another `assert_*!()` macro. Normally they appear uncovered. I submitted a new Issue #84561, and added a coverage test to demonstrate this issue.
2021-04-27Auto merge of #84532 - richkadel:issue-83792, r=tmandrybors-1/+1
Fix coverage ICE because fn_sig can have a span that crosses file bou… Fixes: #83792 MIR `InstrumentCoverage` assumed the `FnSig` span was contained within a single file, but this is not always the case. Some macro constructions can result in a span that starts in one `SourceFile` and ends in a different one. The `FnSig` span is included in coverage results as long as that span is in the same `SourceFile` and the same macro context, but by assuming the `FnSig` span's `hi()` and `lo()` were in the same file, I took this for granted, and checked only that the `FnSig` `hi()` was in the same `SourceFile` as the `body_span`. I actually drop the `hi()` though, and extend the `FnSig` span to the `body_span.lo()`, so I really should have simply checked that the `FnSig` span's `lo()` was in the `SourceFile` of the `body_span`. r? `@tmandry` cc: `@wesleywiser`
2021-04-25remove now-unused 'is_min_const_fn'Ralf Jung-49/+0
2021-04-25unsafety checking: no longer care about is_min_const_fnRalf Jung-50/+17
Rejecting the forbidden unsafe ops is done by const checking, not by unsafety checking
2021-04-24Improve spans for chained function callsRich Kadel-1/+11
Fixes: #84180 For chained function calls separated by the `?` try operator, the function call following the try operator produced a MIR `Call` span that matched the span of the first call. The `?` try operator started a new span, so the second call got no span. It turns out the MIR `Call` terminator has a `func` `Operand` for the `Constant` representing the function name, and the function name's Span can be used to reset the starting position of the span.