-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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]
}
Said code review and recommendations can be found here: rust-lang#37610
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Alright, looking good now. Let's wait for travis to give the OK, then I'll approve. |
@bors r+ rollup |
📌 Commit 5a2997d has been approved by |
…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
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