summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
2023-06-03add FIXMElcnr-0/+5
2023-06-03unique borrows are mutating useslcnr-7/+3
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-1/+6
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-26Rollup merge of #111899 - nnethercote:cgu-cleanups, r=wesleywiserMatthias Krüger-4/+1
CGU cleanups Some code clarity improvements I found when reading this code closely. r? ``@wesleywiser``
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-1/+6
2023-05-25Streamline `modify_size_estimate`.Nicholas Nethercote-4/+1
2023-05-24Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiaskobors-2/+3
Preprocess and cache dominator tree Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344. That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree). This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache. Rebase of https://github.com/rust-lang/rust/pull/107157 cc `@tmiasko`
2023-05-23Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obkDylan DPC-0/+23
MIR drive-by cleanups Some random drive-by cleanups I did while working with MIR/THIR.
2023-05-20Rollup merge of #111619 - cjgillot:profile-pass, r=WaffleLapkinDylan DPC-1/+1
Add timings for MIR passes to profiling report This will help identify which pass is responsible for a regression.
2023-05-17Drive-by cleanup: `debug::term_type` => `TerminatorKind::name`Maybe Waffle-0/+23
2023-05-17Merge DominatorTree and Dominators.Camille GILLOT-7/+1
2023-05-17Cache dominators.Camille GILLOT-4/+6
2023-05-17Preprocess dominator tree to answer queries in O(1)Tomasz Miąsko-1/+6
2023-05-17Finish move of query.rsJohn Kåre Alsaker-2/+4
2023-05-15Profile MIR passes.Camille GILLOT-1/+1
2023-05-15Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwUbors-4/+2
Rename const error methods for consistency renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods. r? `@BoxyUwU`
2023-05-15Suppress "erroneous constant used" for constants tainted by errorsTomasz Miąsko-11/+45
When constant evaluation fails because its MIR is tainted by errors, suppress note indicating that erroneous constant was used, since those errors have to be fixed regardless of the constant being used or not.
2023-05-14Rename const error methods for consistencyMichael Goulet-4/+2
2023-05-13Support ConstantIndex in debuginfo.Camille GILLOT-2/+5
2023-05-13Implement references VarDebugInfo.Camille GILLOT-14/+34
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-2/+1
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11Rollup merge of #111366 - obeis:ascribe-user-type-variance, r=lcnrMichael Goulet-4/+4
Make `NonUseContext::AscribeUserTy` carry `ty::Variance` Close #108267
2023-05-10Remove and fix useless drop of referenceUrgau-2/+1
2023-05-10Make `NonUseContext::AscribeUserTy` carry `ty::Variance`Obei Sideg-4/+4
2023-05-09Implement SSA-based reference propagation.Camille GILLOT-0/+13
2023-05-05Disallow (min) specialization imps with no itemsMatthew Jasper-2/+0
Such implementations are usually mistakes and are not used in the compiler or standard library (after this commit) so forbid them with `min_specialization`.
2023-05-04Rollup merge of #111100 - BoxyUwU:array_repeat_expr_wf, r=compiler-errorsMatthias Krüger-2/+19
check array type of repeat exprs is wf Fixes #111091 Also makes sure that we actually renumber regions in the length of repeat exprs which we previously weren't doing and would cause ICEs in `adt_const_params` + `generic_const_exprs` from attempting to prove the wf goals when the length was an unevaluated constant with `'erased` in the `ty` field of `Const` The duplicate errors are caused by the fact that `const_arg_to_const`/`array_len_to_const` in `FnCtxt` adds a `WellFormed` goal for the created `Const` which is also checked by the added `WellFormed(array_ty)`. I don't want to change this to just emit a `T: Sized` goal for the element type since that would ignore `ConstArgHasType` wf requirements and generally uncomfortable with the idea of trying to sync up `wf::obligations` for arrays and the code in hir typeck for repeat exprs. r? `@compiler-errors`
2023-05-04Rollup merge of #110826 - cjgillot:place-mention-use, r=JakobDegen,lcnrMatthias Krüger-3/+6
Make PlaceMention a non-mutating use. Fixes https://github.com/rust-lang/rust/issues/110781 r? `@JakobDegen` I don't agree with your statement in https://github.com/rust-lang/rust/issues/110781#issuecomment-1520841434. I suggest that we start fixing `PlaceContext` to be accurate enough for optimizations to use it. This structure is very convenient to use in visitors, and we perhaps have an opportunity to make it less of a footgun.
2023-05-04do not allow rustc::pass_by_value lintBoxy-6/+4
2023-05-04check array type of repeat exprs is wfBoxy-2/+21
2023-05-04Rollup merge of #110943 - RalfJung:interpret-unsized-arg-ice, r=oli-obkDylan DPC-0/+4
interpret: fail more gracefully on uninit unsized locals r? `@oli-obk` Fixes https://github.com/rust-lang/rust/issues/68538
2023-05-01Box AssertKindBen Kimock-4/+4
2023-04-29Auto merge of #109611 - Zoxc:query-engine-rem, r=cjgillotbors-1/+3
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of https://github.com/rust-lang/rust/pull/107802 is included which avoids the double indirection. For https://github.com/rust-lang/rust/pull/108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For https://github.com/rust-lang/rust/pull/108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
2023-04-29Expand comment on NonMutatingUseContext.Camille GILLOT-0/+3
2023-04-29Make PlaceMention a non-mutating use.Camille GILLOT-3/+3
2023-04-28interpret: fail more gracefully on uninit unsized localsRalf Jung-0/+4
2023-04-26Remove QueryEngine traitJohn Kåre Alsaker-1/+3
2023-04-26Derive `Type{Foldable,Visitable}` for `UserTypeProjection`.Nicholas Nethercote-24/+3
Because the derived versions are good enough.
2023-04-25Rollup merge of #110750 - scottmcm:vardebug-size, r=cjgillotYuki Okushi-0/+2
Add size asserts for MIR `SourceScopeData` & `VarDebugInfo` There's vectors of both of these in `mir::Body`, so might as well track them. (I was pondering adding something to one or the other, so wanted this to see the memory impact.)
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-7/+7
2023-04-23Add size asserts for MIR `SourceScopeData` & `VarDebugInfo`Scott McMurray-0/+2
There's vectors of both of these in `mir::Body`, so might as well track them.
2023-04-22Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJungbors-3/+2
Evaluate place expression in `PlaceMention` https://github.com/rust-lang/rust/pull/102256 introduces a `PlaceMention(place)` MIR statement which keep trace of `let _ = place` statements from surface rust, but without semantics. This PR proposes to change the behaviour of `let _ =` patterns with respect to the borrow-checker to verify that the bound place is live. Specifically, consider this code: ```rust let _ = { let a = 5; &a }; ``` This passes borrowck without error on stable. Meanwhile, replacing `_` by `_: _` or `_p` errors with "error[E0597]: `a` does not live long enough", [see playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c448d25a7c205dc95a0967fe96bccce8). This PR *does not* change how `_` patterns behave with respect to initializedness: it remains ok to bind a moved-from place to `_`. The relevant test is `tests/ui/borrowck/let_underscore_temporary.rs`. Crater check found no regression. For consistency, this PR changes miri to evaluate the place found in `PlaceMention`, and report eventual dangling pointers found within it. r? `@RalfJung`
2023-04-22Auto merge of #106934 - DrMeepster:offset_of, r=WaffleLapkinbors-6/+14
Add offset_of! macro (RFC 3308) Implements https://github.com/rust-lang/rfcs/pull/3308 (tracking issue #106655) by adding the built in macro `core::mem::offset_of`. Two of the future possibilities are also implemented: * Nested field accesses (without array indexing) * DST support (for `Sized` fields) I wrote this a few months ago, before the RFC merged. Now that it's merged, I decided to rebase and finish it. cc `@thomcc` (RFC author)
2023-04-21Actually keep `PlaceMention` if requested.Camille GILLOT-2/+0
2023-04-21Evaluate place expression in `PlaceMention`.Camille GILLOT-1/+2
2023-04-21test improvementsDrMeepster-1/+5
2023-04-21intern offsetof fieldsDrMeepster-5/+5
2023-04-21offset_ofDrMeepster-3/+7
2023-04-20Remove WithOptconstParam.Camille GILLOT-114/+43
2023-04-18Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillotbors-14/+5
Encode hashes as bytes, not varint In a few places, we store hashes as `u64` or `u128` and then apply `derive(Decodable, Encodable)` to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new types `Hash64` and `Hash128` which are produced by `StableHasher` and replace every use of storing a `u64` or `u128` that represents a hash. Distribution of the byte lengths of leb128 encodings, from `x build --stage 2` with `incremental = true` Before: ``` ( 1) 373418203 (53.7%, 53.7%): 1 ( 2) 196240113 (28.2%, 81.9%): 3 ( 3) 108157958 (15.6%, 97.5%): 2 ( 4) 17213120 ( 2.5%, 99.9%): 4 ( 5) 223614 ( 0.0%,100.0%): 9 ( 6) 216262 ( 0.0%,100.0%): 10 ( 7) 15447 ( 0.0%,100.0%): 5 ( 8) 3633 ( 0.0%,100.0%): 19 ( 9) 3030 ( 0.0%,100.0%): 8 ( 10) 1167 ( 0.0%,100.0%): 18 ( 11) 1032 ( 0.0%,100.0%): 7 ( 12) 1003 ( 0.0%,100.0%): 6 ( 13) 10 ( 0.0%,100.0%): 16 ( 14) 10 ( 0.0%,100.0%): 17 ( 15) 5 ( 0.0%,100.0%): 12 ( 16) 4 ( 0.0%,100.0%): 14 ``` After: ``` ( 1) 372939136 (53.7%, 53.7%): 1 ( 2) 196240140 (28.3%, 82.0%): 3 ( 3) 108014969 (15.6%, 97.5%): 2 ( 4) 17192375 ( 2.5%,100.0%): 4 ( 5) 435 ( 0.0%,100.0%): 5 ( 6) 83 ( 0.0%,100.0%): 18 ( 7) 79 ( 0.0%,100.0%): 10 ( 8) 50 ( 0.0%,100.0%): 9 ( 9) 6 ( 0.0%,100.0%): 19 ``` The remaining 9 or 10 and 18 or 19 are `u64` and `u128` respectively that have the high bits set. As far as I can tell these are coming primarily from `SwitchTargets`.