about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
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`.
2023-04-18Store hashes in special types so they aren't accidentally encoded as numbersBen Kimock-14/+5
2023-04-18Rollup merge of #110417 - jsoref:spelling-compiler, r=NilstriebGuillaume Gomez-3/+3
Spelling compiler This is per https://github.com/rust-lang/rust/pull/110392#issuecomment-1510193656 I'm going to delay performing a squash because I really don't expect people to be perfectly happy w/ my changes, I really am a human and I really do make mistakes. r? Nilstrieb I'm going to be flying this evening, but I should be able to squash / respond to reviews w/in a day or two. I tried to be careful about dropping changes to `tests`, afaict only two files had changes that were likely related to the changes for a given commit (this is where not having eagerly squashed should have given me an advantage), but, that said, picking things apart can be error prone.
2023-04-17Spelling - compilerJosh Soref-3/+3
* account * achieved * advising * always * ambiguous * analysis * annotations * appropriate * build * candidates * cascading * category * character * clarification * compound * conceptually * constituent * consts * convenience * corresponds * debruijn * debug * debugable * debuggable * deterministic * discriminant * display * documentation * doesn't * ellipsis * erroneous * evaluability * evaluate * evaluation * explicitly * fallible * fulfill * getting * has * highlighting * illustrative * imported * incompatible * infringing * initialized * into * intrinsic * introduced * javascript * liveness * metadata * monomorphization * nonexistent * nontrivial * obligation * obligations * offset * opaque * opportunities * opt-in * outlive * overlapping * paragraph * parentheses * poisson * precisely * predecessors * predicates * preexisting * propagated * really * reentrant * referent * responsibility * rustonomicon * shortcircuit * simplifiable * simplifications * specify * stabilized * structurally * suggestibility * translatable * transmuting * two * unclosed * uninhabited * visibility * volatile * workaround Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17Auto merge of #110343 - saethlin:encode-initmask, r=lqdbors-1/+31
Bypass the varint path when encoding InitMask The data in a `InitMask` is stored as `u64` but it is a large bitmask (not numbers) so varint encoding doesn't make sense.
2023-04-17Bypass the varint path when encoding InitMaskBen Kimock-1/+31
2023-04-16Simplify `CloneLiftImpls` and `TrivialTypeTraversalImpls`.Nicholas Nethercote-6/+2
They both allow for a lifetime other than `'tcx`, but this isn't needed.
2023-04-13Auto merge of #109466 - davidlattimore:inline-arg-via-var-debug-info, ↵bors-0/+6
r=wesleywiser Preserve argument indexes when inlining MIR We store argument indexes on VarDebugInfo. Unlike the previous method of relying on the variable index to know whether a variable is an argument, this survives MIR inlining. We also no longer check if var.source_info.scope is the outermost scope. When a function gets inlined, the arguments to the inner function will no longer be in the outermost scope. What we care about though is whether they were in the outermost scope prior to inlining, which we know by whether we assigned an argument index. Fixes #83217 I considered using `Option<NonZeroU16>` instead of `Option<u16>` to store the index. I didn't because `TypeFoldable` isn't implemented for `NonZeroU16` and because it looks like due to padding, it currently wouldn't make any difference. But I indexed from 1 anyway because (a) it'll make it easier if later it becomes worthwhile to use a `NonZeroU16` and because the arguments were previously indexed from 1, so it made for a smaller change. This is my first PR on rust-lang/rust, so apologies if I've gotten anything not quite right.
2023-04-11Preserve argument indexes when inlining MIRDavid Lattimore-0/+6
We store argument indexes on VarDebugInfo. Unlike the previous method of relying on the variable index to know whether a variable is an argument, this survives MIR inlining. We also no longer check if var.source_info.scope is the outermost scope. When a function gets inlined, the arguments to the inner function will no longer be in the outermost scope. What we care about though is whether they were in the outermost scope prior to inlining, which we know by whether we assigned an argument index.
2023-04-10Fix typos in compilerDaniPopes-2/+2
2023-04-09fixup! Improve `Allocation::hashNilstrieb-1/+1
2023-04-09Convert manual loop into `while let`Nilstrieb-11/+1
2023-04-09Remove identity castsNilstrieb-4/+4
2023-04-09Fix some clippy::complexityNilstrieb-1/+1
2023-04-09Improve `Allocation::hashNilstrieb-9/+17
Exhaustively destructure and ignore `()`
2023-04-07Auto merge of #110036 - jackh726:placeholder_boundvar, r=nnethercotebors-4/+2
Remove u32 on BrAnon and BoundTyKind::Anon in favor of BoundVar on Placeholder types r? `@nnethercote` Better alternative to #110025
2023-04-07Auto merge of #102906 - nbdd0121:mir, r=wesleywiser,tmiaskobors-107/+194
Refactor unwind in MIR This makes unwinding from current `Option<BasicBlock>` into ```rust enum UnwindAction { Continue, Cleanup(BasicBlock), Unreachable, Terminate, } ``` cc `@JakobDegen` `@RalfJung` `@Amanieu`
2023-04-06Remove index from BrAnonJack Huey-4/+2
2023-04-06Auto merge of #108504 - cjgillot:thir-pattern, r=compiler-errors,Nilstriebbors-0/+7
Check pattern refutability on THIR The current `check_match` query is based on HIR, but partially re-lowers HIR into THIR. This PR proposed to use the results of the `thir_body` query to check matches, instead of re-building THIR. Most of the diagnostic changes are spans getting shorter, or commas/semicolons not getting removed. This PR degrades the diagnostic for confusing constants in patterns (`let A = foo()` where `A` resolves to a `const A` somewhere): it does not point ot the definition of `const A` any more.
2023-04-06Address review feedbackGary Guo-10/+11
2023-04-06Rename `Abort` terminator to `Terminate`Gary Guo-13/+59
Unify terminology used in unwind action and terminator, and reflect the fact that a nounwind panic is triggered instead of an immediate abort is triggered for this terminator.
2023-04-06Add `UnwindAction::Terminate`Gary Guo-0/+7
2023-04-06Add `UnwindAction::Unreachable`Gary Guo-18/+36
This also makes eval machine's `StackPopUnwind` redundant so that is replaced.
2023-04-06Refactor unwind from Option to a new enumGary Guo-88/+103
2023-04-05Auto merge of #109117 - oli-obk:locks, r=michaelwoeristerbors-1/+2
Avoid a few locks We can use atomics or datastructures tuned for specific access patterns instead of locks. This may be an improvement for parallel rustc, but it's mostly a cleanup making various datastructures only usable in the way they are used right now (append data, never mutate), instead of having a general purpose lock.
2023-04-04Rollup merge of #109901 - cjgillot:validate-debuginfo, r=b-naberMichael Goulet-7/+17
Enforce VarDebugInfo::Place in MIR validation.
2023-04-04Remove a fishy Clone implOli Scherer-1/+2