Skip to content

Commit ea4b94d

Browse files
authored
Auto merge of #37332 - nikomatsakis:incr-comp-benchmark-2, r=michaelwoerister
add more incremental reuse test cases r? @michaelwoerister This is basically a port of the "private method in impl". It works better when it's a top-level fn. =)
2 parents ac968c4 + 3dbf4d1 commit ea4b94d

File tree

5 files changed

+356
-0
lines changed

5 files changed

+356
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change the body of a private method in an impl.
12+
// We then test what sort of functions must be rebuilt as a result.
13+
14+
// revisions:rpass1 rpass2
15+
// compile-flags: -Z query-dep-graph
16+
17+
#![feature(rustc_attrs)]
18+
#![feature(stmt_expr_attributes)]
19+
#![allow(dead_code)]
20+
21+
#![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
22+
23+
#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="rpass2")]
24+
#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_another_impl", cfg="rpass2")]
25+
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
26+
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
27+
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
28+
29+
mod point {
30+
pub struct Point {
31+
pub x: f32,
32+
pub y: f32,
33+
}
34+
35+
fn distance_squared(this: &Point) -> f32 {
36+
#[cfg(rpass1)]
37+
return this.x + this.y;
38+
39+
#[cfg(rpass2)]
40+
return this.x * this.x + this.y * this.y;
41+
}
42+
43+
impl Point {
44+
pub fn distance_from_origin(&self) -> f32 {
45+
distance_squared(self).sqrt()
46+
}
47+
}
48+
49+
impl Point {
50+
pub fn translate(&mut self, x: f32, y: f32) {
51+
self.x += x;
52+
self.y += y;
53+
}
54+
}
55+
56+
}
57+
58+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
59+
mod fn_calls_methods_in_same_impl {
60+
use point::Point;
61+
62+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
63+
pub fn check() {
64+
let x = Point { x: 2.0, y: 2.0 };
65+
x.distance_from_origin();
66+
}
67+
}
68+
69+
/// A fn item that calls (public) methods on `Point` from another impl
70+
mod fn_calls_methods_in_another_impl {
71+
use point::Point;
72+
73+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
74+
pub fn check() {
75+
let mut x = Point { x: 2.0, y: 2.0 };
76+
x.translate(3.0, 3.0);
77+
}
78+
}
79+
80+
/// A fn item that makes an instance of `Point` but does not invoke methods
81+
mod fn_make_struct {
82+
use point::Point;
83+
84+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
85+
pub fn make_origin() -> Point {
86+
Point { x: 2.0, y: 2.0 }
87+
}
88+
}
89+
90+
/// A fn item that reads fields from `Point` but does not invoke methods
91+
mod fn_read_field {
92+
use point::Point;
93+
94+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
95+
pub fn get_x(p: Point) -> f32 {
96+
p.x
97+
}
98+
}
99+
100+
/// A fn item that writes to a field of `Point` but does not invoke methods
101+
mod fn_write_field {
102+
use point::Point;
103+
104+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
105+
pub fn inc_x(p: &mut Point) {
106+
p.x += 1.0;
107+
}
108+
}
109+
110+
fn main() {
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct Point {
12+
pub x: f32,
13+
pub y: f32,
14+
}
15+
16+
fn distance_squared(this: &Point) -> f32 {
17+
#[cfg(rpass1)]
18+
return this.x + this.y;
19+
20+
#[cfg(rpass2)]
21+
return this.x * this.x + this.y * this.y;
22+
}
23+
24+
impl Point {
25+
pub fn distance_from_origin(&self) -> f32 {
26+
distance_squared(self).sqrt()
27+
}
28+
}
29+
30+
impl Point {
31+
pub fn translate(&mut self, x: f32, y: f32) {
32+
self.x += x;
33+
self.y += y;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change the body of a private method in an impl.
12+
// We then test what sort of functions must be rebuilt as a result.
13+
14+
// revisions:rpass1 rpass2
15+
// compile-flags: -Z query-dep-graph
16+
// aux-build:point.rs
17+
18+
#![feature(rustc_attrs)]
19+
#![feature(stmt_expr_attributes)]
20+
#![allow(dead_code)]
21+
22+
#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="rpass2")]
23+
#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_another_impl", cfg="rpass2")]
24+
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
25+
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
26+
27+
// FIXME(#37335) -- should be reused, but an errant Krate edge causes
28+
// it to get translated (at least I *think* this is that same problem)
29+
#![rustc_partition_translated(module="struct_point-fn_make_struct", cfg="rpass2")]
30+
31+
extern crate point;
32+
33+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
34+
mod fn_calls_methods_in_same_impl {
35+
use point::Point;
36+
37+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
38+
pub fn check() {
39+
let x = Point { x: 2.0, y: 2.0 };
40+
x.distance_from_origin();
41+
}
42+
}
43+
44+
/// A fn item that calls (public) methods on `Point` from another impl
45+
mod fn_calls_methods_in_another_impl {
46+
use point::Point;
47+
48+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
49+
pub fn check() {
50+
let mut x = Point { x: 2.0, y: 2.0 };
51+
x.translate(3.0, 3.0);
52+
}
53+
}
54+
55+
/// A fn item that makes an instance of `Point` but does not invoke methods
56+
mod fn_make_struct {
57+
use point::Point;
58+
59+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
60+
pub fn make_origin() -> Point {
61+
Point { x: 2.0, y: 2.0 }
62+
}
63+
}
64+
65+
/// A fn item that reads fields from `Point` but does not invoke methods
66+
mod fn_read_field {
67+
use point::Point;
68+
69+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
70+
pub fn get_x(p: Point) -> f32 {
71+
p.x
72+
}
73+
}
74+
75+
/// A fn item that writes to a field of `Point` but does not invoke methods
76+
mod fn_write_field {
77+
use point::Point;
78+
79+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
80+
pub fn inc_x(p: &mut Point) {
81+
p.x += 1.0;
82+
}
83+
}
84+
85+
fn main() {
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct Point {
12+
pub x: f32,
13+
pub y: f32,
14+
}
15+
16+
impl Point {
17+
fn distance_squared(&self) -> f32 {
18+
#[cfg(rpass1)]
19+
return self.x + self.y;
20+
21+
#[cfg(rpass2)]
22+
return self.x * self.x + self.y * self.y;
23+
}
24+
25+
pub fn distance_from_origin(&self) -> f32 {
26+
self.distance_squared().sqrt()
27+
}
28+
}
29+
30+
impl Point {
31+
pub fn translate(&mut self, x: f32, y: f32) {
32+
self.x += x;
33+
self.y += y;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test where we change the body of a private method in an impl.
12+
// We then test what sort of functions must be rebuilt as a result.
13+
14+
// revisions:rpass1 rpass2
15+
// compile-flags: -Z query-dep-graph
16+
// aux-build:point.rs
17+
18+
#![feature(rustc_attrs)]
19+
#![feature(stmt_expr_attributes)]
20+
#![allow(dead_code)]
21+
22+
// FIXME(#37333) -- the following modules *should* be reused but are not
23+
#![rustc_partition_translated(module="struct_point-fn_calls_methods_in_same_impl", cfg="rpass2")]
24+
#![rustc_partition_translated(module="struct_point-fn_calls_methods_in_another_impl", cfg="rpass2")]
25+
#![rustc_partition_translated(module="struct_point-fn_make_struct", cfg="rpass2")]
26+
#![rustc_partition_translated(module="struct_point-fn_read_field", cfg="rpass2")]
27+
#![rustc_partition_translated(module="struct_point-fn_write_field", cfg="rpass2")]
28+
29+
extern crate point;
30+
31+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
32+
mod fn_calls_methods_in_same_impl {
33+
use point::Point;
34+
35+
// FIXME(#37333) -- we should not need to typeck this again
36+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
37+
pub fn check() {
38+
let x = Point { x: 2.0, y: 2.0 };
39+
x.distance_from_origin();
40+
}
41+
}
42+
43+
/// A fn item that calls (public) methods on `Point` from another impl
44+
mod fn_calls_methods_in_another_impl {
45+
use point::Point;
46+
47+
// FIXME(#37333) -- we should not need to typeck this again
48+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
49+
pub fn check() {
50+
let mut x = Point { x: 2.0, y: 2.0 };
51+
x.translate(3.0, 3.0);
52+
}
53+
}
54+
55+
/// A fn item that makes an instance of `Point` but does not invoke methods
56+
mod fn_make_struct {
57+
use point::Point;
58+
59+
// FIXME(#37333) -- we should not need to typeck this again
60+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
61+
pub fn make_origin() -> Point {
62+
Point { x: 2.0, y: 2.0 }
63+
}
64+
}
65+
66+
/// A fn item that reads fields from `Point` but does not invoke methods
67+
mod fn_read_field {
68+
use point::Point;
69+
70+
// FIXME(#37333) -- we should not need to typeck this again
71+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
72+
pub fn get_x(p: Point) -> f32 {
73+
p.x
74+
}
75+
}
76+
77+
/// A fn item that writes to a field of `Point` but does not invoke methods
78+
mod fn_write_field {
79+
use point::Point;
80+
81+
// FIXME(#37333) -- we should not need to typeck this again
82+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
83+
pub fn inc_x(p: &mut Point) {
84+
p.x += 1.0;
85+
}
86+
}
87+
88+
fn main() {
89+
}

0 commit comments

Comments
 (0)