about summary refs log tree commit diff
path: root/compiler/rustc_mir/src
AgeCommit message (Collapse)AuthorLines
2021-07-25Auto merge of #85646 - Moxinilian:separate-const-switch, r=cjgillotbors-0/+345
MIR opt: separate constant predecessors of a switch For each block S ending with a switch, this pass copies S for each of S's predecessors that seem to assign the value being switched over as a const. This is done using a somewhat simple heuristic to determine what seems to be a const transitively. More precisely, this is what the pass does: - find a block that ends in a switch - track if there is an unique place set before the current basic block that determines the result of the switch (this is the part that resolves switching over discriminants) - if there is, iterate over the parents that have a reasonable terminator and find if the found determining place is likely to be (transitively) set from a const within that parent block - if so, add the corresponding edge to a vector of edges to duplicate - once this is done, iterate over the found edges: copy the target block and replace the reference to the target block in the origin block with the new block This pass is not optimal and could probably duplicate in more cases, but the intention was mostly to address cases like in #85133 or #85365, to avoid creating new enums that get destroyed immediately afterwards (notably making the new try v2 `?` desugar zero-cost). A benefit of this pass working the way it does is that it is easy to ensure its correctness: the worst that can happen is for it to needlessly copy a basic block, which is likely to be destroyed by cleanup passes afterwards. The complex parts where aliasing matters are only heuristics and the hard work is left to further passes like ConstProp. # LLVM blocker Unfortunately, I believe it would be unwise to enable this optimization by default for now. Indeed, currently switch lowering passes like SimplifyCFG in LLVM lose the information on the set of possible variant values, which means it tends to actually generate worse code with this optimization enabled. A fix would have to be done in LLVM itself. This is something I also want to look into. I have opened [a bug report at the LLVM bug tracker](https://bugs.llvm.org/show_bug.cgi?id=50455). When this is done, I hope we can enable this pass by default. It should be fairly fast and I think it is beneficial in many cases. Notably, it should be a sound alternative to simplify-arm-identity. By the way, ConstProp only seems to pick up the optimization in functions that are not generic. This is however most likely an issue in ConstProp that I will look into afterwards. This is my first contribution to rustc, and I would like to thank everyone on the Zulip mir-opt chat for the help and support, and especially `@scottmcm` for the guidance.
2021-07-25clippy::useless_formatMatthias Krüger-8/+8
2021-07-25clippy:: append_instead_of_extendMatthias Krüger-3/+3
2021-07-25use vec![] macro to create Vector with first item inside instead of pushing ↵Matthias Krüger-2/+2
to an empty vec![] slightly reduces code bloat
2021-07-25Miri: santiy check that null pointer can never have an AllocIdRalf Jung-1/+5
2021-07-24Hide allocator details from TryReserveErrorKornel-0/+1
2021-07-24get rid of NoMirFor error variantRalf Jung-15/+4
2021-07-24rename Validator → CheckerRalf Jung-6/+6
2021-07-24rename const checking visitor module to check_consts::checkRalf Jung-3/+3
2021-07-24Auto merge of #86461 - crlf0710:rich_vtable, r=nikomatsakisbors-7/+7
Refactor vtable format for upcoming trait_upcasting feature. This modifies vtable format: 1. reordering occurrence order of methods coming from different traits 2. include `VPtr`s for supertraits where this vtable cannot be directly reused during trait upcasting. Also, during codegen, the vtables corresponding to these newly included `VPtr` will be requested and generated. For the cases where this vtable can directly used, now the super trait vtable has exactly the same content to some prefix of this one. r? `@bjorn3` cc `@RalfJung` cc `@rust-lang/wg-traits`
2021-07-22Add a test for get_body_with_borrowck_facts.Vytautas Astrauskas-0/+9
2021-07-22Enable compiler consumers to obtain Body with Polonius facts.Vytautas Astrauskas-17/+94
2021-07-22Resolve nested inference variables.Oli Scherer-19/+7
I attempted that with the previous code, but I misunderstdood how `shallow_resolve` works.
2021-07-22Remove an unnecessary variableOli Scherer-2/+1
2021-07-22Make mir borrowck's use of opaque types independent of the typeck query's resultOli Scherer-87/+62
2021-07-21Rollup merge of #87311 - oli-obk:nll_suggestion_span, r=estebankGuillaume Gomez-4/+6
Get back the more precise suggestion spans of old regionck I noticed that when you turn on nll, the structured suggestion replaces a snippet instead of appending a snippet. It seems clearer to the user to only highlight the newly added characters instead of the entire `impl Trait` (and old regionck already does it this way). r? ``@estebank``
2021-07-21Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obkGuillaume Gomez-8/+11
Recognize bounds on impls as const bounds r? ```@oli-obk```
2021-07-20Get back the more precise suggestion spans of old regionckOli Scherer-4/+6
2021-07-20Switch to store `Instance` directly within `VtblEntry`, fix `TraitVPtr` ↵Charles Lew-7/+3
representation.
2021-07-20Refactor vtable format.Charles Lew-0/+4
2021-07-20Auto merge of #87224 - RalfJung:miri-ptr-oob, r=oli-obkbors-4/+10
miri: better ptr-out-of-bounds errors For offsets larger than `isize::MAX`, display them as negative offsets. r? `@oli-obk`
2021-07-20Auto merge of #87141 - spastorino:remove_impl_trait_in_bindings, r=oli-obkbors-72/+13
Remove impl trait in bindings Closes #86729 r? `@oli-obk`
2021-07-19Iterate through impls only when permittedDeadbeef-8/+11
2021-07-18Move mir_def_id inside `eq_opaque_type_and_type`Santiago Pastorino-8/+5
2021-07-18Remove `sub_types_or_anon`Santiago Pastorino-30/+2
2021-07-18Add `sub_types` docsSantiago Pastorino-0/+1
2021-07-18Removing unhandled region constraint error that is only for ↵Santiago Pastorino-34/+5
impl_trait_in_bindings
2021-07-18miri: better ptr-out-of-bounds errorsRalf Jung-4/+10
2021-07-18Auto merge of #85686 - ptrojahn:loop_reinitialize, r=estebankbors-18/+74
Add help on reinitialization between move and access Fixes #83760
2021-07-17Auto merge of #87123 - RalfJung:miri-provenance-overhaul, r=oli-obkbors-700/+634
CTFE/Miri engine Pointer type overhaul This fixes the long-standing problem that we are using `Scalar` as a type to represent pointers that might be integer values (since they point to a ZST). The main problem is that with int-to-ptr casts, there are multiple ways to represent the same pointer as a `Scalar` and it is unclear if "normalization" (i.e., the cast) already happened or not. This leads to ugly methods like `force_mplace_ptr` and `force_op_ptr`. Another problem this solves is that in Miri, it would make a lot more sense to have the `Pointer::offset` field represent the full absolute address (instead of being relative to the `AllocId`). This means we can do ptr-to-int casts without access to any machine state, and it means that the overflow checks on pointer arithmetic are (finally!) accurate. To solve this, the `Pointer` type is made entirely parametric over the provenance, so that we can use `Pointer<AllocId>` inside `Scalar` but use `Pointer<Option<AllocId>>` when accessing memory (where `None` represents the case that we could not figure out an `AllocId`; in that case the `offset` is an absolute address). Moreover, the `Provenance` trait determines if a pointer with a given provenance can be cast to an integer by simply dropping the provenance. I hope this can be read commit-by-commit, but the first commit does the bulk of the work. It introduces some FIXMEs that are resolved later. Fixes https://github.com/rust-lang/miri/issues/841 Miri PR: https://github.com/rust-lang/miri/pull/1851 r? `@oli-obk`
2021-07-17Auto merge of #87195 - yaahc:move-assert_matches-again, r=oli-obkbors-1/+1
rename assert_matches module Fixes nightly breakage introduced in https://github.com/rust-lang/rust/pull/86947
2021-07-16Add initial implementation of HIR-based WF checking for diagnosticsAaron Hill-17/+19
During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).
2021-07-16avoid manual Debug impls by adding extra Provenance bounds to typesRalf Jung-149/+46
I wish the derive macro would support adding extra where clauses...
2021-07-16rename assert_matches moduleJane Lusby-1/+1
2021-07-16get rid of incorrect erase_for_fmtRalf Jung-56/+50
2021-07-15make check_ptr_access_align work on function pointer allocationsRalf Jung-6/+12
2021-07-15enable Miri to fix the bytes in an allocation (since ptr offsets have ↵Ralf Jung-53/+41
different meanings there)
2021-07-15adjustions and cleanup to make Miri build againRalf Jung-138/+118
2021-07-15Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahcYuki Okushi-0/+1
Move assert_matches to an inner module Fixes #82913
2021-07-14remove unused error variantRalf Jung-8/+3
2021-07-14more precise message for the ptr access check on derefRalf Jung-8/+7
2021-07-14use NonZeroU64 for AllocId to restore old type sizesRalf Jung-7/+7
2021-07-14consistently treat None-tagged pointers as ints; get rid of some deprecated ↵Ralf Jung-40/+49
Scalar methods
2021-07-14CTFE/Miri engine Pointer type overhaul: make Scalar-to-Pointer conversion ↵Ralf Jung-518/+584
infallible This resolves all the problems we had around "normalizing" the representation of a Scalar in case it carries a Pointer value: we can just use Pointer if we want to have a value taht we are sure is already normalized.
2021-07-13Auto merge of #87044 - cjgillot:expnhash, r=petrochenkovbors-1/+2
Cache expansion hash globally ... instead of computing it multiple times. Split from #86676 r? `@petrochenkov`
2021-07-13Cache expansion hash.Camille GILLOT-1/+2
2021-07-13Auto merge of #86857 - fee1-dead:add-attr, r=oli-obkbors-8/+37
Add #[default_method_body_is_const] `@rustbot` label F-const_trait_impl
2021-07-12remove unnecessary deallocate_local hackRalf Jung-15/+8
2021-07-12remove remaining use of Pointer in Allocation APIRalf Jung-2/+2
2021-07-12Auto merge of #86815 - FabianWolff:issue-84210, r=varkorbors-4/+20
Improve error reporting for modifications behind `&` references I had a look at #84210 and noticed that #85823 has effectively already fixed #84210. However, the string matching in #85823 is _very_ crude and already breaks down when a variable name starts with `mut`. I have made this a bit more robust; further improvements could definitely be made but are complicated by the lack of information provided by an earlier pass: https://github.com/rust-lang/rust/blob/ce331ee6ee010438d1a58c7da8ced4f26d69a20e/compiler/rustc_mir_build/src/build/matches/mod.rs#L2103-L2107 I have also fixed a missing comma in the error message.