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

[MIR] Change destination accessor to return references #30761

Merged
merged 1 commit into from
Jan 12, 2016

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Jan 7, 2016

Previously it was returning a clone, mostly for the two reasons:

  • Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection);
  • There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows
    to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).

However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.

Instead, we have two accessors destination and destination_mut which return a reference to the
destination in desired mode.

r? @nikomatsakis

@nagisa
Copy link
Member Author

nagisa commented Jan 7, 2016

r? @nikomatsakis

@nagisa nagisa changed the title Change destination accessor to return references [MIR] Change destination accessor to return references Jan 7, 2016
@bors
Copy link
Contributor

bors commented Jan 8, 2016

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

@@ -425,7 +425,7 @@ pub trait MutVisitor<'tcx> {
}

Terminator::Call { ref mut func, ref mut args, ref mut kind } => {
if let Some(ref mut destination) = kind.destination() {
Copy link
Contributor

Choose a reason for hiding this comment

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

indeed, this was definitely a bug.

@nikomatsakis
Copy link
Contributor

r+ but I suspect this conflicted with @michaelwoerister's macroization of the visitor

Previously it was returning a value, mostly for the two reasons:

* Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection);
* There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows
  to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).

However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.

Instead, we have two accessors `destination` and `destination_mut` which return a reference to the
destination in desired mode.
@michaelwoerister
Copy link
Member

Before #30757 this actually caused a bug in the MutVisitor. Looks good now :)

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2016

📌 Commit 2f86c16 has been approved by michaelwoerister

nagisa added a commit to nagisa/rust that referenced this pull request Jan 9, 2016
…elwoerister

Previously it was returning a clone, mostly for the two reasons:

* Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection);
* There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows
  to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).

However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.

Instead, we have two accessors `destination` and `destination_mut` which return a reference to the
destination in desired mode.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Jan 11, 2016

⌛ Testing commit 2f86c16 with merge 707dc1f...

bors added a commit that referenced this pull request Jan 11, 2016
Previously it was returning a clone, mostly for the two reasons:

* Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection);
* There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows
  to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).

However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.

Instead, we have two accessors `destination` and `destination_mut` which return a reference to the
destination in desired mode.

r? @nikomatsakis
@alexcrichton
Copy link
Member

@bors: retry force

nagisa added a commit to nagisa/rust that referenced this pull request Jan 11, 2016
…elwoerister

Previously it was returning a clone, mostly for the two reasons:

* Cloning Lvalue is very cheap most of the time (i.e. when Lvalue is not a Projection);
* There’s users who want &mut lvalue and there’s users who want &lvalue. Returning a value allows
  to make either one easier when pattern matching (i.e. Some(ref dest) or Some(ref mut dest)).

However, I’m now convinced this is an invalid approach. Namely the users which want a mutable
reference may modify the Lvalue in-place, but the changes won’t be reflected in the final MIR,
since the Lvalue modified is merely a clone.

Instead, we have two accessors `destination` and `destination_mut` which return a reference to the
destination in desired mode.

r? @nikomatsakis
bors added a commit that referenced this pull request Jan 11, 2016
@bors bors merged commit 2f86c16 into rust-lang:master Jan 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants