Commit graph

11961 commits

Author SHA1 Message Date
bors
d0f8e2913a Auto merge of #45825 - nikomatsakis:nll-factor-region-inference, r=arielb1
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-16 20:56:26 +00:00
Niko Matsakis
8c109f5681 infer/outlives/obligations.rs: wrap some long lines 2017-11-16 05:58:16 -05:00
Niko Matsakis
9e29662a98 obligations.rs: rustfmt 2017-11-16 05:58:16 -05:00
Niko Matsakis
a73d620323 Nit: reset more state after take_and_reset_data 2017-11-16 05:58:11 -05:00
Niko Matsakis
11c84c6625 Nit: improve comment to explain why we wait until regionck 2017-11-16 05:58:00 -05:00
Niko Matsakis
15739b820f Nit: rework region obligations to a snapshotted vector 2017-11-16 05:57:56 -05:00
Niko Matsakis
f72259101f Nit: fix wording in README 2017-11-16 05:57:51 -05:00
Niko Matsakis
5a8c1eb61a leak the affects of closures on the free-region-map, like we used to
This restores the behavior of regionck with respect to the
free-region-map: that is, it collects all the relations from the fn
and its closures. This feels a bit fishy but it's the behavior we've
had for some time, and it will go away with NLL, so seems best to just
keep it.
2017-11-16 05:57:51 -05:00
Niko Matsakis
c7c2603e2c factor out free_region_binding_scope helper 2017-11-16 05:57:51 -05:00
Niko Matsakis
9da54c1ac8 add FIXME for converting RegionVid to use newtype_index! 2017-11-16 05:57:50 -05:00
Niko Matsakis
267574c8df convert TODO in traits into a FIXME 2017-11-16 05:57:50 -05:00
Niko Matsakis
013f88b9fb infer/outlives: add license 2017-11-16 05:57:47 -05:00
Niko Matsakis
b383ab79c9 update READMEs to describe the new situation
The inference README, in particular, was VERY out of date!
2017-11-16 05:57:47 -05:00
Niko Matsakis
4b743da596 integrate NLL with MIR type-checker 2017-11-16 05:57:47 -05:00
Niko Matsakis
12534e9159 renumber: handle ReturnTy better 2017-11-16 05:57:47 -05:00
Niko Matsakis
51ce1f9493 formalize giving ownership of region vars to region inf. context 2017-11-16 05:57:46 -05:00
Niko Matsakis
a87d1bbb93 infer: give access to region variable origins 2017-11-16 05:57:45 -05:00
Niko Matsakis
ad93b695d1 MIR typeck: refactor to track region constraints 2017-11-16 05:57:45 -05:00
Niko Matsakis
034018cd90 rustfmt lexical_region_resolve 2017-11-16 05:57:44 -05:00
Niko Matsakis
1430a600de add method take_and_reset_region_constraints to InferCtxt 2017-11-16 05:57:44 -05:00
Niko Matsakis
1efcf1a115 split the var_origins from the RegionConstraintData 2017-11-16 05:57:44 -05:00
Niko Matsakis
a8daa37df6 region_constraints: only push givens into undo-log if in a snapshot 2017-11-16 05:57:44 -05:00
Niko Matsakis
524e23ae2e make RegionVid implement Idx and use IndexVec 2017-11-16 05:57:44 -05:00
Niko Matsakis
f6037f2816 separate the Collector from the Data it is collecting 2017-11-16 05:57:43 -05:00
Niko Matsakis
adf1519941 make the region_constraints field an Option
This way, we can `take()` ownership of it when we are going to resolve regions.
2017-11-16 05:57:43 -05:00
Niko Matsakis
326ec52eac rename RegionVarBindings to RegionConstraintCollector 2017-11-16 05:57:43 -05:00
Niko Matsakis
48d8f7210b infer: rename region_vars field to region_constraints 2017-11-16 05:57:43 -05:00
Niko Matsakis
23abd85138 rename region_inference module to region_constraints 2017-11-16 05:57:43 -05:00
Niko Matsakis
cff191d444 move refcells out from RegionVarBindings and up into InferCtxt 2017-11-16 05:57:42 -05:00
Niko Matsakis
63d658d87c extract the tcx out from RegionVarBindings 2017-11-16 05:57:42 -05:00
Niko Matsakis
daceedf314 region_inference: rustfmt 2017-11-16 05:57:42 -05:00
Niko Matsakis
ec48b018d6 extract storage of region values from RegionVarBindings 2017-11-16 05:57:42 -05:00
Niko Matsakis
b76978530c move RegionResolutionError into lexical_region_resolve 2017-11-16 05:57:42 -05:00
Niko Matsakis
8e9e15446f region_inference: extract taint into a sub-module 2017-11-16 05:57:41 -05:00
Niko Matsakis
9d63330b6d region_inference: tighten up pub, stop re-exporting enum variants 2017-11-16 05:57:41 -05:00
Guillaume Gomez
b09af7064e Rollup merge of #46005 - GuillaumeGomez:short-unstable, r=nrc
Set short-message feature unstable

