about summary refs log tree commit diff
path: root/src/test/mir-opt
AgeCommit message (Collapse)AuthorLines
2017-11-28tests: update to include move annotations in MIR.Eduard-Mihai Burtescu-128/+128
2017-11-27Auto merge of #44884 - arielb1:pack-safe, r=nikomatsakis,eddybbors-0/+68
Make accesses to fields of packed structs unsafe To handle packed structs with destructors (which you'll think are a rare case, but the `#[repr(packed)] struct Packed<T>(T);` pattern is ever-popular, which requires handling packed structs with destructors to avoid monomorphization-time errors), drops of subfields of packed structs should drop a local move of the field instead of the original one. That's it, I think I'll use a strategy suggested by @Zoxc, where this mir ``` drop(packed_struct.field) ``` is replaced by ``` tmp0 = packed_struct.field; drop tmp0 ``` cc #27060 - this should deal with that issue after codegen of drop glue is updated. The new errors need to be changed to future-compatibility warnings, but I'll rather do a crater run first with them as errors to assess the impact. cc @eddyb Things which still need to be done for this: - [ ] - handle `repr(packed)` structs in `derive` the same way I did in `Span`, and use derive there again - [ ] - implement the "fix packed drops" pass and call it in both the MIR shim and validated MIR pipelines - [ ] - do a crater run - [ ] - convert the errors to compatibility warnings
2017-11-26Update tests for -Zborrowck-mir -> -Zborrowck=mode migrationest31-2/+1
2017-11-26fix codegen of drops of fields of packed structsAriel Ben-Yehuda-0/+68
2017-11-26Auto merge of #46100 - KiChjang:mass-dead-check, r=nikomatsakisbors-0/+1
Kill the storage for all locals on returning terminators Fixes #45704.
2017-11-25Disable region-liveness-drop-no-may-dangle.rsKeith Yeung-0/+1
2017-11-25InstCombine Len([_; N]) => const N in MIRScott McMurray-0/+33
2017-11-24Auto merge of #46093 - scottmcm:lower-128-mir, r=nagisabors-0/+253
Add a MIR pass to lower 128-bit operators to lang item calls Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet. This isn't really useful on its own, but the declarations for the lang items need to be in the compiler before compiler-builtins can be updated to define them, so this is part 1 of at least 3. cc https://github.com/rust-lang/rust/issues/45676 @est31 @nagisa
2017-11-21Auto merge of #45879 - nikomatsakis:nll-kill-cyclic-closures, r=arielb1bors-2/+54
move closure kind, signature into `ClosureSubsts` Instead of using side-tables, store the closure-kind and signature in the substitutions themselves. This has two key effects: - It means that the closure's type changes as inference finds out more things, which is very nice. - As a result, it avoids the need for the `freshen_closure_like` code (though we still use it for generators). - It avoids cyclic closures calls. - These were never meant to be supported, precisely because they make a lot of the fancy inference that we do much more complicated. However, due to an oversight, it was previously possible -- if challenging -- to create a setup where a closure *directly* called itself (see e.g. #21410). We have to see what the effect of this change is, though. Needs a crater run. Marking as [WIP] until that has been assessed. r? @arielb1
2017-11-22Rollup merge of #46157 - martinlindhe:master, r=kennytmkennytm-1/+1
fix some typos This is the result of me testing out a WIP source code typo-finder and your project was the random target this time.
2017-11-21fix some typosMartin Lindhe-1/+1
2017-11-21clean the Debug impl for CrateNum and DefIdAriel Ben-Yehuda-10/+10
before: DefId { krate: CrateNum(11), index: DefIndex(0:6) => foo[8787]::Mapper[0]::OtherType[0] } } after: DefId(11:0:6 ~ foo[8787]::Mapper[0]::OtherType[0])
2017-11-20Handle shifts properlyScott McMurray-16/+26
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)` * The unchecked ones just take u32, like the `*_sh?` methods in core * Because shift-by-anything is allowed, cast into a new local for every shift
2017-11-20Add type checking for the lang itemScott McMurray-20/+28
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
2017-11-19Include tuple projections in MIR testsScott McMurray-0/+34
2017-11-19fix closure inlining by spilling arguments to a temporaryNiko Matsakis-2/+54
2017-11-18Add a MIR pass to lower 128-bit operators to lang item callsScott McMurray-0/+201
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
2017-11-17MIR: hide .rodata constants vs by-ref ABI clash in trans.Eduard-Mihai Burtescu-11/+5
2017-11-16fix mir-opt NLL tests -- variable `'_#0r` is now `'static`Niko Matsakis-25/+25
2017-11-15Auto merge of #45913 - sinkuu:mir-inlining-closure, r=arielb1bors-0/+42
Handle closures correctly in MIR inlining Fixes #45894.
2017-11-14Fix testShotaro Yamada-19/+8
2017-11-14Handle closures correctly in MIR inliningShotaro Yamada-0/+53
2017-11-14always add an unreachable branch on matches to give more info to llvm about ↵Djzin-26/+32
which values are possible
2017-11-10Separately eliminate self-assignmentssinkuu-1/+2
2017-11-10Fix MIR CopyPropagation errneously propagating assignments to function argumentssinkuu-0/+115
2017-11-09change separator from `.` to `-`Mikhail Modin-20/+20
2017-11-09change MIR dump filenames from `nodeN` to `DefPath`Mikhail Modin-130/+130
2017-11-07Fix some rebasing fallout.Michael Woerister-5/+8
2017-11-07Update mir-opt tests.Michael Woerister-5/+20
2017-11-06Auto merge of #45668 - nikomatsakis:nll-free-region, r=arielb1bors-0/+34
extend NLL with preliminary support for free regions on functions This PR extends https://github.com/rust-lang/rust/pull/45538 with support for free regions. This is pretty preliminary and will no doubt want to change in various ways, particularly as we add support for closures, but it's enough to get the basic idea in place: - We now create specific regions to represent each named lifetime declared on the function. - Region values can contain references to these regions (represented for now as a `BTreeSet<RegionIndex>`). - If we wind up trying to infer that `'a: 'b` must hold, but no such relationship was declared, we report an error. It also does a number of drive-by refactorings. r? @arielb1 cc @spastorino
2017-11-05Auto merge of #45072 - nikomatsakis:issue-38714, r=arielb1bors-4/+4
new rules for merging expected and supplied types in closure signatures As uncovered in #38714, we currently have some pretty bogus code for combining the "expected signature" of a closure with the "supplied signature". To set the scene, consider a case like this: ```rust fn foo<F>(f: F) where F: for<'a> FnOnce(&'a u32) -> &'a u32 // ^ *expected* signature comes from this where-clause { ... } fn main() { foo(|x: &u32| -> &u32 { .. } // ^^^^^^^^^^^^^^^^^ supplied signature // comes from here } ``` In this case, the supplied signature (a) includes all the parts and (b) is the same as the expected signature, modulo the names used for the regions. But often people supply only *some* parts of the signature. For example, one might write `foo(|x| ..)`, leaving *everything* to be inferred, or perhaps `foo(|x: &u32| ...)`, which leaves the return type to be inferred. In the current code, we use the expected type to supply the types that are not given, but otherwise use the type the user gave, except for one case: if the user writes `fn foo(|x: _| ..)` (i.e., an underscore at the outermost level), then we will take the expected type (rather than instantiating a fresh type variable). This can result in nonsensical situations, particularly with bound regions that link the types of parameters to one another or to the return type. Consider `foo(|x: &u32| ...)` -- if we *literally* splice the expected return type of `&'a u32` together with what the user gave, we wind up with a signature like `for<'a> fn(&u32) -> &'a u32`. This is not even permitted as a type, because bound regions like `'a` must appear also in the arguments somewhere, which is why #38714 leads to an ICE. This PR institutes some new rules. These are not meant to be the *final* set of rules, but they are a kind of "lower bar" for what kind of code we accept (i.e., we can extend these rules in the future to be smarter in some cases, but -- as we will see -- these rules do accept some things that we then would not be able to back off from). These rules are derived from a few premises: - First and foremost, anonymous regions in closure annotation are mostly requests for the code to "figure out the right lifetime" and shouldn't be read too closely. So for example when people write a closure signature like `|x: &u32|`, they are really intended for us to "figure out" the right region for `x`. - In contrast, the current code treats this supplied type as being more definitive. In particular, writing `|x: &u32|` would always result in the region of `x` being bound in the closure type. In other words, the signature would be something like `for<'a> fn(&'a u32)` -- this is derived from the fact that `fn(&u32)` expands to a type where the region is bound in the fn type. - This PR takes a different approach. The "binding level" for reference types appearing in closure signatures can be informed in some cases by the expected signature. So, for example, if the expected signature is something like `(&'f u32)`, where the region of the first argument appears free, then for `|x: &u32|`, the new code would infer `x` to also have the free region `'f`. - This inference has some limits. We don't do this for bindings that appear within the selected types themselves. So e.g. `|x: fn(&u32)|`, when combined with an expected type of `fn(fn(&'f u32))`, would still result in a closure that expects `for<'a> fn(&'a u32)`. Such an annotation will ultimately result in an error, as it happens, since `foo` is supplying a `fn(&'f u32)` to the closure, but the closure signature demands a `for<'a> fn(&'a u32)`. But still we choose to trust it and have the user change it. - I wanted to preserve the rough intuition that one can copy-and-paste a type out of the fn signature and into the fn body without dramatically changing its meaning. Interestingly, if one has `|x: &u32|`, then regardless of whether the region of `x` is bound or free in the closure signature, it is also free in the region body, and that is also true when one writes `let x: &u32`, so that intuition holds here. But the same would not be true for `fn(&u32)`, hence the different behavior. - Second, we must take either **all** the references to bound regions from the expected type or **none**. The current code, as we saw, will happily take a bound region in the return type but drop the other place where it is used, in the parameters. Since bound regions are all about linking multiple things together, I think it's important not to do that. (That said, we could conceivably be a bit less strict here, since the subtyping rules will get our back, but we definitely don't want any bound regions that appear only in the return type.) - Finally, we cannot take the bound region names from the supplied types and "intermix" them with the names from the expected types. - We *could* potentially do some alpha renaming, but I didn't do that. - Ultimately, if the types the user supplied do not match expectations in some way that we cannot recover from, we fallback to deriving the closure signature solely from those expected types. - For example, if the expected type is `u32` but the user wrote `i32`. - Or, more subtle, if the user wrote e.g. `&'x u32` for some named lifetime `'x`, but the expected type includes a bound lifetime (`for<'a> (&'a u32)`). In that case, preferring the type that the user explicitly wrote would hide an appearance of a bound name from the expected type, and we try to never do that. The detailed rules that I came up with are found in the code, but for ease of reading I've also [excerpted them into a gist](https://gist.github.com/nikomatsakis/e69252a2b57e6d97d044c2f254c177f1). I am not convinced they are correct and would welcome feedback for alternative approaches. (As an aside, the way I think I would ultimately *prefer* to think about this is that the conversion from HIR types to internal types could be parameterized by an "expected type" that it uses to guide itself. However, since that would be a pain, I opted *in the code* to first instantiate the supplied types as `Ty<'tcx>` and then "merge" those types with the `Ty<'tcx>` from the expected signature.) I think we should probably FCP this before landing. cc @rust-lang/lang r? @arielb1
2017-11-02new rules for merging expected/supplied types in closure signaturesNiko Matsakis-4/+4
Also, fix numbering in mir-opt tests. We are now anonymizing more consistently, I think, and hence some of the `TyAnon` indices shifted.
2017-11-02replace Add by tupleMikhail Modin-18/+18
2017-11-02add `mir-opt/named-lifetimes-basic.rs`Niko Matsakis-0/+34
This lets us inspect the regions we infer around named arguments.
2017-11-02change mir stage in testMikhail Modin-7/+7
2017-11-02add one more sampleMikhail Modin-6/+68
2017-11-02fix pre binding false edgesMikhail Modin-79/+83
2017-11-02fix opt-mir test and remove false edge if no guardMikhail Modin-70/+74
2017-11-02add TerminatorKind::FalseEdges and use it in matchesMikhail Modin-0/+166
2017-10-31patch mir-opt reference filesNiko Matsakis-7/+13
2017-10-31change region display to `'_#Nr`, update the `newtype_index!` macroNiko Matsakis-14/+14
The macro now takes a format string. It no longer defaults to using the type name. Didn't seem worth going through contortions to maintain. I also changed most of the debug formats to be `foo[N]` instead of `fooN`.
2017-10-31add basic region subtyping inferenceSantiago Pastorino-0/+49
2017-10-31add reborrow constraintsSantiago Pastorino-0/+39
2017-10-31update the format of liveness debug dumps to be more readableNiko Matsakis-46/+23
2017-10-31add subregion between borrow region and resulting referenceNiko Matsakis-0/+50
2017-10-31preliminary support for may-dangle attribute and drop constraintsNiko Matsakis-0/+50
2017-10-31extend liveness to distinguish "drop" and "non-drop" usesNiko Matsakis-25/+94
2017-10-31introduce liveness constraints into NLL codeNiko Matsakis-0/+55
And do a bunch of gratuitious refactoring that I did not bother to separate into nice commits.
2017-10-31extend liveness to compute intrablock liveness and add unit testsNiko Matsakis-5/+18
2017-10-31factor out `pre_defs` field by going backwardsNiko Matsakis-0/+36