about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-04-20change usages of explicit_item_bounds to bound_explicit_item_boundsKyle Matsuda-1/+3
2023-04-20Remove WithOptconstParam.Camille GILLOT-119/+37
2023-04-19Move `GenericArgKind::as_{type,const,region}` to `GenericArg`Maybe Waffle-2/+2
2023-04-19Add `GenericArgKind::as_{type,const,region}`Maybe Waffle-26/+22
2023-04-19Auto merge of #110477 - miguelraz:canoodling2-electric-boogaloo, ↵bors-48/+56
r=compiler-errors Don't allocate on SimplifyCfg/Locals/Const on every MIR pass Hey! 👋🏾 This is a first PR attempt to see if I could speed up some rustc internals. Thought process: ```rust pub struct SimplifyCfg { label: String, } ``` in [compiler/src/rustc_mir_transform/simplify.rs](https://github.com/rust-lang/rust/blob/7908a1d65496b88626e4b7c193c81d777005d6f3/compiler/rustc_mir_transform/src/simplify.rs#L39) fires multiple times per MIR analysis. This means that a likely string allocation is happening in each of these runs, which may add up, as they are not being lazily allocated or cached in between the different passes. ...yes, I know that adding a global static array is probably not the future-proof solution, but I wanted to lob this now as a proof of concept to see if it's worth shaving off a few cycles and then making more robust.
2023-04-18Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillotbors-1/+6
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-18refactor SimlifyCfg and friends - no globals, just enumsmiguelraz-48/+56
2023-04-18Store hashes in special types so they aren't accidentally encoded as numbersBen Kimock-1/+6
2023-04-17Spelling - compilerJosh Soref-13/+13
* 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-17Rollup merge of #110434 - compiler-errors:issue-110171, r=oli-obkMatthias Krüger-2/+3
Check freeze with right param-env in `deduced_param_attrs` We're checking if a trait (`Freeze`) holds in a polymorphic function, but not using that function's own (reveal-all) param-env. This causes us to try to eagerly normalize a specializable projection type that has no default value, which causes an ICE. Fixes #110171
2023-04-17Rollup merge of #110404 - matthiaskrgr:mapmap, r=NilstriebMatthias Krüger-1/+1
fix clippy::toplevel_ref_arg and ::manual_map r? ``@Nilstrieb``
2023-04-17Auto merge of #109247 - saethlin:inline-without-inline, r=oli-obkbors-8/+2
Permit MIR inlining without #[inline] I noticed that there are at least a handful of portable-simd functions that have no `#[inline]` but compile to an assign + return. I locally benchmarked inlining thresholds between 0 and 50 in increments of 5, and 50 seems to be the best. Interesting. That didn't include check builds though, ~maybe perf will have something to say about that~. Perf has little useful to say about this. We generally regress all the check builds, as best as I can tell, due to a number of small codegen changes in a particular hot function in the compiler. Probably this is because we've nudged the inlining outcomes all over, and uses of `#[inline(always)]`/`#[inline(never)]` might need to be adjusted.
2023-04-16Check freeze with right param-envMichael Goulet-2/+3
2023-04-16Rollup merge of #110400 - matthiaskrgr:style_mix, r=fee1-deadfee1-dead-4/+2
more clippy fixes: clippy::{iter_cloned_collect, unwarp_or_else_defau… …lt, option_map_or_none} r? `@Nilstrieb`
2023-04-16fix clippy::toplevel_ref_arg and ::manual_mapMatthias Krüger-1/+1
2023-04-16more clippy fixes: clippy::{iter_cloned_collect, unwarp_or_else_default, ↵Matthias Krüger-4/+2
option_map_or_none}
2023-04-16Move some utils out of `rustc_const_eval`Nilstrieb-1/+6
This allows us to get rid of the `rustc_const_eval->rustc_borrowck` dependency edge which was delaying the compilation of borrowck. The added utils in `rustc_middle` are small and should not affect compile times there.
2023-04-15Remove outdated comment.Camille GILLOT-2/+0
2023-04-15Remove useless methods in visit.Camille GILLOT-6/+0
2023-04-15Only enable ConstProp at mir-opt-level >= 2.Camille GILLOT-1/+1
2023-04-13Rollup merge of #110283 - saethlin:check-panics-before-alignment, r=bjorn3Matthias Krüger-0/+7
Only emit alignment checks if we have a panic_impl Fixes https://github.com/rust-lang/rust/issues/109996 r? `@bjorn3` because you commented that this situation could impact you as well
2023-04-13Only emit alignment checks if we have a panic_implBen Kimock-0/+7
2023-04-13Auto merge of #109466 - davidlattimore:inline-arg-via-var-debug-info, ↵bors-0/+7
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/+7
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-09Auto merge of #110031 - compiler-errors:generic-elaboration, r=b-naberbors-8/+2
Make elaboration generic over input Combines all the `elaborate_*` family of functions into just one, which is an iterator over the same type that you pass in (e.g. elaborating `Predicate` gives `Predicate`s, elaborating `Obligation`s gives `Obligation`s, etc.)
2023-04-07Permit MIR inlining without #[inline]Ben Kimock-8/+2
2023-04-07Auto merge of #102906 - nbdd0121:mir, r=wesleywiser,tmiaskobors-115/+137
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-06Make elaborator genericMichael Goulet-8/+2
2023-04-06UnwindAction::Terminate edge is also critical edgeGary Guo-1/+2
2023-04-06Fix new usage of old apiGary Guo-1/+1
2023-04-06Fix new usage of old apiGary Guo-4/+4
2023-04-06Address review feedbackGary Guo-4/+4
2023-04-06Rename `Abort` terminator to `Terminate`Gary Guo-27/+23
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-32/+15
2023-04-06Add `UnwindAction::Unreachable`Gary Guo-18/+29
This also makes eval machine's `StackPopUnwind` redundant so that is replaced.
2023-04-06Refactor unwind from Option to a new enumGary Guo-58/+89
2023-04-06Auto merge of #109915 - scottmcm:layout-indexvec, r=oli-obkbors-1/+1
Use `FieldIdx` in `FieldsShape` Finally got to the main motivating example from https://github.com/rust-lang/compiler-team/issues/606 :)
2023-04-05Comment logic around worklist.Camille GILLOT-0/+3
2023-04-05Only visit reachable blocks in ConstProp lint.Camille GILLOT-8/+32
2023-04-05Extract check_assertion.Camille GILLOT-72/+71
2023-04-05Manipulate Location instead of SourceInfo.Camille GILLOT-50/+36
2023-04-05Do not keep extra references to scopes and decls.Camille GILLOT-18/+13
2023-04-04Use `FieldIdx` in `FieldsShape`Scott McMurray-1/+1
Finally got to the main motivating example from the MCP :)
2023-04-04Rollup merge of #109938 - oli-obk:try_norm, r=compiler-errorsMichael Goulet-1/+9
Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible fixes #109743 This hack didn't need to live in the mir interpreter. For const-prop-lint it is entirely correct to avoid doing any const prop if normalization fails at this stage. Most likely we couldn't const propagate anything anyway, and if revealing was needed (so opaque types were involved), we wouldn't want to be too smart and leak the hidden type anyway.
2023-04-04Move a const-prop-lint specific hack from mir interpret to const-prop-lint ↵Oli Scherer-1/+9
and make it fallible
2023-04-03Doc-comment `IndexVec::from_elem` and use it in a few more placesScott McMurray-3/+2
2023-04-02Use `&IndexSlice` instead of `&IndexVec` where possibleScott McMurray-22/+22
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-01Use `FieldIdx` in various things related to aggregatesScott McMurray-2/+2
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
2023-03-31Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obkbors-0/+229
Insert alignment checks for pointer dereferences when debug assertions are enabled Closes https://github.com/rust-lang/rust/issues/54915 - [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit) - [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue! - [x] Implement a more helpful panic message like slice bounds checking. r? `@oli-obk`