summary refs log tree commit diff
path: root/src/librustc_mir/interpret
AgeCommit message (Collapse)AuthorLines
2020-06-01Auto merge of #71192 - oli-obk:eager_alloc_id_canonicalization, r=wesleywiserbors-0/+16
Make TLS accesses explicit in MIR r? @rust-lang/wg-mir-opt cc @RalfJung @vakaras for miri thread locals cc @bjorn3 for cranelift fixes #70685
2020-05-30Rollup merge of #72772 - RalfJung:valid-char, r=petrochenkovRalf Jung-1/+1
miri validation: clarify valid values of 'char' The old text said "expected a valid unicode codepoint", which is not actually correct -- it has to be a scalar value (which is a code point that is not part of a surrogate pair).
2020-05-30Rollup merge of #72540 - davidtwco:issue-67552-mono-collector-comparison, ↵Ralf Jung-1/+1
r=varkor mir: adjust conditional in recursion limit check Fixes #67552. This PR adjusts the condition used in the recursion limit check of the monomorphization collector, from `>` to `>=`. In #67552, the test case had infinite indirect recursion, repeating a handful of functions (from the perspective of the monomorphization collector): `rec` -> `identity` -> `Iterator::count` -> `Iterator::fold` -> `Iterator::next` -> `rec`. During this process, `resolve_associated_item` was invoked for `Iterator::fold` (during the construction of an `Instance`), and ICE'd due to substitutions needing inference. However, previous iterations of this recursion would have called this function for `Iterator::fold` - and did! - and succeeded in doing so (trivially checkable from debug logging, `()` is present where `_` is in the substs of the failing execution). The expected outcome of this test case would be a recursion limit error (which is present when the `identity` fn indirection is removed), and the recursion depth of `rec` is increasing (other functions finish collecting their neighbours and thus have their recursion depths reset). When the ICE occurs, the recursion depth of `rec` is 256 (which matches the recursion limit), which suggests perhaps that a different part of the compiler is using a `>=` comparison and returning a different result on this recursion rather than what it returned in every previous recursion, thus stopping the monomorphization collector from reporting an error on the next recursion, where `recursion_depth_of_rec > 256` would have been true. With grep and some educated guesses, we can determine that the recursion limit check at line 818 in `src/librustc_trait_selection/traits/project.rs` is the other check that is using a different comparison. Modifying either comparison to be `>` or `>=` respectively will fix the error, but changing the monomorphization collector produces the nicer error.
2020-05-30Make TLS accesses explicit in MIROliver Scherer-0/+16
2020-05-30miri validation: clarify valid values of 'char'Ralf Jung-1/+1
2020-05-30Rollup merge of #72419 - RalfJung:read-discriminant, r=oli-obk,eddybYuki Okushi-79/+105
Miri read_discriminant: return a scalar instead of raw underlying bytes r? @oli-obk @eddyb
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-3/+54
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2020-05-30more type sanity checks in MiriRalf Jung-2/+18
2020-05-29Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJungRalf Jung-3/+54
Make pointer offset methods/intrinsics const Implements #71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
2020-05-29Rollup merge of #72591 - sexxi-goose:rename_upvar_list-to-closure_captures, ↵Dylan DPC-1/+1
r=matthewjasper librustc_middle: Rename upvar_list to closure_captures As part of supporting RFC 2229, we will be capturing all the places that are mentioned in a closure. Currently the `upvar_list` field gives access to a `FxIndexMap<HirId, Upvar>` map. Eventually this will change, with the `upvar_list` having a more general structure that expresses captured paths, not just the mentioned `upvars`. We will make those changes in subsequent PRs. This commit modifies the name of the `upvar_list` map to `closure_captures` in `TypeckTables`. r? @matthewjasper
2020-05-28standardize limit comparisons with `Limit` typeDavid Wood-1/+1
This commit introduces a `Limit` type which is used to ensure that all comparisons against limits within the compiler are consistent (which can result in ICEs if they aren't). Signed-off-by: David Wood <david@davidtw.co>
2020-05-27Add additional checks for isize overflowJoe Richey-3/+2
We now perform the correct checks even if the pointer size differs between the host and target. Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-28Auto merge of #72494 - lcnr:predicate-cleanup, r=nikomatsakisbors-7/+7
Pass more `Copy` types by value. There are a lot of locations where we pass `&T where T: Copy` by reference, which should both be slightly less performant and less readable IMO. This PR currently consists of three fairly self contained commits: - passes `ty::Predicate` by value and stops depending on `AsRef<ty::Predicate>`. - changes `<&List<_>>::into_iter` to iterate over the elements by value. This would break `List`s of non copy types. But as the only list constructor requires `T` to be copy anyways, I think the improved readability is worth this potential future restriction. - passes `mir::PlaceElem` by value. Mir currently has quite a few copy types which are passed by reference, e.g. `Local`. As I don't have a lot of experience working with MIR, I mostly did this to get some feedback from people who use MIR more frequently - tries to reuse `ty::Predicate` in case it did not change in some places, which should hopefully fix the regression caused by #72055 r? @nikomatsakis for the first commit, which continues the work of #72055 and makes adding `PredicateKind::ForAll` slightly more pleasant. Feel free to reassign though
2020-05-26Add checks and tests for computing abs(offset_bytes)Joe Richey-2/+3
The previous code paniced if offset_bytes == i64::MIN. This commit: - Properly computes the absoulte value to avoid this panic - Adds a test for this edge case Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25Rename upvar_list to closure_capturesDhruv Jauhar-1/+1
As part of supporting RFC 2229, we will be capturing all the places that are mentioned in a closure. Currently the upvar_list field gives access to a FxIndexMap<HirId, Upvar> map. Eventually this will change, with the upvar_list having a more general structure that expresses captured paths, not just the mentioned upvars. We will make those changes in subsequent PRs. This commit modifies the name of the upvar_list map to closure_captures in TypeckTables. Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com> Co-authored-by: Aman Arora <me@aman-arora.com>
2020-05-25librustc_mir: Add back use statementJoe Richey-0/+2
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25librustc_mir: Add support for const fn offset/arith_offsetJoe Richey-2/+51
Miri's pointer_offset_inbounds implementation has been moved into librustc_mir as ptr_offset_inbounds (to avoid breaking miri on a nightly update). The comments have been slightly reworked to better match `offset`'s external documentation about what causes UB. The intrinsic implementations are taken directly from miri. Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25fix discriminant_ty for non-enumsRalf Jung-2/+2
2020-05-25Add helper method for determining the type of a discriminantRalf Jung-39/+24
2020-05-25Format and more tracingRalf Jung-2/+2
2020-05-25assert that types without discriminant use variant idx of 0Ralf Jung-1/+2
2020-05-25comments and refactor variable namesRalf Jung-38/+46
2020-05-25Miri: refactor read_discriminant and make it return ScalarRalf Jung-68/+84
2020-05-24comment nitRalf Jung-1/+1
2020-05-24use helper method for determining size of int typeRalf Jung-15/+11
2020-05-24Fix unsizing castsRalf Jung-20/+18
2020-05-24Miri casts: do not blindly rely on dest typeRalf Jung-51/+76
2020-05-24make some cast helpers infallibleRalf Jung-29/+17
2020-05-23take mir::PlaceElem by valueBastian Kauschke-7/+7
2020-05-23iterate List by valueBastian Kauschke-2/+2
2020-05-22Use `OnceCell` instead of `Once`Dylan MacKenzie-1/+1
2020-05-22Rollup merge of #71610 - divergentdave:InvalidUndefBytes-range, r=RalfJungRalf Jung-6/+8
InvalidUndefBytes: Track size of undef region used This PR adds a size to `UndefinedBehaviorInfo::InvalidUndefBytes`, to keep track of how many undefined bytes in a row were accessed, and changes a few methods to pass this information through. This additional information will eventually be used in Miri to improve diagnostics for this UB error. See also rust-lang/miri#1354 for prior discussion. I expect Miri will break the next time its submodule is updated, due to this change to the `InvalidUndefBytes`. (The current commit for src/tools/miri predates rust-lang/miri#1354, and thus does not try to destructure the `InvalidUndefBytes` variant) I have a corresponding change prepared for that repository. r? @RalfJung
2020-05-21fix discriminant sign extensionRalf Jung-1/+4
2020-05-21Auto merge of #70705 - lcnr:generic_discriminant, r=nikomatsakisbors-3/+6
Use `T`'s discriminant type in `mem::Discriminant<T>` instead of `u64`. fixes #70509 Adds the lang-item `discriminant_kind`. Updates the function signature of `intrinsics::discriminant_value`. Adds the *probably permanently unstable* trait `DiscriminantKind`. `mem::Discriminant` should now be smaller in some cases. r? @ghost
2020-05-19update codegen of `discriminant_value`Bastian Kauschke-3/+6
2020-05-18Add asm! to MIRAmanieu d'Antras-0/+3
2020-05-16Auto merge of #71665 - RalfJung:miri-intern-no-ice, r=oli-obkbors-153/+180
Miri interning: replace ICEs by proper errors Fixes https://github.com/rust-lang/rust/issues/71316 I also did some refactoring, as I kept being confused by all the parameters to `intern_shallow`, some of which have invalid combinations (such as a mutable const). So instead `InternMode` now contains all the information that is needed and invalid combinations are ruled out by the type system. Also I removed interpreter errors from interning. We already ignored almost all errors, and the `ValidationFailure` errors that we handled separately actually cannot ever happen here. The only interpreter failure that was actually reachable was the UB on dangling pointers -- and arguably, a dangling raw pointer is not UB, so the error was not even correct. It's just that the rest of the compiler does not like "dangling" `AllocId`. It should be possible to review the 3 commits separately. r? @oli-obk Cc @rust-lang/wg-const-eval
2020-05-15InvalidUninitBytes: Track more info about accessDavid Cook-6/+8
2020-05-14Rollup merge of #72150 - jackh726:unnorm_projection, r=nikomatsakisRalf Jung-2/+0
Remove UnnormalizedProjection This was only used for the old chalk integration with chalk-engine r? @nikomatsakis
2020-05-12strings do not have to be valid UTF-8 any moreRalf Jung-3/+4
2020-05-12Remove ty::UnnormalizedProjectionJack Huey-2/+0
2020-05-10TypoRalf Jung-1/+1
Co-Authored-By: Oliver Scherer <github35764891676564198441@oli-obk.de>
2020-05-10fmtRalf Jung-27/+16
2020-05-10avoid raising interpreter errors from interningRalf Jung-15/+24
2020-05-10remove some dead code, and assert we do not swallow allocating errorsRalf Jung-18/+19
2020-05-10Miri interning: replace ICEs by proper errors, make intern_shallow type ↵Ralf Jung-119/+147
signature more precise
2020-05-09Rollup merge of #71508 - oli-obk:alloc_map_unlock, r=RalfJungRalf Jung-19/+17
Simplify the `tcx.alloc_map` API This PR changes all functions that require manually locking the `alloc_map` to functions on `TyCtxt` that lock the map internally. In the same step we make the `TyCtxt::alloc_map` field private. r? @RalfJung
2020-05-08Auto merge of #71418 - hbina:rename_miri_undef, r=RalfJungbors-24/+24
Renamed "undef" -> "uninit" 1. InvalidUndefBytes -> InvalidUninitBytes 2. ScalarMaybeUndef -> ScalarMaybeUninit 3. UndefMask -> InitMask Related issue #71193
2020-05-08Create a convenience wrapper for `get_global_alloc(id).unwrap()`Oliver Scherer-2/+2
2020-05-08Move `unwrap_fn` and `unwrap_memory` to `GlobalAlloc`Oliver Scherer-1/+1