Skip to content

Add unary and binary tests for incr-comp #37610

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

Merged
merged 3 commits into from
Nov 9, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions src/test/incremental/hashes/unary_and_binary_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


// This test case tests the incremental compilation hash (ICH) implementation
// for struct definitions.
// for unary and binary expressions.

// The general pattern followed here is: Change one thing between rev1 and rev2
// and make sure that the hash has changed, then change nothing between rev2 and
Expand Down Expand Up @@ -41,6 +41,7 @@ pub fn const_negation() -> i32 {
}



// Change constant operand of bitwise not --------------------------------------
#[cfg(cfail1)]
pub fn const_bitwise_not() -> i32 {
Expand All @@ -57,9 +58,10 @@ pub fn const_bitwise_not() -> i32 {
}



// Change variable operand of negation -----------------------------------------
#[cfg(cfail1)]
pub fn var_negation(x: i32) -> i32 {
pub fn var_negation(x: i32, y: i32) -> i32 {
-x
}

Expand All @@ -68,14 +70,15 @@ pub fn var_negation(x: i32) -> i32 {
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_negation(y: i32) -> i32 {
pub fn var_negation(x: i32, 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.

}



// Change variable operand of bitwise not --------------------------------------
#[cfg(cfail1)]
pub fn var_bitwise_not(x: i32) -> i32 {
pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
!x
}

Expand All @@ -84,14 +87,15 @@ pub fn var_bitwise_not(x: i32) -> i32 {
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_bitwise_not(y: i32) -> i32 {
pub fn var_bitwise_not(x: i32, 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

}



// Change variable operand of deref --------------------------------------------
#[cfg(cfail1)]
pub fn var_deref(x: &i32) -> i32 {
pub fn var_deref(x: &i32, y: &i32) -> i32 {
*x
}

Expand All @@ -100,11 +104,12 @@ pub fn var_deref(x: &i32) -> i32 {
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn var_deref(y: &i32) -> i32 {
pub fn var_deref(x: &i32, 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

}



// Change first constant operand of addition -----------------------------------
#[cfg(cfail1)]
pub fn first_const_add() -> i32 {
Expand All @@ -121,6 +126,7 @@ pub fn first_const_add() -> i32 {
}



// Change second constant operand of addition -----------------------------------
#[cfg(cfail1)]
pub fn second_const_add() -> i32 {
Expand All @@ -137,9 +143,10 @@ pub fn second_const_add() -> i32 {
}



// Change first variable operand of addition -----------------------------------
#[cfg(cfail1)]
pub fn first_var_add(a: i32) -> i32 {
pub fn first_var_add(a: i32, b: i32) -> i32 {
a + 2
}

Expand All @@ -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.

Same as above

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.

}



// Change second variable operand of addition ----------------------------------
#[cfg(cfail1)]
pub fn second_var_add(a: i32) -> i32 {
pub fn second_var_add(a: i32, b: i32) -> i32 {
1 + a
}

Expand All @@ -164,11 +172,12 @@ pub fn second_var_add(a: i32) -> i32 {
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn second_var_add(b: i32) -> i32 {
pub fn second_var_add(a: i32, 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

}



// Change operator from + to - -------------------------------------------------
#[cfg(cfail1)]
pub fn plus_to_minus(a: i32) -> i32 {
Expand All @@ -185,6 +194,7 @@ pub fn plus_to_minus(a: i32) -> i32 {
}



// Change operator from + to * -------------------------------------------------
#[cfg(cfail1)]
pub fn plus_to_mult(a: i32) -> i32 {
Expand All @@ -201,6 +211,7 @@ pub fn plus_to_mult(a: i32) -> i32 {
}



// Change operator from + to / -------------------------------------------------
#[cfg(cfail1)]
pub fn plus_to_div(a: i32) -> i32 {
Expand All @@ -217,6 +228,7 @@ pub fn plus_to_div(a: i32) -> i32 {
}



// Change operator from + to % -------------------------------------------------
#[cfg(cfail1)]
pub fn plus_to_mod(a: i32) -> i32 {
Expand All @@ -233,6 +245,7 @@ pub fn plus_to_mod(a: i32) -> i32 {
}



// Change operator from && to || -----------------------------------------------
#[cfg(cfail1)]
pub fn and_to_or(a: bool, b: bool) -> bool {
Expand Down Expand Up @@ -444,7 +457,9 @@ pub fn value_cast(a: u32) -> i32 {
// Change l-value in assignment ------------------------------------------------
#[cfg(cfail1)]
pub fn lvalue() -> i32 {
let x = 10;
let mut x = 10;
let mut y = 11;
x = 9;
x
}

Expand All @@ -454,7 +469,9 @@ pub fn lvalue() -> i32 {
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn lvalue() -> i32 {
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.

}

Expand All @@ -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.

x = 9;
x
}

Expand All @@ -473,25 +492,25 @@ pub fn rvalue() -> i32 {
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn rvalue() -> i32 {
let x = 11;
let mut x = 10;
let mut y = 11;
x = 8;
x
}



// Change index into slice -----------------------------------------------------
#[cfg(cfail1)]
pub fn index_to_slice() -> i32 {
let xs = [1,2,3,4,5];
xs[1]
pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
s[i]
}

#[cfg(not(cfail1))]
#[rustc_dirty(label="Hir", cfg="cfails2")]
#[rustc_clean(label="Hir", cfg="cfails3")]
#[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")]
pub fn index_to_slice() -> i32 {
let xs = &[1,2,3,4,5];
xs[1]
pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
s[j]
}