about summary refs log tree commit diff
path: root/src/librustc_mir
AgeCommit message (Collapse)AuthorLines
2020-04-30Rollup merge of #71655 - RalfJung:const-pattern-soundness, r=oli-obkDylan DPC-10/+29
Miri: better document and fix dynamic const pattern soundness checks https://github.com/rust-lang/const-eval/issues/42 got me thinking about soundness for consts being used in patterns, and I found a hole in our existing dynamic checks: a const referring to a mutable static *in a different crate* was not caught. This PR fixes that. It also adds some comments that explain which invariants are crucial for soundness of const-patterns. Curiously, trying to weaponize this soundness hole failed: pattern matching compilation ICEd when encountering the cross-crate static, saying "expected allocation ID alloc0 to point to memory". I don't know why that would happen, statics *should* be entirely normal memory for pattern matching to access. r? @oli-obk Cc @rust-lang/wg-const-eval
2020-04-30Auto merge of #70175 - Amanieu:remove_nlp, r=pnkfelixbors-3/+6
Remove -Z no-landing-pads flag Since #67502, `-Z no-landing-pads` will cause all attempted unwinds to abort since we don't generate a `try` / `catch`. This previously worked because `__rust_try` was located in libpanic_unwind which is always compiled with `-C panic=unwind`, but `__rust_try` is now directly inline into the crate that uses `catch_unwind`. As such, `-Z no-landing-pads` is now mostly useless and people should use `-C panic=abort` instead.
2020-04-29Allow `Unreachable` terminators unconditionallyDylan MacKenzie-7/+3
2020-04-29Allow `Downcast` projections unconditionallyDylan MacKenzie-18/+2
2020-04-29Auto merge of #67343 - ecstatic-morse:qualif-structural-match, r=pnkfelixbors-7/+73
Const qualification for `StructuralEq` Furthers #62411. Resolves #62614. The goal of this PR is to implement the logic in #67088 on the MIR instead of the HIR. It uses the `Qualif` trait to track `StructuralPartialEq`/`StructuralEq` in the final value of a `const`. Then, if we encounter a constant during HAIR lowering whose value may not be structurally matchable, we emit the `indirect_structural_match` lint. This PR contains all the tests present in #67088 and emits the proper warnings for the corner cases. This PR does not handle #65466, which would require that we be [more aggressive](https://github.com/rust-lang/rust/blob/42abbd8878d3b67238f3611b0587c704ba94f39c/src/librustc_mir_build/hair/pattern/const_to_pat.rs#L126-L130) when checking matched types for `PartialEq`. I think that should be done separately. Because this works on MIR and uses dataflow, this PR should accept more cases than #67088. Notably, the qualifs in the final value of a const are encoded cross-crate, so matching on a constant whose value is defined in another crate to be `Option::<TyWithCustomEqImpl>::None` should work. Additionally, if a `const` has branching/looping, we will only emit the warning if any possible control flow path could result in a type with a custom `PartialEq` impl ending up as the final value of a `const`. I'm not sure how #67088 handled this. AFAIK, it's not settled that these are the semantics we actually want: it's just how the `Qualif` framework happens to work. If the cross-crate part is undesirable, it would be quite easy to change the result of `mir_const_qualif().custom_eq` to `true` before encoding it in the crate metadata. This way, other crates would have to assume that all publicly exported constants may not be safe for matching. r? @pnkfelix cc @eddyb
2020-04-29expand comment in memory.rs with extra soundness concernsRalf Jung-1/+3
2020-04-29Rollup merge of #71217 - estebank:tail-borrow-sugg, r=pnkfelixDylan DPC-15/+24
Suggest `;` or assignment to drop borrows in tail exprs Address the diagnostics part of #70844. ``` error[E0597]: `counter` does not live long enough --> $DIR/issue-54556-niconii.rs:22:20 | LL | if let Ok(_) = counter.lock() { } | ^^^^^^^------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... ... LL | } | - | | | `counter` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `std::result::Result<MutexGuard<'_>, ()>` | help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | if let Ok(_) = counter.lock() { }; | ^ ```
2020-04-29Auto merge of #71518 - felix91gr:const_prop_bugfix_just_block_prop, ↵bors-21/+70
r=wesleywiser Const-prop bugfix: only add propagation inside own block for user variables A testing spinoff of #71298. This one only adds the const-prop for locals that are user variables.
2020-04-28Suggest `;` or assignment to drop borrows in tail exprsEsteban Küber-15/+24
Address the diagnostics part of #70844. ``` error[E0597]: `counter` does not live long enough --> $DIR/issue-54556-niconii.rs:22:20 | LL | if let Ok(_) = counter.lock() { } | ^^^^^^^------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... ... LL | } | - | | | `counter` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `std::result::Result<MutexGuard<'_>, ()>` | help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | if let Ok(_) = counter.lock() { }; | ^ ```
2020-04-29Remove Session::no_landing_pads()Amanieu d'Antras-3/+6
2020-04-28Add `CustomEq` qualifDylan MacKenzie-1/+63
2020-04-28clarify commentRalf Jung-1/+3
2020-04-28better document const-pattern dynamic soundness checks, and fix a soundness holeRalf Jung-9/+24
2020-04-28Pass `Substs` to `in_adt_inherently`Dylan MacKenzie-6/+10
2020-04-28Rollup merge of #71615 - RalfJung:share-machine-code, r=oli-obkDylan DPC-113/+74
share some common code for compile-time miri instances Fixes https://github.com/rust-lang/rust/issues/71129 r? @oli-obk
2020-04-28Rollup merge of #71585 - tshepang:obsolete-comment, r=Dylan-DPCDylan DPC-7/+0
remove obsolete comment Not sure if it's better to have an outdated comment or no comment at all (made obsolete by 2b9fea1300b515e0f8929bb3a09d4fb6fef3f0ea).
2020-04-28Rollup merge of #71488 - spastorino:normalize-ty-to-fix-broken-mir, r=eddybDylan DPC-0/+1
normalize field projection ty to fix broken MIR issue Fixes #71344 r? @eddyb
2020-04-28Use the query system to allocate.Camille GILLOT-13/+13
2020-04-28Introduce ArenaStorage.Camille GILLOT-2/+2
2020-04-28Auto merge of #71292 - marmeladema:queries-local-def-id, r=eddybbors-52/+74
Convert more queries to use `LocalDefId` This PR is based on commits in https://github.com/rust-lang/rust/pull/71215 and should partially solve #70853
2020-04-28Polished documentation, removed not-so-useful-anymore traces, and added some ↵Félix Fischer-6/+13
doc comments in `mir/transform/const_prop.rs`
2020-04-28Allow Locals to be propagated into and from, but restricted to their own blockFélix Fischer-13/+46
2020-04-27Blocked `MutatingUseContext::Projection` for all locals of kind ↵Félix Fischer-4/+13
`LocalKind::Temp`. Added a cache of `LocalKind`s to `CanConstProp`
2020-04-27Change return type of `entry_fn` query to return a `LocalDefId`marmeladema-2/+2
2020-04-27Accept `LocalDefId` as key for `mir_validated` querymarmeladema-9/+13
2020-04-27Accept `LocalDefId` as key for `mir_borrowck` querymarmeladema-11/+15
2020-04-27Return a `FxHashSet<LocalDefId>` from `mir_keys` querymarmeladema-8/+13
2020-04-27Use `LocalDefId` in `mir_built` querymarmeladema-3/+7
2020-04-27Use `LocalDefId` in `unsafety_check_result` querymarmeladema-12/+10
2020-04-27Use `LocalDefId` in `typeck_tables_of` and `used_trait_imports` queriesmarmeladema-15/+22
2020-04-27Auto merge of #71200 - oli-obk:mir_bless, r=eddybbors-5/+5
Emit basic block info for stmts and terminators in MIR dumps only with -Zverbose r? @eddyb as per https://github.com/rust-lang/rust/pull/70755#discussion_r403419476
2020-04-27share some common code for compile-time miri instancesRalf Jung-113/+74
2020-04-27Emit basic block ids for statements and terminators in MIR only in -Zverbose ↵Oliver Scherer-5/+5
mode
2020-04-27Auto merge of #71268 - estebank:devectorize, r=eddybbors-2/+1
Remove some `Vec` allocations to improve performance This claws back most of the performance lost in https://github.com/rust-lang/rust/pull/69745. r? @eddyb
2020-04-27Auto merge of #70073 - wesleywiser:mir_opt_level_0, r=oli-obkbors-55/+81
Don't run various MIR optimizations at mir-opt-level=0 Add missing checks for mir-opt-level to non-essential MIR passes. I verified that this can still bootstrap even with these passes disabled. r? @oli-obk cc @RalfJung
2020-04-26Rollup merge of #71551 - gizmondo:gen-index-vec, r=jonas-schievinkDylan DPC-21/+13
Minor refactoring around IndexVec usage in generator transformation Replace hash map with IndexVec for liveness data. Utilize IndexVec::push return value to avoid redundant object creation. r? @eddyb
2020-04-26fmtRalf Jung-1/+1
2020-04-26organize Debug/Display impls a bit more; avoid sign-ignorant decimal displayRalf Jung-2/+4
2020-04-26print pointers more compactly when they are too bigRalf Jung-0/+4
2020-04-26sync alloc dump and pointer printingRalf Jung-12/+15
2020-04-26remove obsolete commentTshepang Lekhonkhobe-7/+0
2020-04-26Rollup merge of #71562 - matthiaskrgr:cl7ppy, r=Dylan-DPCDylan DPC-2/+2
fix more clippy warnings clippy::{redundant_pattern_matching, clone_on_copy, iter_cloned_collect, option_as_ref_deref, match_ref_pats} r? @Dylan-DPC
2020-04-26fix more clippy warningsMatthias Krüger-2/+2
clippy::{redundant_pattern_matching, clone_on_copy, iter_cloned_collect, option_as_ref_deref, match_ref_pats}
2020-04-26Rollup merge of #71392 - ecstatic-morse:body-predecessor-cache-arc, ↵Dylan DPC-3/+3
r=nikomatsakis Don't hold the predecessor cache lock longer than necessary #71044 returns a `LockGuard` with the predecessor cache to callers of `Body::predecessors`. As a result, the lock around the predecessor cache could be held for an arbitrarily long time. This PR uses reference counting for ownership of the predecessor cache, meaning the lock is only ever held within `PredecessorCache::compute`. Checking this API for potential sources of deadlock is much easier now, since we no longer have to consider its consumers, only its internals. This required removing `predecessors_for`, since there is no equivalent to `LockGuard::map` for `Arc` and `Rc`. I believe this could be emulated with `owning_ref::{Arc,Rc}Ref`, but I don't think it's necessary. Also, we continue to return an opaque type from `Body::predecessors` with the lifetime of the `Body`, not `'static`. This depends on #71044. Only the last two commits are new. r? @nikomatsakis
2020-04-26Rollup merge of #71140 - oli-obk:static_cycle, r=RalfJungDylan DPC-8/+17
[breaking change] Disallow statics initializing themselves fixes #71078 Self-initialization is unsound because it breaks privacy assumptions that unsafe code can make. In ```rust pub mod foo { #[derive(Debug, Copy, Clone)] pub struct Foo { x: (), } } pub static FOO: foo::Foo = FOO; ``` unsafe could could expect that ony functions inside the `foo` module were able to create a value of type `Foo`.
2020-04-26Rollup merge of #70043 - mark-i-m:def-kind-more, r=eddybDylan DPC-11/+8
Add all remaining `DefKind`s. r? @eddyb or @Centril ~~I'm not sure if this is what you were thinking of. There are also a few places where I'm not sure what the correct choice is because I don't fully understand the meaning of some variants.~~ ~~In general, it feels a bit odd to add some of these as `DefKind`s (e.g. `Arm`) because they don't feel like definitions. Are there things that it makes sense not to add?~~
2020-04-25Rollup merge of #71544 - cuviper:filter_map_next, r=Mark-SimulacrumDylan DPC-4/+2
Replace filter_map().next() calls with find_map() These are semantically the same, but `find_map()` is more concise.
2020-04-25Replace hash map with IndexVec for liveness data.Alex Aktsipetrov-21/+13
Utilize IndexVec::push to avoid redundant object creation.
2020-04-25Rollup merge of #71533 - pnkfelix:revert-70566-for-const-validation-fix, ↵Dylan DPC-5/+5
r=Dylan-DPC Revert PR 70566 for const validation fix This is a port of PR #71441 but ported to the master branch, as discussed in [yesterday's T-compiler meeting](https://zulip-archive.rust-lang.org/131828tcompiler/88751weeklymeeting2020042354818.html#195065903)
2020-04-24Replace filter_map().next() calls with find_map()Josh Stone-4/+2
These are semantically the same, but `find_map()` is more concise.