Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify memory categorization #66246

Merged
merged 5 commits into from
Nov 28, 2019
Merged

Conversation

matthewjasper
Copy link
Contributor

@matthewjasper matthewjasper commented Nov 9, 2019

With AST borrowck gone, mem_categorization can be simplified, a lot.

  • cmt_ is now called Place. Most local variable names have been updated to reflect this, but the cat_* methods retain their names.
  • MemCategorizationContext no longer needs a ScopeTree and always needs an InferCtxt.
  • Place now uses a similar representation to mir::Place with a Vec of projections.
  • Upvar places don't include the implicit environment and capture derefs. These are now handled by regionck when needed.
  • Various types, methods and variants only used by AST borrowck have been removed.
  • ExprUseVisitor now lives in rustc_typeck::expr_use_visitor.
  • MemCategorizationContext and Place live in rustc_typeck::mem_categorization.
  • Place is re-exported in rustc_typeck::expr_use_visitor so that Clippy can access it.

The loss of an error in issue-4335.rs is due to a change in capture inference in ill-formed programs. If any projection from a variable is moved from then we capture that variable by move, whether or not the place being moved from allows this.

Closes #66270

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 9, 2019
@matthewjasper
Copy link
Contributor Author

r? @nikomatsakis or @pnkfelix

@rust-highfive

This comment has been minimized.

src/librustc/middle/mem_categorization.rs Outdated Show resolved Hide resolved
src/librustc/middle/mem_categorization.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Nov 11, 2019

☔ The latest upstream changes (presumably #66252) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Nov 14, 2019

☔ The latest upstream changes (presumably #66314) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2019
@JohnCSimon
Copy link
Member

Ping from triage
@matthewjasper - can you please address the merge conflicts?
Thank you!

@matthewjasper matthewjasper added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 24, 2019
@bors
Copy link
Contributor

bors commented Nov 25, 2019

☔ The latest upstream changes (presumably #66671) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix
Copy link
Member

r? @pnkfelix

@@ -899,10 +896,6 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
}

cmt = self.with_mc(|mc| mc.cat_expr_adjusted(expr, cmt, &adjustment))?;

if let Categorization::Deref(_, mc::BorrowedPtr(_, r_ptr)) = cmt.cat {
self.mk_subregion_due_to_dereference(expr.span, expr_region, r_ptr);
Copy link
Member

@pnkfelix pnkfelix Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know what this was originally here for? I just want a note in this PR about why we don't need it, no need to add comments to the source code or anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(is this a case where mir-borrowck (and/or nll/type-check) is imposing the same constraint and so we do not need to impose it here?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the case for most of the constraints in this file. This check specifically is to ensure, in the language of NLL, that 'a is live at the point marked:

let x: &'a (i32, i32) = ...;
let _ = x.0; //here

This is redundant because:

  • There's no longer any check that makes use of ReScopes (except for the leak check, but that's hopefully going away soon).
  • NLL does is own region liveness inference.
  • I think that we're already adding this relation because all of the regions in the unadjusted expression are already marked live.

@pnkfelix
Copy link
Member

This looks great! r=me once you have addressed the nits above.

@pnkfelix pnkfelix added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2019
@matthewjasper
Copy link
Contributor Author

@bors r=pnkfelix

@bors
Copy link
Contributor

bors commented Nov 27, 2019

📌 Commit 5bc1586 has been approved by pnkfelix

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 27, 2019
@bors
Copy link
Contributor

bors commented Nov 28, 2019

⌛ Testing commit 5bc1586 with merge 223a873de4d7729c3869832b3189f8ddbd17b7c2...

@rust-highfive
Copy link
Collaborator

The job dist-powerpc64-linux of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Nov 28, 2019

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 28, 2019
@matthewjasper
Copy link
Contributor Author

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 28, 2019
@bors
Copy link
Contributor

bors commented Nov 28, 2019

⌛ Testing commit 5bc1586 with merge 4752c05...

bors added a commit that referenced this pull request Nov 28, 2019
Simplify memory categorization

With AST borrowck gone, mem_categorization can be simplified, a lot.

* `cmt_` is now called `Place`. Most local variable names have been updated to reflect this, but the `cat_*` methods retain their names.
* `MemCategorizationContext` no longer needs a `ScopeTree` and always needs an `InferCtxt`.
* `Place` now uses a similar representation to `mir::Place` with a `Vec` of projections.
* `Upvar` places don't include the implicit environment and capture derefs. These are now handled by `regionck` when needed.
* Various types, methods and variants only used by AST borrowck have been removed.
* `ExprUseVisitor` now lives in `rustc_typeck::expr_use_visitor`.
* `MemCategorizationContext` and `Place` live in `rustc_typeck::mem_categorization`.
* `Place` is re-exported in `rustc_typeck::expr_use_visitor` so that Clippy can access it.

The loss of an error in `issue-4335.rs` is due to a change in capture inference in ill-formed programs. If any projection from a variable is moved from then we capture that variable by move, whether or not the place being moved from allows this.

Closes #66270
@bors
Copy link
Contributor

bors commented Nov 28, 2019

☀️ Test successful - checks-azure
Approved by: pnkfelix
Pushing 4752c05 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 28, 2019
@bors bors merged commit 5bc1586 into rust-lang:master Nov 28, 2019
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #66246!

Tested on commit 4752c05.
Direct link to PR: #66246

💔 clippy-driver on windows: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq, @rust-lang/infra).
💔 clippy-driver on linux: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq, @rust-lang/infra).
💔 rls on windows: test-pass → test-fail (cc @Xanewok, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Nov 28, 2019
Tested on commit rust-lang/rust@4752c05.
Direct link to PR: <rust-lang/rust#66246>

💔 clippy-driver on windows: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq, @rust-lang/infra).
💔 clippy-driver on linux: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq, @rust-lang/infra).
💔 rls on windows: test-pass → test-fail (cc @Xanewok, @rust-lang/infra).
@@ -83,6 +86,7 @@ mod collect;
mod constrained_generic_params;
mod structured_errors;
mod impl_wf_check;
mod mem_categorization;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, this needs to be public too, Clippy can't use EUV without memcat

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we should be very careful about marking existing things as private

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, you want us to use Place from EUV, and Categorization isn't a thing anymore

bors added a commit to rust-lang/rust-clippy that referenced this pull request Nov 29, 2019
Centril added a commit to Centril/rust that referenced this pull request Dec 23, 2019
…-DPC

Add regression tests for fixed ICEs

Closes rust-lang#61747 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66205 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66270 (fixed by rust-lang#66246)
Closes rust-lang#66868 (fixed by rust-lang#67071)
Closes rust-lang#67424 (fixed by rust-lang#67160)

Also picking a minor nit up from rust-lang#67071 with 101dd7b

r? @Centril
Centril added a commit to Centril/rust that referenced this pull request Dec 23, 2019
…-DPC

Add regression tests for fixed ICEs

Closes rust-lang#61747 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66205 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66270 (fixed by rust-lang#66246)
Closes rust-lang#66868 (fixed by rust-lang#67071)
Closes rust-lang#67424 (fixed by rust-lang#67160)

Also picking a minor nit up from rust-lang#67071 with 101dd7b

r? @Centril
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Dec 24, 2019
Add regression tests for fixed ICEs

Closes rust-lang#61747 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66205 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66270 (fixed by rust-lang#66246)
Closes rust-lang#67424 (fixed by rust-lang#67160)

Also picking a minor nit up from rust-lang#67071 with 101dd7b

r? @Centril
Centril added a commit to Centril/rust that referenced this pull request Dec 24, 2019
Add regression tests for fixed ICEs

Closes rust-lang#61747 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66205 (fixed from 1.41.0-nightly (4007d4e 2019-12-01))
Closes rust-lang#66270 (fixed by rust-lang#66246)
Closes rust-lang#67424 (fixed by rust-lang#67160)

Also picking a minor nit up from rust-lang#67071 with 101dd7b

r? @Centril
@matthewjasper matthewjasper deleted the simplify-mem-cat branch December 31, 2019 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destructuring of incorrectly defined struct produces ICE
10 participants