about summary refs log tree commit diff
path: root/src/librustc_mir/transform
AgeCommit message (Collapse)AuthorLines
2020-06-15moved instrument_coverage pass, optimized scalar, added FIXMERich Kadel-13/+22
2020-06-15moved to post_borrowck_cleanup & used MirPatchRich Kadel-56/+62
2020-06-15[WIP] injects llvm intrinsic instrprof.increment for coverage reportsRich Kadel-0/+103
This initial version only injects counters at the top of each function. Rust Coverage will require injecting additional counters at each conditional code branch.
2020-06-15Auto merge of #73369 - RalfJung:rollup-hl8g9zf, r=RalfJungbors-15/+7
Rollup of 10 pull requests Successful merges: - #72707 (Use min_specialization in the remaining rustc crates) - #72740 (On recursive ADT, provide indirection structured suggestion) - #72879 (Miri: avoid tracking current location three times) - #72938 (Stabilize Option::zip) - #73086 (Rename "cyclone" to "apple-a7" per changes in upstream LLVM) - #73104 (Example about explicit mutex dropping) - #73139 (Add methods to go from a nul-terminated Vec<u8> to a CString) - #73296 (Remove vestigial CI job msvc-aux.) - #73304 (Revert heterogeneous SocketAddr PartialEq impls) - #73331 (extend network support for HermitCore) Failed merges: r? @ghost
2020-06-15Rollup merge of #72879 - RalfJung:miri-tctx-at, r=oli-obkRalf Jung-15/+7
Miri: avoid tracking current location three times Miri tracks the current instruction to execute in the call stack, but it also additionally has two `TyCtxtAt` that carry a `Span` that also tracks the current instruction. That is quite silly, so this PR uses `TyCtxt` instead, and then uses a method for computing the current span when a `TyCtxtAt` is needed. Having less redundant (semi-)global state seems like a good improvement to me. :D To keep the ConstProp errors the same, I had to add the option to `error_to_const_error` to overwrite the span. Also for some reason this changes cycle errors a bit -- not sure if we are now better or worse as giving those queries the right span. (It is unfortunately quite easy to accidentally use `DUMMY_SP` by calling the query on a `TyCtxt` instead of a `TyCtxtAt`.) r? @oli-obk @eddyb
2020-06-15Rollup merge of #72389 - Aaron1011:feature/move-fn-self-msg, r=nikomatsakisRalf Jung-0/+1
Explain move errors that occur due to method calls involving `self` When calling a method that takes `self` (e.g. `vec.into_iter()`), the method receiver is moved out of. If the method receiver is used again, a move error will be emitted:: ```rust fn main() { let a = vec![true]; a.into_iter(); a; } ``` emits ``` error[E0382]: use of moved value: `a` --> src/main.rs:4:5 | 2 | let a = vec![true]; | - move occurs because `a` has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait 3 | a.into_iter(); | - value moved here 4 | a; | ^ value used here after move ``` However, the error message doesn't make it clear that the move is caused by the call to `into_iter`. This PR adds additional messages to move errors when the move is caused by using a value as the receiver of a `self` method:: ``` error[E0382]: use of moved value: `a` --> vec.rs:4:5 | 2 | let a = vec![true]; | - move occurs because `a` has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait 3 | a.into_iter(); | ------------- value moved due to this method call 4 | a; | ^ value used here after move | note: this function takes `self`, which moves the receiver --> /home/aaron/repos/rust/src/libcore/iter/traits/collect.rs:239:5 | 239 | fn into_iter(self) -> Self::IntoIter; ``` TODO: - [x] Add special handling for `FnOnce/FnMut/Fn` - we probably don't want to point at the unstable trait methods - [x] Consider adding additional context for operations (e.g. `Shr::shr`) when the call was generated using the operator syntax (e.g. `a >> b`) - [x] Consider pointing to the method parent (impl or trait block) in addition to the method itself.
2020-06-15Rollup merge of #71824 - ecstatic-morse:const-check-post-drop-elab, r=oli-obkRalf Jung-34/+192
Check for live drops in constants after drop elaboration Resolves #66753. This PR splits the MIR "optimization" pass series in two and introduces a query–`mir_drops_elaborated_and_const_checked`–that holds the result of the `post_borrowck_cleanup` analyses and checks for live drops. This query is invoked in `rustc_interface` for all items requiring const-checking, which means we now do `post_borrowck_cleanup` for items even if they are unused in the crate. As a result, we are now more precise about when drops are live. This is because drop elaboration can e.g. eliminate drops of a local when all its fields are moved from. This does not mean we are doing value-based analysis on move paths, however; Storing a `Some(CustomDropImpl)` into a field of a local will still set the qualifs for that entire local. r? @oli-obk
2020-06-14validator: print MIR instance on failureJonas Schievink-6/+4
2020-06-14Diagnose use of incompatible sanitizersTomasz Miąsko-19/+2
Emit an error when incompatible sanitizer are configured through command line options. Previously the last one configured prevailed and others were silently ignored. Additionally use a set to represent configured sanitizers, making it possible to enable multiple sanitizers at once. At least in principle, since currently all of them are considered to be incompatible with others.
2020-06-14Don't run generator transform when there's a TyErrJonas Schievink-1/+5
2020-06-13Add MIR phase and query for drop elaborationDylan MacKenzie-9/+40
2020-06-13Add `CheckLiveDrops` passDylan MacKenzie-0/+126
2020-06-13Make `Qualifs` getters publicDylan MacKenzie-3/+3
2020-06-13Move `check_op` logic to `ops` moduleDylan MacKenzie-22/+23
2020-06-13Rollup merge of #73066 - ecstatic-morse:query-structural-eq2, r=pnkfelixDylan DPC-5/+1
Querify whether a type has structural equality (Take 2) Alternative to #72177. Unlike in #72177, this helper method works for all types, falling back to a query for `TyKind::Adt`s that determines whether the `{Partial,}StructuralEq` traits are implemented. This is my preferred interface for this method. I think this is better than just documenting that the helper only works for ADTs. If others disagree, we can just merge #72177 with the fixes applied. This has already taken far too long.
2020-06-12Helper method for whether type has structural equalityDylan MacKenzie-5/+1
This helper method works for all types, falling back to a query for `TyKind::Adt`s to determine whether the implement the `{Partial,}StructuralEq` traits.
2020-06-12Disable the `SimplifyArmIdentity` pass on betaWesley Wiser-1/+5
This pass is buggy so I'm disabling it to fix a stable-to-beta regression. Related to #73223
2020-06-12fix const_prop spans and re-bless testsRalf Jung-7/+2
2020-06-12make miri InterpCx TyCtxtAt a TyCtxt, and separately remember the root span ↵Ralf Jung-9/+6
of the evaluation
2020-06-11Explain move errors that occur due to method calls involving `self`Aaron Hill-0/+1
2020-06-11Rollup merge of #73182 - Aaron1011:feature/call-fn-span, r=matthewjasperDylan DPC-2/+10
Track span of function in method calls, and use this in #[track_caller] Fixes #69977 When we parse a chain of method calls like `foo.a().b().c()`, each `MethodCallExpr` gets assigned a span that starts at the beginning of the call chain (`foo`). While this is useful for diagnostics, it means that `Location::caller` will return the same location for every call in a call chain. This PR makes us separately record the span of the function name and arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This `Span` is passed through HIR lowering and MIR building to `TerminatorKind::Call`, where it is used in preference to `Terminator.source_info.span` when determining `Location::caller`. This new span is also useful for diagnostics where we want to emphasize a particular method call - for an example, see https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-11Rollup merge of #73172 - matthiaskrgr:cl9ppy, r=Dylan-DPCDylan DPC-5/+5
Fix more clippy warnings Fixes more of: clippy::unused_unit clippy::op_ref clippy::useless_format clippy::needless_return clippy::useless_conversion clippy::bind_instead_of_map clippy::into_iter_on_ref clippy::redundant_clone clippy::nonminimal_bool clippy::redundant_closure clippy::option_as_ref_deref clippy::len_zero clippy::iter_cloned_collect clippy::filter_next r? @Dylan-DPC
2020-06-10Track span of function in method calls, and use this in #[track_caller]Aaron Hill-2/+10
Fixes #69977 When we parse a chain of method calls like `foo.a().b().c()`, each `MethodCallExpr` gets assigned a span that starts at the beginning of the call chain (`foo`). While this is useful for diagnostics, it means that `Location::caller` will return the same location for every call in a call chain. This PR makes us separately record the span of the function name and arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This `Span` is passed through HIR lowering and MIR building to `TerminatorKind::Call`, where it is used in preference to `Terminator.source_info.span` when determining `Location::caller`. This new span is also useful for diagnostics where we want to emphasize a particular method call - for an example, see https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-10Rollup merge of #73133 - doctorn:unwind-mir-validation, r=jonas-schievinkDylan DPC-19/+48
Enforce unwind invariants I had a quick look at #72959. The failure message probably needs to be more detailed but I just wanted to check I got the right idea. I have no idea how to right a test for this either... r? @jonas-schievink Resolves #72959 (hypothetically)
2020-06-09Fix more clippy warningsMatthias Krüger-5/+5
Fixes more of: clippy::unused_unit clippy::op_ref clippy::useless_format clippy::needless_return clippy::useless_conversion clippy::bind_instead_of_map clippy::into_iter_on_ref clippy::redundant_clone clippy::nonminimal_bool clippy::redundant_closure clippy::option_as_ref_deref clippy::len_zero clippy::iter_cloned_collect clippy::filter_next
2020-06-09Stop allowing `Indirect(..)` values to be propagatedWesley Wiser-1/+0
Closes #72679 Closes #72372 Closes #72285
2020-06-09Address commentsNathan Corbyn-19/+26
2020-06-08Revert #71956Dylan MacKenzie-127/+136
2020-06-08Strengthen cleanup to cleanup checkNathan Corbyn-16/+16
2020-06-08Relax cleanup to cleanup checkNathan Corbyn-2/+2
2020-06-08Enforce unwind invariantsNathan Corbyn-19/+41
2020-06-07Don't intern memory in const prop.Oliver Scherer-8/+4
This isn't sound without validation. We don't want to report errors in case of failure to intern and validate, we just don't want to const prop. Interning and const prop is not built for this, let's not do it until we have a clearer picture on aggregate propagation.
2020-06-07Rollup merge of #72908 - RalfJung:false-edge, r=matthewjasperDylan DPC-9/+9
rename FalseEdges -> FalseEdge There's just a single false edge in this terminator, not multiple of them. r? @matthewjasper @jonas-schievink
2020-06-07Rollup merge of #72764 - jonas-schievink:mind-the-tyerr, r=estebankDylan DPC-26/+43
Be more careful around ty::Error in generators cc https://github.com/rust-lang/rust/issues/72685 (doesn't close it because it's missing a reproduction to use as a test case) r? @estebank
2020-06-07rename FalseEdges -> FalseEdgeRalf Jung-9/+9
2020-06-07Rollup merge of #72810 - RalfJung:mir-terminate-sanity, r=jonas-schievinkDylan DPC-15/+120
validate basic sanity for TerminatorKind r? @jonas-schievink This mainly checks that all `BasicBlock` actually exist. On top of that, it checks that `Call` actually calls something of `FnPtr`/`FnDef` type, and `Assert` has to work on a `bool`. Also `SwitchInt` cannot have an empty target list.
2020-06-03Rollup merge of #72820 - jonas-schievink:instcombine-uninit, r=oli-obkDylan DPC-10/+8
InstCombine: Don't optimize `&mut *x` into `x` Fixes https://github.com/rust-lang/rust/issues/72797
2020-06-01test miri-unleash TLS accessesRalf Jung-10/+1
2020-06-01Auto merge of #71192 - oli-obk:eager_alloc_id_canonicalization, r=wesleywiserbors-6/+15
Make TLS accesses explicit in MIR r? @rust-lang/wg-mir-opt cc @RalfJung @vakaras for miri thread locals cc @bjorn3 for cranelift fixes #70685
2020-05-31InstCombine: Don't optimize `&mut *x` into `x`Jonas Schievink-10/+8
2020-05-31always print MIR Location when validator finds a problemRalf Jung-32/+36
2020-05-31more checks for SwitchIntRalf Jung-3/+7
2020-05-31replace DUMMY_SP by proper spanRalf Jung-5/+3
2020-05-31validate basic sanity for TerminatorKindRalf Jung-2/+101
2020-05-30Make TLS accesses explicit in MIROliver Scherer-6/+15
2020-05-30more `LocalDefId`sBastian Kauschke-8/+9
2020-05-30Be more careful around ty::Error in generatorsJonas Schievink-26/+43
2020-05-29Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, ↵Ralf Jung-23/+117
r=nikomatsakis Implement RFC 2585: unsafe blocks in unsafe fn Tracking issue: #71668 r? @RalfJung cc @nikomatsakis
2020-05-28remove redundant `mk_const`Bastian Kauschke-1/+1
2020-05-28Auto merge of #72494 - lcnr:predicate-cleanup, r=nikomatsakisbors-12/+12
Pass more `Copy` types by value. There are a lot of locations where we pass `&T where T: Copy` by reference, which should both be slightly less performant and less readable IMO. This PR currently consists of three fairly self contained commits: - passes `ty::Predicate` by value and stops depending on `AsRef<ty::Predicate>`. - changes `<&List<_>>::into_iter` to iterate over the elements by value. This would break `List`s of non copy types. But as the only list constructor requires `T` to be copy anyways, I think the improved readability is worth this potential future restriction. - passes `mir::PlaceElem` by value. Mir currently has quite a few copy types which are passed by reference, e.g. `Local`. As I don't have a lot of experience working with MIR, I mostly did this to get some feedback from people who use MIR more frequently - tries to reuse `ty::Predicate` in case it did not change in some places, which should hopefully fix the regression caused by #72055 r? @nikomatsakis for the first commit, which continues the work of #72055 and makes adding `PredicateKind::ForAll` slightly more pleasant. Feel free to reassign though