summary refs log tree commit diff
path: root/src/librustc_mir/transform
AgeCommit message (Collapse)AuthorLines
2017-12-21Revert "Auto merge of #45225 - eddyb:trans-abi, r=arielb1"Ariel Ben-Yehuda-5/+6
This reverts commit f50fd075c2555d8511ccee8a7fe7aee3f2c45e14, reversing changes made to 5041b3bb3d953a14f32b15d1e41341c629acae12.
2017-11-19Auto merge of #45225 - eddyb:trans-abi, r=arielb1bors-6/+5
Refactor type memory layouts and ABIs, to be more general and easier to optimize. To combat combinatorial explosion, type layouts are now described through 3 orthogonal properties: * `Variants` describes the plurality of sum types (where applicable) * `Single` is for one inhabited/active variant, including all C `struct`s and `union`s * `Tagged` has its variants discriminated by an integer tag, including C `enum`s * `NicheFilling` uses otherwise-invalid values ("niches") for all but one of its inhabited variants * `FieldPlacement` describes the number and memory offsets of fields (if any) * `Union` has all its fields at offset `0` * `Array` has offsets that are a multiple of its `stride`; guarantees all fields have one type * `Arbitrary` records all the field offsets, which can be out-of-order * `Abi` describes how values of the type should be passed around, including for FFI * `Uninhabited` corresponds to no values, associated with unreachable control-flow * `Scalar` is ABI-identical to its only integer/floating-point/pointer "scalar component" * `ScalarPair` has two "scalar components", but only applies to the Rust ABI * `Vector` is for SIMD vectors, typically `#[repr(simd)]` `struct`s in Rust * `Aggregate` has arbitrary contents, including all non-transparent C `struct`s and `union`s Size optimizations implemented so far: * ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.: * `Option<!>` is 0 bytes * `Result<T, !>` has the same size as `T` * using arbitrary niches, not just `0`, to represent a data-less variant, e.g.: * `Option<bool>`, `Option<Option<bool>>`, `Option<Ordering>` are all 1 byte * `Option<char>` is 4 bytes * using a range of niches to represent *multiple* data-less variants, e.g.: * `enum E { A(bool), B, C, D }` is 1 byte Code generation now takes advantage of `Scalar` and `ScalarPair` to, in more cases, pass around scalar components as immediates instead of indirectly, through pointers into temporary memory, while avoiding LLVM's "first-class aggregates", and there's more untapped potential here. Closes #44426, fixes #5977, fixes #14540, fixes #43278.
2017-11-19rustc: move size, align & primitive_align from Abi::Aggregate to layout.Eduard-Mihai Burtescu-1/+1
2017-11-19rustc: remove Ty::layout and move everything to layout_of.Eduard-Mihai Burtescu-3/+2
2017-11-18rustc_mir: always downcast enums, even if univariant.Eduard-Mihai Burtescu-3/+3
2017-11-18Remove return_ty from Mirloomaclin-10/+7
https://github.com/rust-lang/rust/issues/46001
2017-11-16Auto merge of #45825 - nikomatsakis:nll-factor-region-inference, r=arielb1bors-627/+922
integrate MIR type-checker with NLL inference This branch refactors NLL type inference so that it uses the MIR type-checker to gather constraints. Along the way, it also refactors how region constraints are gathered in the normal inference context mildly. The new setup is like this: - What used to be `region_inference` is split into two parts: - `region_constraints`, which just collects up sets of constraints - `lexical_region_resolve`, which does the iterative, lexical region resolution - When `resolve_regions_and_report_errors` is invoked, the inference engine converts the constraints into final values. - In the MIR type checker, however, we do not invoke this method, but instead periodically take the region constraints and package them up for the NLL solver to use later. - This allows us to track when and where those constraints were incurred. - We also remove the central fulfillment context from the MIR type checker, instead instantiating new fulfillment contexts at each point. This allows us to capture the set of obligations that occurred at a particular point, and also to ensure that if the same obligation arises at two points, we will enforce the region constraints at both locations. - The MIR type checker is also enhanced to instantiate late-bound-regions with fresh variables and handle a few other corner cases that arose. - I also extracted some of the 'outlives' logic from the regionck, which will be needed later (see future work) to handle the type-outlives relationships. One concern I have with this branch: since the MIR type checker is used even without the `-Znll` switch, I'm not sure if it will impact performance. One simple fix here would be to only enable the MIR type-checker if debug-assertions are enabled, since it just serves to validate the MIR. Longer term I hope to address this by improving the interface to the trait solver to be more query-based (ongoing work). There is plenty of future work left. Here are two things that leap to mind: - **Type-region outlives.** Currently, the NLL solver will ICE if it is required to handle a constraint like `T: 'a`. Fixing this will require a small amount of refactoring to extract the implied bounds code. I plan to follow a file-up bug on this (hopefully with mentoring instructions). - **Testing.** It's a good idea to enumerate some of the tricky scenarios that need testing, but I think it'd be nice to try and parallelize some of the actual test writing (and resulting bug fixing): - Same obligation occurring at two points. - Well-formedness and trait obligations of various kinds (which are not all processed by the current MIR type-checker). - More tests for how subtyping and region inferencing interact. - More suggestions welcome! r? @arielb1
2017-11-16Nit: fix typoNiko Matsakis-1/+1
2017-11-16integrate NLL with MIR type-checkerNiko Matsakis-160/+154
2017-11-16region_infer: improved debug loggingNiko Matsakis-9/+35
2017-11-16renumber: debug logs, use `visit_region` rather than `visit_rvalue`Niko Matsakis-22/+29
2017-11-16renumber: handle ReturnTy betterNiko Matsakis-1/+9
2017-11-16formalize giving ownership of region vars to region inf. contextNiko Matsakis-70/+57
2017-11-16infer: extract total number of region variables from infcxNiko Matsakis-13/+6
We are heading towards deeper integration with the region inference system in infcx; in particular, prior to the creation of the `RegionInferenceContext`, it will be the "owner" of the set of region variables.
2017-11-16replace `RegionIndex` with `RegionVid` (which now impls Idx)Niko Matsakis-52/+42
2017-11-16replace `usize` with `RegionIndex` in indices mapNiko Matsakis-17/+19
2017-11-16MIR typeck: refactor to track region constraintsNiko Matsakis-72/+242
2017-11-16MIR typeck: rustfmtNiko Matsakis-10/+4
2017-11-16fix rename to block_data in type_check.rsNiko Matsakis-2/+2
2017-11-16Auto merge of #45985 - arielb1:unsafe-dedup, r=eddybbors-1/+0
check_unsafety: fix unused unsafe block duplication The duplicate error message is later removed by error message deduplication, but it still appears on beta and is still a bug. r? @eddyb
2017-11-15modify MIR type-checker to process obligations as they are incurredNiko Matsakis-44/+37
2017-11-15apply rustfmt to `type_check`Niko Matsakis-256/+364
2017-11-15thread location info through mir typeck (but do not use)Niko Matsakis-49/+72
2017-11-15Auto merge of #45913 - sinkuu:mir-inlining-closure, r=arielb1bors-28/+66
Handle closures correctly in MIR inlining Fixes #45894.
2017-11-14check_unsafety: fix unused unsafe block duplicationAriel Ben-Yehuda-1/+0
The duplicate error message is later removed by error message deduplication, but it still appears on beta and is still a bug
2017-11-14Add TyCtxt::is_closureShotaro Yamada-8/+6
2017-11-14Make create_temp_necessary a methodShotaro Yamada-46/+40
2017-11-14Handle closures correctly in MIR inliningShotaro Yamada-10/+56
2017-11-14rustc: split off BodyOwnerKind from MirSource.Eduard-Mihai Burtescu-111/+125
2017-11-14rustc: remove unused MirSource::GeneratorDrop.Eduard-Mihai Burtescu-2/+0
2017-11-14rustc_mir: drive passes directly with a macro.Eduard-Mihai Burtescu-216/+104
2017-11-14rustc: move the MIR pass infrastructure and list to rustc_mir.Eduard-Mihai Burtescu-23/+197
2017-11-14Auto merge of #45909 - sinkuu:issue-45885, r=arielb1bors-5/+33
Normalize inlined function in MIR inliner Fixes #45885 r? @arielb1
2017-11-13mir-borrowck: Move `is_static_mut()` to `ty/utils.rs`Basile Desloges-21/+2
2017-11-12Auto merge of #45753 - sinkuu:mir_copyprop_arg, r=arielb1bors-4/+46
Fix MIR CopyPropagation errneously propagating assignments to function args Compiling this code with MIR CopyPropagation activated will result in printing `5`, because CopyProp errneously propagates the assignment of `5` to all `x`: ```rust fn bar(mut x: u8) { println!("{}", x); x = 5; } fn main() { bar(123); } ``` If a local is propagated, it will result in an ICE at trans due to an use-before-def: ```rust fn dummy(x: u8) -> u8 { x } fn foo(mut x: u8) { x = dummy(x); // this will assign a local to `x` } ``` Currently CopyProp conservatively gives up if there are multiple assignments to a local, but it is not took into account that arguments are already assigned from the beginning. This PR fixes the problem by preventing propagation of assignments to function arguments.
2017-11-10Separately eliminate self-assignmentssinkuu-4/+39
2017-11-10Fix MIR CopyPropagation errneously propagating assignments to function argumentssinkuu-0/+7
2017-11-10Normalize inlined function in MIR inlinerShotaro Yamada-5/+33
2017-11-10Auto merge of #45785 - arielb1:unsafe-fixes, r=eddybbors-69/+113
fixes to MIR effectck r? @eddyb beta-nominating because regression (MIR effectck is new)
2017-11-09add a bunch of debug logging to transform::inlineAriel Ben-Yehuda-6/+23
2017-11-06Auto merge of #45668 - nikomatsakis:nll-free-region, r=arielb1bors-177/+462
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-06collect unused unsafe codeAriel Ben-Yehuda-61/+92
FIXME: de-uglify
2017-11-06run unsafety checking before dead block collectionAriel Ben-Yehuda-4/+12
Fixes #45087.
2017-11-06fix unsafety checking for generatorsAriel Ben-Yehuda-7/+12
Fixes #45729
2017-11-02trace span info for constraints and report errorsNiko Matsakis-26/+104
2017-11-02encapsulate the `Region` struct within region inferenceNiko Matsakis-39/+47
2017-11-02add comments to `region_infer`, restructure a bitNiko Matsakis-35/+56
2017-11-02extend NLL regions to include free region indices and add outlivesNiko Matsakis-110/+289
2017-11-02rename `Lookup` to `TyContext` and pass more info when visiting tysNiko Matsakis-23/+22
2017-11-02add TerminatorKind::FalseEdges and use it in matchesMikhail Modin-4/+23