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

Add unary and binary tests for incr-comp #37610

Merged
merged 3 commits into from
Nov 9, 2016

Conversation

zimurgh
Copy link

@zimurgh zimurgh commented Nov 6, 2016

This is my draft of tests for unary and binary expressions as desired by #37520 for use in the test suite for hashes in incremental compilation. Feedback would be wonderful, if there's any changes I need to make I would appreciate the code review.

?r @michaelwoerister

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

r? @michaelwoerister

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @OldManMike!
Except for the "only change"-cases and some nits this looks very good already. If you fix the things I commented on, this is good to go.

(...plus adapt the comment at the top that is still talking about structs)

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_negation(y: i32) -> i32 {
-y
Copy link
Member

Choose a reason for hiding this comment

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

In this case we have to make sure that y already exists in the cfail1 version (and x still in the later version). Otherwise the hashing algorithm might miss the operand but we wouldn't know because the hash was changed anyway by renaming the function argument. Changing the operand should really be the only change.

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_bitwise_not(y: i32) -> i32 {
!y
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_deref(y: &i32) -> i32 {
*y
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn first_var_add(b: i32) -> i32 {
b + 3
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn second_var_add(b: i32) -> i32 {
1 + b
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn type_cast(a: u8) -> u64 {
let b = a as u32;
Copy link
Member

Choose a reason for hiding this comment

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

That's a nice way of making this work!

// Change l-value in assignment ------------------------------------------------
#[cfg(cfail1)]
pub fn lvalue() -> i32 {
let x = 10;
Copy link
Member

Choose a reason for hiding this comment

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

A let statement is different from an assignment, as far as the compiler is concerned. It's an assignment when writing into an existing variable. So this should be something like:

pub fn lvalue() -> i32 {
    let mut x = 1;
    let mut y = 2;
    x = 10;
    y
}

Note, that I also already added y so that changing the left-hand side of the assignment is really the only change.

// Change r-value in assignment ------------------------------------------------
#[cfg(cfail1)]
pub fn rvalue() -> i32 {
let x = 10;
Copy link
Member

Choose a reason for hiding this comment

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

Same as above


// Change index into slice -----------------------------------------------------
#[cfg(cfail1)]
pub fn index_to_slice() -> i32 {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit different than I imagined (what you implemented is something that I want to cover in a separate suite of tests for let statements). Here I'd like the indexing expression in a slice to be tested:

pub fn slice_index(s: &[u8], i: usize, j: usize) -> u8 {
    s[i]
}

// becomes

pub fn slice_index(s: &[u8], i: usize, j: usize) -> u8 {
    s[j]
}

oldmanmike added 2 commits November 7, 2016 12:42
Said code review and recommendations can be found here:
rust-lang#37610
Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

I added some more comments.

@@ -148,14 +155,15 @@ pub fn first_var_add(a: i32) -> i32 {
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn first_var_add(b: i32) -> i32 {
pub fn first_var_add(a: i32, b: i32) -> i32 {
b + 3
Copy link
Member

Choose a reason for hiding this comment

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

This should be b + 2, otherwise we change both operands.

let y = 10;
let mut x = 10;
let mut y = 11;
x = 9;
y
Copy link
Member

Choose a reason for hiding this comment

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

We want to change the left-hand side of the assignment here, not the return value of the function.

@@ -463,7 +480,9 @@ pub fn lvalue() -> i32 {
// Change r-value in assignment ------------------------------------------------
#[cfg(cfail1)]
pub fn rvalue() -> i32 {
let x = 10;
let mut x = 10;
let mut y = 11;
Copy link
Member

Choose a reason for hiding this comment

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

The variable y is not needed in the rvalue() test case.

@michaelwoerister
Copy link
Member

Alright, looking good now. Let's wait for travis to give the OK, then I'll approve.

@michaelwoerister
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 8, 2016

📌 Commit 5a2997d has been approved by michaelwoerister

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Nov 8, 2016
…r=michaelwoerister

Add unary and binary tests for incr-comp

This is my draft of tests for unary and binary expressions as desired by rust-lang#37520 for use in the test suite for hashes in incremental compilation. Feedback would be wonderful, if there's any changes I need to make I would appreciate the code review.

?r @michaelwoerister
bors added a commit that referenced this pull request Nov 9, 2016
Rollup of 8 pull requests

- Successful merges: #35102, #37425, #37483, #37588, #37601, #37610, #37650, #37652
- Failed merges:
@bors bors merged commit 5a2997d into rust-lang:master Nov 9, 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