Fixes #45995.

r? @nrc
2017-11-16 10:05:06 +01:00
Guillaume Gomez
ed64b97d61 Rollup merge of #45984 - ExpHP:attr-error-context, r=estebank
Add context to E0084, E0517, E0518

A small diagnostic enhancement to get my feet wet.  Please scrutinize!

This modifies errors E0084, E0517, and E0518 to include both the annotation and the annotated item.  All of these errors already had labels; I moved the label to the other span, and rephrased it as necessary.

Fixes #45886
2017-11-16 10:05:04 +01:00
Niko Matsakis
58c77600a5 move region resolution to be a sibling of region_inference
Temporary make various fields public.
2017-11-15 16:58:14 -05:00
Niko Matsakis
467f2ea653 extract lexical region resolution into its own sub-module 2017-11-15 16:50:32 -05:00
Niko Matsakis
6d672961fb thread location info through mir typeck (but do not use) 2017-11-15 16:49:23 -05:00
Niko Matsakis
15a2dfa324 move the OutlivesEnvironment into infer so that nll can use it
Unquestionably there is more cleanup to be done, but I'm not sure what
it should look like yet, so leaving it roughly as is.
2017-11-15 16:49:22 -05:00
Niko Matsakis
56e5eb5fd4 rename mod region_obligations to outlives::obligations 2017-11-15 16:49:22 -05:00
Niko Matsakis
0c81d0158f extract out the implied bounds code from regionck 2017-11-15 16:49:22 -05:00
Niko Matsakis
3cc44a569d do not invoke required_region_bounds in region_obligations
Instead, just search the param env predicates directly. This is
equivalent to what we were doing before but more efficient.
2017-11-15 16:49:22 -05:00
Niko Matsakis
e0630e8683 refactor how we extract outlives bounds from trait definitions
This new way is **slightly** less expressive (I would be shocked if it
affects any code, though) when it comes to higher-ranked bounds or a
few other weird tricks. But we don't handle those consistently
regardless, and the new way does not require normalization and is just
wildly simpler.
2017-11-15 16:49:22 -05:00
Niko Matsakis
22cd041ba0 move the region_obligations processing code into InferCtxt 2017-11-15 16:49:21 -05:00
Niko Matsakis
d73be851fb extract regionck_outlives into a separate helper function
This helps make its inputs and outputs more clear.
2017-11-15 16:49:21 -05:00
Niko Matsakis
c925008a5c assert that we are consuming all of the region obligations
When we get around to resolving regions, we really ought to take region
obligations into account. There is one case where they are presently
being ignored. Keep ignoring them there for now but leave a TODO.
2017-11-15 16:49:21 -05:00
Niko Matsakis
0d78e40e88 convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
cc #37166
2017-11-15 16:49:21 -05:00
Niko Matsakis
64206b44b9 move region constraints into inference context 2017-11-15 16:49:21 -05:00