about summary refs log tree commit diff
path: root/src/librustc_mir
AgeCommit message (Collapse)AuthorLines
2020-05-30Rollup merge of #72625 - Amanieu:asm-srcloc, r=petrochenkovRalf Jung-4/+22
Improve inline asm error diagnostics Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics. The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line `srcloc` attribute to map an error in inline assembly directly to the relevant line of source code. Incidentally also fixes #71639 by disabling `srcloc` metadata during LTO builds since we don't know what crate it might have come from. We can only resolve `srcloc`s from the currently crate since it indexes into the source map for the current crate. Fixes #72664 Fixes #71639 r? @petrochenkov ### Old style ```rust #![feature(llvm_asm)] fn main() { unsafe { let _x: i32; llvm_asm!( "mov $0, $1 invalid_instruction $0, $1 mov $0, $1" : "=&r" (_x) : "r" (0) :: "intel" ); } } ``` ``` error: <inline asm>:3:14: error: invalid instruction mnemonic 'invalid_instruction' invalid_instruction ecx, eax ^~~~~~~~~~~~~~~~~~~ --> src/main.rs:6:9 | 6 | / llvm_asm!( 7 | | "mov $0, $1 8 | | invalid_instruction $0, $1 9 | | mov $0, $1" ... | 12 | | :: "intel" 13 | | ); | |__________^ ``` ### New style ```rust #![feature(asm)] fn main() { unsafe { asm!( "mov {0}, {1} invalid_instruction {0}, {1} mov {0}, {1}", out(reg) _, in(reg) 0i64, ); } } ``` ``` error: invalid instruction mnemonic 'invalid_instruction' --> test.rs:7:14 | 7 | invalid_instruction {0}, {1} | ^ | note: instantiated into assembly here --> <inline asm>:3:14 | 3 | invalid_instruction rax, rcx | ^^^^^^^^^^^^^^^^^^^ ```
2020-05-30miri errors: rename InvalidDiscriminant -> InvalidTagRalf Jung-6/+6
2020-05-30tag/niche terminology cleanupRalf Jung-39/+37
2020-05-30Rollup merge of #72540 - davidtwco:issue-67552-mono-collector-comparison, ↵Ralf Jung-5/+6
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-30Rollup merge of #72521 - Amanieu:fix-72484, r=petrochenkovRalf Jung-2/+9
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items Fixes #72484
2020-05-30Rollup merge of #72299 - lcnr:sized_help, r=petrochenkovRalf Jung-8/+9
more `LocalDefId`s
2020-05-30Make TLS accesses explicit in MIROliver Scherer-6/+40
2020-05-30more `LocalDefId`sBastian Kauschke-8/+9
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-30Be more careful around ty::Error in generatorsJonas Schievink-26/+43
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-92/+229
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 #72103 - lcnr:borrowck-localdefid, r=jonas-schievinkRalf Jung-66/+58
borrowck `DefId` -> `LocalDefId` Replaces some `DefId`s which must always be local with `LocalDefId` in `librustc_mir/borrowck`. cc @marmeladema
2020-05-29Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, ↵Ralf Jung-23/+117
r=nikomatsakis Implement RFC 2585: unsafe blocks in unsafe fn Tracking issue: #71668 r? @RalfJung cc @nikomatsakis
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-2/+2
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-29Improve inline asm error diagnosticsAmanieu d'Antras-4/+22
2020-05-28remove redundant `mk_const`Bastian Kauschke-1/+1
2020-05-28standardize limit comparisons with `Limit` typeDavid Wood-5/+6
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-28mir: adjust conditional in recursion limit checkDavid Wood-1/+1
This commit 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. 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-35/+35
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-27Add explanation about taking the minimum of the two lintsLeSeulArtichaut-0/+11
2020-05-27Fix wrong conflict resolutionLeSeulArtichaut-7/+1
2020-05-27Use the lowest of `unsafe_op_in_unsafe_fn` and `safe_borrow_packed` for ↵LeSeulArtichaut-5/+28
packed borrows in unsafe fns
2020-05-27Fix inverted `if` conditionLeSeulArtichaut-1/+1
2020-05-27Apply suggestions from code reviewLeSeulArtichaut-23/+44
2020-05-27Implement RFC 2585LeSeulArtichaut-9/+54
2020-05-26Rollup merge of #72401 - ecstatic-morse:issue-72394, r=eddybDylan DPC-2/+2
Use correct function for detecting `const fn` in unsafety checking Resolves #72394.
2020-05-26Rollup merge of #72270 - RalfJung:lint-ref-to-packed, r=oli-obkDylan DPC-1/+71
add a lint against references to packed fields Creating a reference to an insufficiently aligned packed field is UB and should be disallowed, both inside and outside of `unsafe` blocks. However, currently there is no stable alternative (https://github.com/rust-lang/rust/issues/64490) so all we do right now is have a future incompatibility warning when doing this outside `unsafe` (https://github.com/rust-lang/rust/issues/46043). This adds an allow-by-default lint. @retep998 suggested this can help early adopters avoid issues. It also means we can then do a crater run where this is deny-by-default as suggested by @joshtriplett. I guess the main thing to bikeshed is the lint name. I am not particularly happy with "packed_references" as it sounds like the packed field has reference type. I chose this because it is similar to "safe_packed_borrows". What about "reference_to_packed" or "unaligned_reference" or so?
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-26Auto merge of #72093 - jonas-schievink:unmut, r=oli-obkbors-9/+111
Avoid `Operand::Copy` with `&mut T` This is generally unsound to do, as the copied type is assumed to implement `Copy`. Closes https://github.com/rust-lang/rust/issues/46420
2020-05-25Display information about captured variable in `FnMut` errorAaron Hill-52/+123
Fixes #69446 When we encounter a region error involving an `FnMut` closure, we display a specialized error message. However, we currently do not tell the user which upvar was captured. This makes it difficult to determine the cause of the error, especially when the closure is large. This commit records marks constraints involving closure upvars with `ConstraintCategory::ClosureUpvar`. When we decide to 'blame' a `ConstraintCategory::Return`, we additionall store the captured upvar if we found a `ConstraintCategory::ClosureUpvar` in the path. When generating an error message, we point to relevant spans if we have closure upvar information available. We further customize the message if an `async` closure is being returned, to make it clear that the captured variable is being returned indirectly.
2020-05-25Rename upvar_list to closure_capturesDhruv Jauhar-2/+2
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-25Rollup merge of #72538 - rakshith-ravi:refactor/remove-const-query, r=oli-obkDylan DPC-32/+1
Removed all instances of const_field. Fixes #72264 r? @oli-obk
2020-05-25Rollup merge of #72451 - ecstatic-morse:nrvo-type-mismatch, r=matthewjasperDylan DPC-12/+6
Perform MIR NRVO even if types don't match This is the most straightforward way to resolve #72428, but it could cause problems in codegen since the type of `_0` may no longer match the return type of the body.
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-25Always validate MIR after optimizingJonas Schievink-0/+5
2020-05-25Add a small MIR validation passJonas Schievink-1/+93
2020-05-25Avoid `Operand::Copy` with `&mut T`Jonas Schievink-8/+13
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-25rename lintRalf Jung-4/+4
2020-05-25Auto merge of #72562 - RalfJung:rollup-2ngjgwi, r=RalfJungbors-98/+110
Rollup of 5 pull requests Successful merges: - #71940 (Add `len` and `slice_from_raw_parts` to `NonNull<[T]>`) - #72525 (Miri casts: do not blindly rely on dest type) - #72537 (Fix InlineAsmOperand expresions being visited twice during liveness checking) - #72544 (librustc_middle: Rename upvars query to upvars_mentioned) - #72551 (First draft documenting Debug stability.) Failed merges: r? @ghost